001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
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.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.LockPersistence;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.UserPersistence;
045    import com.liferay.portal.service.persistence.WebDAVPropsPersistence;
046    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.asset.service.persistence.AssetCategoryPersistence;
050    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
051    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
052    import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
053    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
054    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl;
055    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryModelImpl;
056    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
057    import com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence;
058    import com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence;
059    import com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence;
060    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
061    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
062    
063    import java.io.Serializable;
064    
065    import java.util.ArrayList;
066    import java.util.Collections;
067    import java.util.List;
068    
069    /**
070     * The persistence implementation for the d l file entry service.
071     *
072     * <p>
073     * Never modify or reference this class directly. Always use {@link DLFileEntryUtil} to access the d l file entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074     * </p>
075     *
076     * <p>
077     * Caching information and settings can be found in <code>portal.properties</code>
078     * </p>
079     *
080     * @author Brian Wing Shun Chan
081     * @see DLFileEntryPersistence
082     * @see DLFileEntryUtil
083     * @generated
084     */
085    public class DLFileEntryPersistenceImpl extends BasePersistenceImpl<DLFileEntry>
086            implements DLFileEntryPersistence {
087            public static final String FINDER_CLASS_NAME_ENTITY = DLFileEntryImpl.class.getName();
088            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
089                    ".List";
090            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
091                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
092                            "findByUuid",
093                            new String[] {
094                                    String.class.getName(),
095                                    
096                            "java.lang.Integer", "java.lang.Integer",
097                                    "com.liferay.portal.kernel.util.OrderByComparator"
098                            });
099            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
100                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101                            "countByUuid", new String[] { String.class.getName() });
102            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
103                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED,
104                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
105                            new String[] { String.class.getName(), Long.class.getName() });
106            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
107                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108                            "countByUUID_G",
109                            new String[] { String.class.getName(), Long.class.getName() });
110            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
111                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
112                            "findByGroupId",
113                            new String[] {
114                                    Long.class.getName(),
115                                    
116                            "java.lang.Integer", "java.lang.Integer",
117                                    "com.liferay.portal.kernel.util.OrderByComparator"
118                            });
119            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
120                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121                            "countByGroupId", new String[] { Long.class.getName() });
122            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
123                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124                            "findByCompanyId",
125                            new String[] {
126                                    Long.class.getName(),
127                                    
128                            "java.lang.Integer", "java.lang.Integer",
129                                    "com.liferay.portal.kernel.util.OrderByComparator"
130                            });
131            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
132                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133                            "countByCompanyId", new String[] { Long.class.getName() });
134            public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
135                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
136                            "findByG_U",
137                            new String[] {
138                                    Long.class.getName(), Long.class.getName(),
139                                    
140                            "java.lang.Integer", "java.lang.Integer",
141                                    "com.liferay.portal.kernel.util.OrderByComparator"
142                            });
143            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
144                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
145                            "countByG_U",
146                            new String[] { Long.class.getName(), Long.class.getName() });
147            public static final FinderPath FINDER_PATH_FIND_BY_G_F = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
148                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
149                            "findByG_F",
150                            new String[] {
151                                    Long.class.getName(), Long.class.getName(),
152                                    
153                            "java.lang.Integer", "java.lang.Integer",
154                                    "com.liferay.portal.kernel.util.OrderByComparator"
155                            });
156            public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
157                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
158                            "countByG_F",
159                            new String[] { Long.class.getName(), Long.class.getName() });
160            public static final FinderPath FINDER_PATH_FIND_BY_G_U_F = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
161                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
162                            "findByG_U_F",
163                            new String[] {
164                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
165                                    
166                            "java.lang.Integer", "java.lang.Integer",
167                                    "com.liferay.portal.kernel.util.OrderByComparator"
168                            });
169            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_F = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
170                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
171                            "countByG_U_F",
172                            new String[] {
173                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
174                            });
175            public static final FinderPath FINDER_PATH_FETCH_BY_G_F_N = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
176                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED,
177                            FINDER_CLASS_NAME_ENTITY, "fetchByG_F_N",
178                            new String[] {
179                                    Long.class.getName(), Long.class.getName(),
180                                    String.class.getName()
181                            });
182            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
183                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
184                            "countByG_F_N",
185                            new String[] {
186                                    Long.class.getName(), Long.class.getName(),
187                                    String.class.getName()
188                            });
189            public static final FinderPath FINDER_PATH_FETCH_BY_G_F_T = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
190                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED,
191                            FINDER_CLASS_NAME_ENTITY, "fetchByG_F_T",
192                            new String[] {
193                                    Long.class.getName(), Long.class.getName(),
194                                    String.class.getName()
195                            });
196            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_T = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
197                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
198                            "countByG_F_T",
199                            new String[] {
200                                    Long.class.getName(), Long.class.getName(),
201                                    String.class.getName()
202                            });
203            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
204                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
205                            "findAll", new String[0]);
206            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
207                            DLFileEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
208                            "countAll", new String[0]);
209    
210            /**
211             * Caches the d l file entry in the entity cache if it is enabled.
212             *
213             * @param dlFileEntry the d l file entry to cache
214             */
215            public void cacheResult(DLFileEntry dlFileEntry) {
216                    EntityCacheUtil.putResult(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
217                            DLFileEntryImpl.class, dlFileEntry.getPrimaryKey(), dlFileEntry);
218    
219                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
220                            new Object[] {
221                                    dlFileEntry.getUuid(), new Long(dlFileEntry.getGroupId())
222                            }, dlFileEntry);
223    
224                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N,
225                            new Object[] {
226                                    new Long(dlFileEntry.getGroupId()),
227                                    new Long(dlFileEntry.getFolderId()),
228                                    
229                            dlFileEntry.getName()
230                            }, dlFileEntry);
231    
232                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_T,
233                            new Object[] {
234                                    new Long(dlFileEntry.getGroupId()),
235                                    new Long(dlFileEntry.getFolderId()),
236                                    
237                            dlFileEntry.getTitle()
238                            }, dlFileEntry);
239            }
240    
241            /**
242             * Caches the d l file entries in the entity cache if it is enabled.
243             *
244             * @param dlFileEntries the d l file entries to cache
245             */
246            public void cacheResult(List<DLFileEntry> dlFileEntries) {
247                    for (DLFileEntry dlFileEntry : dlFileEntries) {
248                            if (EntityCacheUtil.getResult(
249                                                    DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
250                                                    DLFileEntryImpl.class, dlFileEntry.getPrimaryKey(), this) == null) {
251                                    cacheResult(dlFileEntry);
252                            }
253                    }
254            }
255    
256            /**
257             * Clears the cache for all d l file entries.
258             *
259             * <p>
260             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
261             * </p>
262             */
263            public void clearCache() {
264                    CacheRegistryUtil.clear(DLFileEntryImpl.class.getName());
265                    EntityCacheUtil.clearCache(DLFileEntryImpl.class.getName());
266                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
267                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
268            }
269    
270            /**
271             * Clears the cache for the d l file entry.
272             *
273             * <p>
274             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
275             * </p>
276             */
277            public void clearCache(DLFileEntry dlFileEntry) {
278                    EntityCacheUtil.removeResult(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
279                            DLFileEntryImpl.class, dlFileEntry.getPrimaryKey());
280    
281                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
282                            new Object[] {
283                                    dlFileEntry.getUuid(), new Long(dlFileEntry.getGroupId())
284                            });
285    
286                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N,
287                            new Object[] {
288                                    new Long(dlFileEntry.getGroupId()),
289                                    new Long(dlFileEntry.getFolderId()),
290                                    
291                            dlFileEntry.getName()
292                            });
293    
294                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_T,
295                            new Object[] {
296                                    new Long(dlFileEntry.getGroupId()),
297                                    new Long(dlFileEntry.getFolderId()),
298                                    
299                            dlFileEntry.getTitle()
300                            });
301            }
302    
303            /**
304             * Creates a new d l file entry with the primary key. Does not add the d l file entry to the database.
305             *
306             * @param fileEntryId the primary key for the new d l file entry
307             * @return the new d l file entry
308             */
309            public DLFileEntry create(long fileEntryId) {
310                    DLFileEntry dlFileEntry = new DLFileEntryImpl();
311    
312                    dlFileEntry.setNew(true);
313                    dlFileEntry.setPrimaryKey(fileEntryId);
314    
315                    String uuid = PortalUUIDUtil.generate();
316    
317                    dlFileEntry.setUuid(uuid);
318    
319                    return dlFileEntry;
320            }
321    
322            /**
323             * Removes the d l file entry with the primary key from the database. Also notifies the appropriate model listeners.
324             *
325             * @param primaryKey the primary key of the d l file entry to remove
326             * @return the d l file entry that was removed
327             * @throws com.liferay.portal.NoSuchModelException if a d l file entry with the primary key could not be found
328             * @throws SystemException if a system exception occurred
329             */
330            public DLFileEntry remove(Serializable primaryKey)
331                    throws NoSuchModelException, SystemException {
332                    return remove(((Long)primaryKey).longValue());
333            }
334    
335            /**
336             * Removes the d l file entry with the primary key from the database. Also notifies the appropriate model listeners.
337             *
338             * @param fileEntryId the primary key of the d l file entry to remove
339             * @return the d l file entry that was removed
340             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a d l file entry with the primary key could not be found
341             * @throws SystemException if a system exception occurred
342             */
343            public DLFileEntry remove(long fileEntryId)
344                    throws NoSuchFileEntryException, SystemException {
345                    Session session = null;
346    
347                    try {
348                            session = openSession();
349    
350                            DLFileEntry dlFileEntry = (DLFileEntry)session.get(DLFileEntryImpl.class,
351                                            new Long(fileEntryId));
352    
353                            if (dlFileEntry == null) {
354                                    if (_log.isWarnEnabled()) {
355                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileEntryId);
356                                    }
357    
358                                    throw new NoSuchFileEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
359                                            fileEntryId);
360                            }
361    
362                            return remove(dlFileEntry);
363                    }
364                    catch (NoSuchFileEntryException nsee) {
365                            throw nsee;
366                    }
367                    catch (Exception e) {
368                            throw processException(e);
369                    }
370                    finally {
371                            closeSession(session);
372                    }
373            }
374    
375            protected DLFileEntry removeImpl(DLFileEntry dlFileEntry)
376                    throws SystemException {
377                    dlFileEntry = toUnwrappedModel(dlFileEntry);
378    
379                    Session session = null;
380    
381                    try {
382                            session = openSession();
383    
384                            BatchSessionUtil.delete(session, dlFileEntry);
385                    }
386                    catch (Exception e) {
387                            throw processException(e);
388                    }
389                    finally {
390                            closeSession(session);
391                    }
392    
393                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
394    
395                    DLFileEntryModelImpl dlFileEntryModelImpl = (DLFileEntryModelImpl)dlFileEntry;
396    
397                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
398                            new Object[] {
399                                    dlFileEntryModelImpl.getOriginalUuid(),
400                                    new Long(dlFileEntryModelImpl.getOriginalGroupId())
401                            });
402    
403                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N,
404                            new Object[] {
405                                    new Long(dlFileEntryModelImpl.getOriginalGroupId()),
406                                    new Long(dlFileEntryModelImpl.getOriginalFolderId()),
407                                    
408                            dlFileEntryModelImpl.getOriginalName()
409                            });
410    
411                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_T,
412                            new Object[] {
413                                    new Long(dlFileEntryModelImpl.getOriginalGroupId()),
414                                    new Long(dlFileEntryModelImpl.getOriginalFolderId()),
415                                    
416                            dlFileEntryModelImpl.getOriginalTitle()
417                            });
418    
419                    EntityCacheUtil.removeResult(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
420                            DLFileEntryImpl.class, dlFileEntry.getPrimaryKey());
421    
422                    return dlFileEntry;
423            }
424    
425            public DLFileEntry updateImpl(
426                    com.liferay.portlet.documentlibrary.model.DLFileEntry dlFileEntry,
427                    boolean merge) throws SystemException {
428                    dlFileEntry = toUnwrappedModel(dlFileEntry);
429    
430                    boolean isNew = dlFileEntry.isNew();
431    
432                    DLFileEntryModelImpl dlFileEntryModelImpl = (DLFileEntryModelImpl)dlFileEntry;
433    
434                    if (Validator.isNull(dlFileEntry.getUuid())) {
435                            String uuid = PortalUUIDUtil.generate();
436    
437                            dlFileEntry.setUuid(uuid);
438                    }
439    
440                    Session session = null;
441    
442                    try {
443                            session = openSession();
444    
445                            BatchSessionUtil.update(session, dlFileEntry, merge);
446    
447                            dlFileEntry.setNew(false);
448                    }
449                    catch (Exception e) {
450                            throw processException(e);
451                    }
452                    finally {
453                            closeSession(session);
454                    }
455    
456                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
457    
458                    EntityCacheUtil.putResult(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
459                            DLFileEntryImpl.class, dlFileEntry.getPrimaryKey(), dlFileEntry);
460    
461                    if (!isNew &&
462                                    (!Validator.equals(dlFileEntry.getUuid(),
463                                            dlFileEntryModelImpl.getOriginalUuid()) ||
464                                    (dlFileEntry.getGroupId() != dlFileEntryModelImpl.getOriginalGroupId()))) {
465                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
466                                    new Object[] {
467                                            dlFileEntryModelImpl.getOriginalUuid(),
468                                            new Long(dlFileEntryModelImpl.getOriginalGroupId())
469                                    });
470                    }
471    
472                    if (isNew ||
473                                    (!Validator.equals(dlFileEntry.getUuid(),
474                                            dlFileEntryModelImpl.getOriginalUuid()) ||
475                                    (dlFileEntry.getGroupId() != dlFileEntryModelImpl.getOriginalGroupId()))) {
476                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
477                                    new Object[] {
478                                            dlFileEntry.getUuid(), new Long(dlFileEntry.getGroupId())
479                                    }, dlFileEntry);
480                    }
481    
482                    if (!isNew &&
483                                    ((dlFileEntry.getGroupId() != dlFileEntryModelImpl.getOriginalGroupId()) ||
484                                    (dlFileEntry.getFolderId() != dlFileEntryModelImpl.getOriginalFolderId()) ||
485                                    !Validator.equals(dlFileEntry.getName(),
486                                            dlFileEntryModelImpl.getOriginalName()))) {
487                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N,
488                                    new Object[] {
489                                            new Long(dlFileEntryModelImpl.getOriginalGroupId()),
490                                            new Long(dlFileEntryModelImpl.getOriginalFolderId()),
491                                            
492                                    dlFileEntryModelImpl.getOriginalName()
493                                    });
494                    }
495    
496                    if (isNew ||
497                                    ((dlFileEntry.getGroupId() != dlFileEntryModelImpl.getOriginalGroupId()) ||
498                                    (dlFileEntry.getFolderId() != dlFileEntryModelImpl.getOriginalFolderId()) ||
499                                    !Validator.equals(dlFileEntry.getName(),
500                                            dlFileEntryModelImpl.getOriginalName()))) {
501                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N,
502                                    new Object[] {
503                                            new Long(dlFileEntry.getGroupId()),
504                                            new Long(dlFileEntry.getFolderId()),
505                                            
506                                    dlFileEntry.getName()
507                                    }, dlFileEntry);
508                    }
509    
510                    if (!isNew &&
511                                    ((dlFileEntry.getGroupId() != dlFileEntryModelImpl.getOriginalGroupId()) ||
512                                    (dlFileEntry.getFolderId() != dlFileEntryModelImpl.getOriginalFolderId()) ||
513                                    !Validator.equals(dlFileEntry.getTitle(),
514                                            dlFileEntryModelImpl.getOriginalTitle()))) {
515                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_T,
516                                    new Object[] {
517                                            new Long(dlFileEntryModelImpl.getOriginalGroupId()),
518                                            new Long(dlFileEntryModelImpl.getOriginalFolderId()),
519                                            
520                                    dlFileEntryModelImpl.getOriginalTitle()
521                                    });
522                    }
523    
524                    if (isNew ||
525                                    ((dlFileEntry.getGroupId() != dlFileEntryModelImpl.getOriginalGroupId()) ||
526                                    (dlFileEntry.getFolderId() != dlFileEntryModelImpl.getOriginalFolderId()) ||
527                                    !Validator.equals(dlFileEntry.getTitle(),
528                                            dlFileEntryModelImpl.getOriginalTitle()))) {
529                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_T,
530                                    new Object[] {
531                                            new Long(dlFileEntry.getGroupId()),
532                                            new Long(dlFileEntry.getFolderId()),
533                                            
534                                    dlFileEntry.getTitle()
535                                    }, dlFileEntry);
536                    }
537    
538                    return dlFileEntry;
539            }
540    
541            protected DLFileEntry toUnwrappedModel(DLFileEntry dlFileEntry) {
542                    if (dlFileEntry instanceof DLFileEntryImpl) {
543                            return dlFileEntry;
544                    }
545    
546                    DLFileEntryImpl dlFileEntryImpl = new DLFileEntryImpl();
547    
548                    dlFileEntryImpl.setNew(dlFileEntry.isNew());
549                    dlFileEntryImpl.setPrimaryKey(dlFileEntry.getPrimaryKey());
550    
551                    dlFileEntryImpl.setUuid(dlFileEntry.getUuid());
552                    dlFileEntryImpl.setFileEntryId(dlFileEntry.getFileEntryId());
553                    dlFileEntryImpl.setGroupId(dlFileEntry.getGroupId());
554                    dlFileEntryImpl.setCompanyId(dlFileEntry.getCompanyId());
555                    dlFileEntryImpl.setUserId(dlFileEntry.getUserId());
556                    dlFileEntryImpl.setUserName(dlFileEntry.getUserName());
557                    dlFileEntryImpl.setVersionUserId(dlFileEntry.getVersionUserId());
558                    dlFileEntryImpl.setVersionUserName(dlFileEntry.getVersionUserName());
559                    dlFileEntryImpl.setCreateDate(dlFileEntry.getCreateDate());
560                    dlFileEntryImpl.setModifiedDate(dlFileEntry.getModifiedDate());
561                    dlFileEntryImpl.setFolderId(dlFileEntry.getFolderId());
562                    dlFileEntryImpl.setName(dlFileEntry.getName());
563                    dlFileEntryImpl.setExtension(dlFileEntry.getExtension());
564                    dlFileEntryImpl.setTitle(dlFileEntry.getTitle());
565                    dlFileEntryImpl.setDescription(dlFileEntry.getDescription());
566                    dlFileEntryImpl.setExtraSettings(dlFileEntry.getExtraSettings());
567                    dlFileEntryImpl.setVersion(dlFileEntry.getVersion());
568                    dlFileEntryImpl.setSize(dlFileEntry.getSize());
569                    dlFileEntryImpl.setReadCount(dlFileEntry.getReadCount());
570    
571                    return dlFileEntryImpl;
572            }
573    
574            /**
575             * Finds the d l file entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
576             *
577             * @param primaryKey the primary key of the d l file entry to find
578             * @return the d l file entry
579             * @throws com.liferay.portal.NoSuchModelException if a d l file entry with the primary key could not be found
580             * @throws SystemException if a system exception occurred
581             */
582            public DLFileEntry findByPrimaryKey(Serializable primaryKey)
583                    throws NoSuchModelException, SystemException {
584                    return findByPrimaryKey(((Long)primaryKey).longValue());
585            }
586    
587            /**
588             * Finds the d l file entry with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFileEntryException} if it could not be found.
589             *
590             * @param fileEntryId the primary key of the d l file entry to find
591             * @return the d l file entry
592             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a d l file entry with the primary key could not be found
593             * @throws SystemException if a system exception occurred
594             */
595            public DLFileEntry findByPrimaryKey(long fileEntryId)
596                    throws NoSuchFileEntryException, SystemException {
597                    DLFileEntry dlFileEntry = fetchByPrimaryKey(fileEntryId);
598    
599                    if (dlFileEntry == null) {
600                            if (_log.isWarnEnabled()) {
601                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileEntryId);
602                            }
603    
604                            throw new NoSuchFileEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
605                                    fileEntryId);
606                    }
607    
608                    return dlFileEntry;
609            }
610    
611            /**
612             * Finds the d l file entry with the primary key or returns <code>null</code> if it could not be found.
613             *
614             * @param primaryKey the primary key of the d l file entry to find
615             * @return the d l file entry, or <code>null</code> if a d l file entry with the primary key could not be found
616             * @throws SystemException if a system exception occurred
617             */
618            public DLFileEntry fetchByPrimaryKey(Serializable primaryKey)
619                    throws SystemException {
620                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
621            }
622    
623            /**
624             * Finds the d l file entry with the primary key or returns <code>null</code> if it could not be found.
625             *
626             * @param fileEntryId the primary key of the d l file entry to find
627             * @return the d l file entry, or <code>null</code> if a d l file entry with the primary key could not be found
628             * @throws SystemException if a system exception occurred
629             */
630            public DLFileEntry fetchByPrimaryKey(long fileEntryId)
631                    throws SystemException {
632                    DLFileEntry dlFileEntry = (DLFileEntry)EntityCacheUtil.getResult(DLFileEntryModelImpl.ENTITY_CACHE_ENABLED,
633                                    DLFileEntryImpl.class, fileEntryId, this);
634    
635                    if (dlFileEntry == null) {
636                            Session session = null;
637    
638                            try {
639                                    session = openSession();
640    
641                                    dlFileEntry = (DLFileEntry)session.get(DLFileEntryImpl.class,
642                                                    new Long(fileEntryId));
643                            }
644                            catch (Exception e) {
645                                    throw processException(e);
646                            }
647                            finally {
648                                    if (dlFileEntry != null) {
649                                            cacheResult(dlFileEntry);
650                                    }
651    
652                                    closeSession(session);
653                            }
654                    }
655    
656                    return dlFileEntry;
657            }
658    
659            /**
660             * Finds all the d l file entries where uuid = &#63;.
661             *
662             * @param uuid the uuid to search with
663             * @return the matching d l file entries
664             * @throws SystemException if a system exception occurred
665             */
666            public List<DLFileEntry> findByUuid(String uuid) throws SystemException {
667                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
668            }
669    
670            /**
671             * Finds a range of all the d l file entries where uuid = &#63;.
672             *
673             * <p>
674             * 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.
675             * </p>
676             *
677             * @param uuid the uuid to search with
678             * @param start the lower bound of the range of d l file entries to return
679             * @param end the upper bound of the range of d l file entries to return (not inclusive)
680             * @return the range of matching d l file entries
681             * @throws SystemException if a system exception occurred
682             */
683            public List<DLFileEntry> findByUuid(String uuid, int start, int end)
684                    throws SystemException {
685                    return findByUuid(uuid, start, end, null);
686            }
687    
688            /**
689             * Finds an ordered range of all the d l file entries where uuid = &#63;.
690             *
691             * <p>
692             * 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.
693             * </p>
694             *
695             * @param uuid the uuid to search with
696             * @param start the lower bound of the range of d l file entries to return
697             * @param end the upper bound of the range of d l file entries to return (not inclusive)
698             * @param orderByComparator the comparator to order the results by
699             * @return the ordered range of matching d l file entries
700             * @throws SystemException if a system exception occurred
701             */
702            public List<DLFileEntry> findByUuid(String uuid, int start, int end,
703                    OrderByComparator orderByComparator) throws SystemException {
704                    Object[] finderArgs = new Object[] {
705                                    uuid,
706                                    
707                                    String.valueOf(start), String.valueOf(end),
708                                    String.valueOf(orderByComparator)
709                            };
710    
711                    List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
712                                    finderArgs, this);
713    
714                    if (list == null) {
715                            Session session = null;
716    
717                            try {
718                                    session = openSession();
719    
720                                    StringBundler query = null;
721    
722                                    if (orderByComparator != null) {
723                                            query = new StringBundler(3 +
724                                                            (orderByComparator.getOrderByFields().length * 3));
725                                    }
726                                    else {
727                                            query = new StringBundler(3);
728                                    }
729    
730                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
731    
732                                    if (uuid == null) {
733                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
734                                    }
735                                    else {
736                                            if (uuid.equals(StringPool.BLANK)) {
737                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
738                                            }
739                                            else {
740                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
741                                            }
742                                    }
743    
744                                    if (orderByComparator != null) {
745                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
746                                                    orderByComparator);
747                                    }
748    
749                                    else {
750                                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
751                                    }
752    
753                                    String sql = query.toString();
754    
755                                    Query q = session.createQuery(sql);
756    
757                                    QueryPos qPos = QueryPos.getInstance(q);
758    
759                                    if (uuid != null) {
760                                            qPos.add(uuid);
761                                    }
762    
763                                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
764                                                    start, end);
765                            }
766                            catch (Exception e) {
767                                    throw processException(e);
768                            }
769                            finally {
770                                    if (list == null) {
771                                            list = new ArrayList<DLFileEntry>();
772                                    }
773    
774                                    cacheResult(list);
775    
776                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
777                                            list);
778    
779                                    closeSession(session);
780                            }
781                    }
782    
783                    return list;
784            }
785    
786            /**
787             * Finds the first d l file entry in the ordered set where uuid = &#63;.
788             *
789             * <p>
790             * 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.
791             * </p>
792             *
793             * @param uuid the uuid to search with
794             * @param orderByComparator the comparator to order the set by
795             * @return the first matching d l file entry
796             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
797             * @throws SystemException if a system exception occurred
798             */
799            public DLFileEntry findByUuid_First(String uuid,
800                    OrderByComparator orderByComparator)
801                    throws NoSuchFileEntryException, SystemException {
802                    List<DLFileEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
803    
804                    if (list.isEmpty()) {
805                            StringBundler msg = new StringBundler(4);
806    
807                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
808    
809                            msg.append("uuid=");
810                            msg.append(uuid);
811    
812                            msg.append(StringPool.CLOSE_CURLY_BRACE);
813    
814                            throw new NoSuchFileEntryException(msg.toString());
815                    }
816                    else {
817                            return list.get(0);
818                    }
819            }
820    
821            /**
822             * Finds the last d l file entry in the ordered set where uuid = &#63;.
823             *
824             * <p>
825             * 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.
826             * </p>
827             *
828             * @param uuid the uuid to search with
829             * @param orderByComparator the comparator to order the set by
830             * @return the last matching d l file entry
831             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
832             * @throws SystemException if a system exception occurred
833             */
834            public DLFileEntry findByUuid_Last(String uuid,
835                    OrderByComparator orderByComparator)
836                    throws NoSuchFileEntryException, SystemException {
837                    int count = countByUuid(uuid);
838    
839                    List<DLFileEntry> list = findByUuid(uuid, count - 1, count,
840                                    orderByComparator);
841    
842                    if (list.isEmpty()) {
843                            StringBundler msg = new StringBundler(4);
844    
845                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
846    
847                            msg.append("uuid=");
848                            msg.append(uuid);
849    
850                            msg.append(StringPool.CLOSE_CURLY_BRACE);
851    
852                            throw new NoSuchFileEntryException(msg.toString());
853                    }
854                    else {
855                            return list.get(0);
856                    }
857            }
858    
859            /**
860             * Finds the d l file entries before and after the current d l file entry in the ordered set where uuid = &#63;.
861             *
862             * <p>
863             * 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.
864             * </p>
865             *
866             * @param fileEntryId the primary key of the current d l file entry
867             * @param uuid the uuid to search with
868             * @param orderByComparator the comparator to order the set by
869             * @return the previous, current, and next d l file entry
870             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a d l file entry with the primary key could not be found
871             * @throws SystemException if a system exception occurred
872             */
873            public DLFileEntry[] findByUuid_PrevAndNext(long fileEntryId, String uuid,
874                    OrderByComparator orderByComparator)
875                    throws NoSuchFileEntryException, SystemException {
876                    DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
877    
878                    Session session = null;
879    
880                    try {
881                            session = openSession();
882    
883                            DLFileEntry[] array = new DLFileEntryImpl[3];
884    
885                            array[0] = getByUuid_PrevAndNext(session, dlFileEntry, uuid,
886                                            orderByComparator, true);
887    
888                            array[1] = dlFileEntry;
889    
890                            array[2] = getByUuid_PrevAndNext(session, dlFileEntry, uuid,
891                                            orderByComparator, false);
892    
893                            return array;
894                    }
895                    catch (Exception e) {
896                            throw processException(e);
897                    }
898                    finally {
899                            closeSession(session);
900                    }
901            }
902    
903            protected DLFileEntry getByUuid_PrevAndNext(Session session,
904                    DLFileEntry dlFileEntry, String uuid,
905                    OrderByComparator orderByComparator, boolean previous) {
906                    StringBundler query = null;
907    
908                    if (orderByComparator != null) {
909                            query = new StringBundler(6 +
910                                            (orderByComparator.getOrderByFields().length * 6));
911                    }
912                    else {
913                            query = new StringBundler(3);
914                    }
915    
916                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
917    
918                    if (uuid == null) {
919                            query.append(_FINDER_COLUMN_UUID_UUID_1);
920                    }
921                    else {
922                            if (uuid.equals(StringPool.BLANK)) {
923                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
924                            }
925                            else {
926                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
927                            }
928                    }
929    
930                    if (orderByComparator != null) {
931                            String[] orderByFields = orderByComparator.getOrderByFields();
932    
933                            if (orderByFields.length > 0) {
934                                    query.append(WHERE_AND);
935                            }
936    
937                            for (int i = 0; i < orderByFields.length; i++) {
938                                    query.append(_ORDER_BY_ENTITY_ALIAS);
939                                    query.append(orderByFields[i]);
940    
941                                    if ((i + 1) < orderByFields.length) {
942                                            if (orderByComparator.isAscending() ^ previous) {
943                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
944                                            }
945                                            else {
946                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
947                                            }
948                                    }
949                                    else {
950                                            if (orderByComparator.isAscending() ^ previous) {
951                                                    query.append(WHERE_GREATER_THAN);
952                                            }
953                                            else {
954                                                    query.append(WHERE_LESSER_THAN);
955                                            }
956                                    }
957                            }
958    
959                            query.append(ORDER_BY_CLAUSE);
960    
961                            for (int i = 0; i < orderByFields.length; i++) {
962                                    query.append(_ORDER_BY_ENTITY_ALIAS);
963                                    query.append(orderByFields[i]);
964    
965                                    if ((i + 1) < orderByFields.length) {
966                                            if (orderByComparator.isAscending() ^ previous) {
967                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
968                                            }
969                                            else {
970                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
971                                            }
972                                    }
973                                    else {
974                                            if (orderByComparator.isAscending() ^ previous) {
975                                                    query.append(ORDER_BY_ASC);
976                                            }
977                                            else {
978                                                    query.append(ORDER_BY_DESC);
979                                            }
980                                    }
981                            }
982                    }
983    
984                    else {
985                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
986                    }
987    
988                    String sql = query.toString();
989    
990                    Query q = session.createQuery(sql);
991    
992                    q.setFirstResult(0);
993                    q.setMaxResults(2);
994    
995                    QueryPos qPos = QueryPos.getInstance(q);
996    
997                    if (uuid != null) {
998                            qPos.add(uuid);
999                    }
1000    
1001                    if (orderByComparator != null) {
1002                            Object[] values = orderByComparator.getOrderByValues(dlFileEntry);
1003    
1004                            for (Object value : values) {
1005                                    qPos.add(value);
1006                            }
1007                    }
1008    
1009                    List<DLFileEntry> list = q.list();
1010    
1011                    if (list.size() == 2) {
1012                            return list.get(1);
1013                    }
1014                    else {
1015                            return null;
1016                    }
1017            }
1018    
1019            /**
1020             * Finds the d l file entry where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFileEntryException} if it could not be found.
1021             *
1022             * @param uuid the uuid to search with
1023             * @param groupId the group id to search with
1024             * @return the matching d l file entry
1025             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
1026             * @throws SystemException if a system exception occurred
1027             */
1028            public DLFileEntry findByUUID_G(String uuid, long groupId)
1029                    throws NoSuchFileEntryException, SystemException {
1030                    DLFileEntry dlFileEntry = fetchByUUID_G(uuid, groupId);
1031    
1032                    if (dlFileEntry == null) {
1033                            StringBundler msg = new StringBundler(6);
1034    
1035                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1036    
1037                            msg.append("uuid=");
1038                            msg.append(uuid);
1039    
1040                            msg.append(", groupId=");
1041                            msg.append(groupId);
1042    
1043                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1044    
1045                            if (_log.isWarnEnabled()) {
1046                                    _log.warn(msg.toString());
1047                            }
1048    
1049                            throw new NoSuchFileEntryException(msg.toString());
1050                    }
1051    
1052                    return dlFileEntry;
1053            }
1054    
1055            /**
1056             * Finds the d l file entry where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1057             *
1058             * @param uuid the uuid to search with
1059             * @param groupId the group id to search with
1060             * @return the matching d l file entry, or <code>null</code> if a matching d l file entry could not be found
1061             * @throws SystemException if a system exception occurred
1062             */
1063            public DLFileEntry fetchByUUID_G(String uuid, long groupId)
1064                    throws SystemException {
1065                    return fetchByUUID_G(uuid, groupId, true);
1066            }
1067    
1068            /**
1069             * Finds the d l file entry where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1070             *
1071             * @param uuid the uuid to search with
1072             * @param groupId the group id to search with
1073             * @return the matching d l file entry, or <code>null</code> if a matching d l file entry could not be found
1074             * @throws SystemException if a system exception occurred
1075             */
1076            public DLFileEntry fetchByUUID_G(String uuid, long groupId,
1077                    boolean retrieveFromCache) throws SystemException {
1078                    Object[] finderArgs = new Object[] { uuid, groupId };
1079    
1080                    Object result = null;
1081    
1082                    if (retrieveFromCache) {
1083                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1084                                            finderArgs, this);
1085                    }
1086    
1087                    if (result == null) {
1088                            Session session = null;
1089    
1090                            try {
1091                                    session = openSession();
1092    
1093                                    StringBundler query = new StringBundler(4);
1094    
1095                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
1096    
1097                                    if (uuid == null) {
1098                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1099                                    }
1100                                    else {
1101                                            if (uuid.equals(StringPool.BLANK)) {
1102                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1103                                            }
1104                                            else {
1105                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1106                                            }
1107                                    }
1108    
1109                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1110    
1111                                    query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
1112    
1113                                    String sql = query.toString();
1114    
1115                                    Query q = session.createQuery(sql);
1116    
1117                                    QueryPos qPos = QueryPos.getInstance(q);
1118    
1119                                    if (uuid != null) {
1120                                            qPos.add(uuid);
1121                                    }
1122    
1123                                    qPos.add(groupId);
1124    
1125                                    List<DLFileEntry> list = q.list();
1126    
1127                                    result = list;
1128    
1129                                    DLFileEntry dlFileEntry = null;
1130    
1131                                    if (list.isEmpty()) {
1132                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1133                                                    finderArgs, list);
1134                                    }
1135                                    else {
1136                                            dlFileEntry = list.get(0);
1137    
1138                                            cacheResult(dlFileEntry);
1139    
1140                                            if ((dlFileEntry.getUuid() == null) ||
1141                                                            !dlFileEntry.getUuid().equals(uuid) ||
1142                                                            (dlFileEntry.getGroupId() != groupId)) {
1143                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1144                                                            finderArgs, dlFileEntry);
1145                                            }
1146                                    }
1147    
1148                                    return dlFileEntry;
1149                            }
1150                            catch (Exception e) {
1151                                    throw processException(e);
1152                            }
1153                            finally {
1154                                    if (result == null) {
1155                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1156                                                    finderArgs, new ArrayList<DLFileEntry>());
1157                                    }
1158    
1159                                    closeSession(session);
1160                            }
1161                    }
1162                    else {
1163                            if (result instanceof List<?>) {
1164                                    return null;
1165                            }
1166                            else {
1167                                    return (DLFileEntry)result;
1168                            }
1169                    }
1170            }
1171    
1172            /**
1173             * Finds all the d l file entries where groupId = &#63;.
1174             *
1175             * @param groupId the group id to search with
1176             * @return the matching d l file entries
1177             * @throws SystemException if a system exception occurred
1178             */
1179            public List<DLFileEntry> findByGroupId(long groupId)
1180                    throws SystemException {
1181                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1182            }
1183    
1184            /**
1185             * Finds a range of all the d l file entries where groupId = &#63;.
1186             *
1187             * <p>
1188             * 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.
1189             * </p>
1190             *
1191             * @param groupId the group id to search with
1192             * @param start the lower bound of the range of d l file entries to return
1193             * @param end the upper bound of the range of d l file entries to return (not inclusive)
1194             * @return the range of matching d l file entries
1195             * @throws SystemException if a system exception occurred
1196             */
1197            public List<DLFileEntry> findByGroupId(long groupId, int start, int end)
1198                    throws SystemException {
1199                    return findByGroupId(groupId, start, end, null);
1200            }
1201    
1202            /**
1203             * Finds an ordered range of all the d l file entries where groupId = &#63;.
1204             *
1205             * <p>
1206             * 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.
1207             * </p>
1208             *
1209             * @param groupId the group id to search with
1210             * @param start the lower bound of the range of d l file entries to return
1211             * @param end the upper bound of the range of d l file entries to return (not inclusive)
1212             * @param orderByComparator the comparator to order the results by
1213             * @return the ordered range of matching d l file entries
1214             * @throws SystemException if a system exception occurred
1215             */
1216            public List<DLFileEntry> findByGroupId(long groupId, int start, int end,
1217                    OrderByComparator orderByComparator) throws SystemException {
1218                    Object[] finderArgs = new Object[] {
1219                                    groupId,
1220                                    
1221                                    String.valueOf(start), String.valueOf(end),
1222                                    String.valueOf(orderByComparator)
1223                            };
1224    
1225                    List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1226                                    finderArgs, this);
1227    
1228                    if (list == null) {
1229                            Session session = null;
1230    
1231                            try {
1232                                    session = openSession();
1233    
1234                                    StringBundler query = null;
1235    
1236                                    if (orderByComparator != null) {
1237                                            query = new StringBundler(3 +
1238                                                            (orderByComparator.getOrderByFields().length * 3));
1239                                    }
1240                                    else {
1241                                            query = new StringBundler(3);
1242                                    }
1243    
1244                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
1245    
1246                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1247    
1248                                    if (orderByComparator != null) {
1249                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1250                                                    orderByComparator);
1251                                    }
1252    
1253                                    else {
1254                                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
1255                                    }
1256    
1257                                    String sql = query.toString();
1258    
1259                                    Query q = session.createQuery(sql);
1260    
1261                                    QueryPos qPos = QueryPos.getInstance(q);
1262    
1263                                    qPos.add(groupId);
1264    
1265                                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
1266                                                    start, end);
1267                            }
1268                            catch (Exception e) {
1269                                    throw processException(e);
1270                            }
1271                            finally {
1272                                    if (list == null) {
1273                                            list = new ArrayList<DLFileEntry>();
1274                                    }
1275    
1276                                    cacheResult(list);
1277    
1278                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1279                                            finderArgs, list);
1280    
1281                                    closeSession(session);
1282                            }
1283                    }
1284    
1285                    return list;
1286            }
1287    
1288            /**
1289             * Finds the first d l file entry in the ordered set where groupId = &#63;.
1290             *
1291             * <p>
1292             * 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.
1293             * </p>
1294             *
1295             * @param groupId the group id to search with
1296             * @param orderByComparator the comparator to order the set by
1297             * @return the first matching d l file entry
1298             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
1299             * @throws SystemException if a system exception occurred
1300             */
1301            public DLFileEntry findByGroupId_First(long groupId,
1302                    OrderByComparator orderByComparator)
1303                    throws NoSuchFileEntryException, SystemException {
1304                    List<DLFileEntry> list = findByGroupId(groupId, 0, 1, orderByComparator);
1305    
1306                    if (list.isEmpty()) {
1307                            StringBundler msg = new StringBundler(4);
1308    
1309                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1310    
1311                            msg.append("groupId=");
1312                            msg.append(groupId);
1313    
1314                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1315    
1316                            throw new NoSuchFileEntryException(msg.toString());
1317                    }
1318                    else {
1319                            return list.get(0);
1320                    }
1321            }
1322    
1323            /**
1324             * Finds the last d l file entry in the ordered set where groupId = &#63;.
1325             *
1326             * <p>
1327             * 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.
1328             * </p>
1329             *
1330             * @param groupId the group id to search with
1331             * @param orderByComparator the comparator to order the set by
1332             * @return the last matching d l file entry
1333             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
1334             * @throws SystemException if a system exception occurred
1335             */
1336            public DLFileEntry findByGroupId_Last(long groupId,
1337                    OrderByComparator orderByComparator)
1338                    throws NoSuchFileEntryException, SystemException {
1339                    int count = countByGroupId(groupId);
1340    
1341                    List<DLFileEntry> list = findByGroupId(groupId, count - 1, count,
1342                                    orderByComparator);
1343    
1344                    if (list.isEmpty()) {
1345                            StringBundler msg = new StringBundler(4);
1346    
1347                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1348    
1349                            msg.append("groupId=");
1350                            msg.append(groupId);
1351    
1352                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1353    
1354                            throw new NoSuchFileEntryException(msg.toString());
1355                    }
1356                    else {
1357                            return list.get(0);
1358                    }
1359            }
1360    
1361            /**
1362             * Finds the d l file entries before and after the current d l file entry in the ordered set where groupId = &#63;.
1363             *
1364             * <p>
1365             * 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.
1366             * </p>
1367             *
1368             * @param fileEntryId the primary key of the current d l file entry
1369             * @param groupId the group id to search with
1370             * @param orderByComparator the comparator to order the set by
1371             * @return the previous, current, and next d l file entry
1372             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a d l file entry with the primary key could not be found
1373             * @throws SystemException if a system exception occurred
1374             */
1375            public DLFileEntry[] findByGroupId_PrevAndNext(long fileEntryId,
1376                    long groupId, OrderByComparator orderByComparator)
1377                    throws NoSuchFileEntryException, SystemException {
1378                    DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
1379    
1380                    Session session = null;
1381    
1382                    try {
1383                            session = openSession();
1384    
1385                            DLFileEntry[] array = new DLFileEntryImpl[3];
1386    
1387                            array[0] = getByGroupId_PrevAndNext(session, dlFileEntry, groupId,
1388                                            orderByComparator, true);
1389    
1390                            array[1] = dlFileEntry;
1391    
1392                            array[2] = getByGroupId_PrevAndNext(session, dlFileEntry, groupId,
1393                                            orderByComparator, false);
1394    
1395                            return array;
1396                    }
1397                    catch (Exception e) {
1398                            throw processException(e);
1399                    }
1400                    finally {
1401                            closeSession(session);
1402                    }
1403            }
1404    
1405            protected DLFileEntry getByGroupId_PrevAndNext(Session session,
1406                    DLFileEntry dlFileEntry, long groupId,
1407                    OrderByComparator orderByComparator, boolean previous) {
1408                    StringBundler query = null;
1409    
1410                    if (orderByComparator != null) {
1411                            query = new StringBundler(6 +
1412                                            (orderByComparator.getOrderByFields().length * 6));
1413                    }
1414                    else {
1415                            query = new StringBundler(3);
1416                    }
1417    
1418                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
1419    
1420                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1421    
1422                    if (orderByComparator != null) {
1423                            String[] orderByFields = orderByComparator.getOrderByFields();
1424    
1425                            if (orderByFields.length > 0) {
1426                                    query.append(WHERE_AND);
1427                            }
1428    
1429                            for (int i = 0; i < orderByFields.length; i++) {
1430                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1431                                    query.append(orderByFields[i]);
1432    
1433                                    if ((i + 1) < orderByFields.length) {
1434                                            if (orderByComparator.isAscending() ^ previous) {
1435                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1436                                            }
1437                                            else {
1438                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1439                                            }
1440                                    }
1441                                    else {
1442                                            if (orderByComparator.isAscending() ^ previous) {
1443                                                    query.append(WHERE_GREATER_THAN);
1444                                            }
1445                                            else {
1446                                                    query.append(WHERE_LESSER_THAN);
1447                                            }
1448                                    }
1449                            }
1450    
1451                            query.append(ORDER_BY_CLAUSE);
1452    
1453                            for (int i = 0; i < orderByFields.length; i++) {
1454                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1455                                    query.append(orderByFields[i]);
1456    
1457                                    if ((i + 1) < orderByFields.length) {
1458                                            if (orderByComparator.isAscending() ^ previous) {
1459                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1460                                            }
1461                                            else {
1462                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1463                                            }
1464                                    }
1465                                    else {
1466                                            if (orderByComparator.isAscending() ^ previous) {
1467                                                    query.append(ORDER_BY_ASC);
1468                                            }
1469                                            else {
1470                                                    query.append(ORDER_BY_DESC);
1471                                            }
1472                                    }
1473                            }
1474                    }
1475    
1476                    else {
1477                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
1478                    }
1479    
1480                    String sql = query.toString();
1481    
1482                    Query q = session.createQuery(sql);
1483    
1484                    q.setFirstResult(0);
1485                    q.setMaxResults(2);
1486    
1487                    QueryPos qPos = QueryPos.getInstance(q);
1488    
1489                    qPos.add(groupId);
1490    
1491                    if (orderByComparator != null) {
1492                            Object[] values = orderByComparator.getOrderByValues(dlFileEntry);
1493    
1494                            for (Object value : values) {
1495                                    qPos.add(value);
1496                            }
1497                    }
1498    
1499                    List<DLFileEntry> list = q.list();
1500    
1501                    if (list.size() == 2) {
1502                            return list.get(1);
1503                    }
1504                    else {
1505                            return null;
1506                    }
1507            }
1508    
1509            /**
1510             * Filters by the user's permissions and finds all the d l file entries where groupId = &#63;.
1511             *
1512             * @param groupId the group id to search with
1513             * @return the matching d l file entries that the user has permission to view
1514             * @throws SystemException if a system exception occurred
1515             */
1516            public List<DLFileEntry> filterFindByGroupId(long groupId)
1517                    throws SystemException {
1518                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1519                            QueryUtil.ALL_POS, null);
1520            }
1521    
1522            /**
1523             * Filters by the user's permissions and finds a range of all the d l file entries where groupId = &#63;.
1524             *
1525             * <p>
1526             * 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.
1527             * </p>
1528             *
1529             * @param groupId the group id to search with
1530             * @param start the lower bound of the range of d l file entries to return
1531             * @param end the upper bound of the range of d l file entries to return (not inclusive)
1532             * @return the range of matching d l file entries that the user has permission to view
1533             * @throws SystemException if a system exception occurred
1534             */
1535            public List<DLFileEntry> filterFindByGroupId(long groupId, int start,
1536                    int end) throws SystemException {
1537                    return filterFindByGroupId(groupId, start, end, null);
1538            }
1539    
1540            /**
1541             * Filters by the user's permissions and finds an ordered range of all the d l file entries where groupId = &#63;.
1542             *
1543             * <p>
1544             * 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.
1545             * </p>
1546             *
1547             * @param groupId the group id to search with
1548             * @param start the lower bound of the range of d l file entries to return
1549             * @param end the upper bound of the range of d l file entries to return (not inclusive)
1550             * @param orderByComparator the comparator to order the results by
1551             * @return the ordered range of matching d l file entries that the user has permission to view
1552             * @throws SystemException if a system exception occurred
1553             */
1554            public List<DLFileEntry> filterFindByGroupId(long groupId, int start,
1555                    int end, OrderByComparator orderByComparator) throws SystemException {
1556                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1557                            return findByGroupId(groupId, start, end, orderByComparator);
1558                    }
1559    
1560                    Session session = null;
1561    
1562                    try {
1563                            session = openSession();
1564    
1565                            StringBundler query = null;
1566    
1567                            if (orderByComparator != null) {
1568                                    query = new StringBundler(3 +
1569                                                    (orderByComparator.getOrderByFields().length * 3));
1570                            }
1571                            else {
1572                                    query = new StringBundler(3);
1573                            }
1574    
1575                            if (getDB().isSupportsInlineDistinct()) {
1576                                    query.append(_FILTER_SQL_SELECT_DLFILEENTRY_WHERE);
1577                            }
1578                            else {
1579                                    query.append(_FILTER_SQL_SELECT_DLFILEENTRY_NO_INLINE_DISTINCT_WHERE);
1580                            }
1581    
1582                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1583    
1584                            if (orderByComparator != null) {
1585                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1586                                            orderByComparator);
1587                            }
1588    
1589                            else {
1590                                    query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
1591                            }
1592    
1593                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1594                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
1595                                            _FILTER_COLUMN_USERID, groupId);
1596    
1597                            SQLQuery q = session.createSQLQuery(sql);
1598    
1599                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFileEntryImpl.class);
1600    
1601                            QueryPos qPos = QueryPos.getInstance(q);
1602    
1603                            qPos.add(groupId);
1604    
1605                            return (List<DLFileEntry>)QueryUtil.list(q, getDialect(), start, end);
1606                    }
1607                    catch (Exception e) {
1608                            throw processException(e);
1609                    }
1610                    finally {
1611                            closeSession(session);
1612                    }
1613            }
1614    
1615            /**
1616             * Finds all the d l file entries where companyId = &#63;.
1617             *
1618             * @param companyId the company id to search with
1619             * @return the matching d l file entries
1620             * @throws SystemException if a system exception occurred
1621             */
1622            public List<DLFileEntry> findByCompanyId(long companyId)
1623                    throws SystemException {
1624                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1625                            null);
1626            }
1627    
1628            /**
1629             * Finds a range of all the d l file entries where companyId = &#63;.
1630             *
1631             * <p>
1632             * 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.
1633             * </p>
1634             *
1635             * @param companyId the company id to search with
1636             * @param start the lower bound of the range of d l file entries to return
1637             * @param end the upper bound of the range of d l file entries to return (not inclusive)
1638             * @return the range of matching d l file entries
1639             * @throws SystemException if a system exception occurred
1640             */
1641            public List<DLFileEntry> findByCompanyId(long companyId, int start, int end)
1642                    throws SystemException {
1643                    return findByCompanyId(companyId, start, end, null);
1644            }
1645    
1646            /**
1647             * Finds an ordered range of all the d l file entries where companyId = &#63;.
1648             *
1649             * <p>
1650             * 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.
1651             * </p>
1652             *
1653             * @param companyId the company id to search with
1654             * @param start the lower bound of the range of d l file entries to return
1655             * @param end the upper bound of the range of d l file entries to return (not inclusive)
1656             * @param orderByComparator the comparator to order the results by
1657             * @return the ordered range of matching d l file entries
1658             * @throws SystemException if a system exception occurred
1659             */
1660            public List<DLFileEntry> findByCompanyId(long companyId, int start,
1661                    int end, OrderByComparator orderByComparator) throws SystemException {
1662                    Object[] finderArgs = new Object[] {
1663                                    companyId,
1664                                    
1665                                    String.valueOf(start), String.valueOf(end),
1666                                    String.valueOf(orderByComparator)
1667                            };
1668    
1669                    List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1670                                    finderArgs, this);
1671    
1672                    if (list == null) {
1673                            Session session = null;
1674    
1675                            try {
1676                                    session = openSession();
1677    
1678                                    StringBundler query = null;
1679    
1680                                    if (orderByComparator != null) {
1681                                            query = new StringBundler(3 +
1682                                                            (orderByComparator.getOrderByFields().length * 3));
1683                                    }
1684                                    else {
1685                                            query = new StringBundler(3);
1686                                    }
1687    
1688                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
1689    
1690                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1691    
1692                                    if (orderByComparator != null) {
1693                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1694                                                    orderByComparator);
1695                                    }
1696    
1697                                    else {
1698                                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
1699                                    }
1700    
1701                                    String sql = query.toString();
1702    
1703                                    Query q = session.createQuery(sql);
1704    
1705                                    QueryPos qPos = QueryPos.getInstance(q);
1706    
1707                                    qPos.add(companyId);
1708    
1709                                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
1710                                                    start, end);
1711                            }
1712                            catch (Exception e) {
1713                                    throw processException(e);
1714                            }
1715                            finally {
1716                                    if (list == null) {
1717                                            list = new ArrayList<DLFileEntry>();
1718                                    }
1719    
1720                                    cacheResult(list);
1721    
1722                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1723                                            finderArgs, list);
1724    
1725                                    closeSession(session);
1726                            }
1727                    }
1728    
1729                    return list;
1730            }
1731    
1732            /**
1733             * Finds the first d l file entry in the ordered set where companyId = &#63;.
1734             *
1735             * <p>
1736             * 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.
1737             * </p>
1738             *
1739             * @param companyId the company id to search with
1740             * @param orderByComparator the comparator to order the set by
1741             * @return the first matching d l file entry
1742             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
1743             * @throws SystemException if a system exception occurred
1744             */
1745            public DLFileEntry findByCompanyId_First(long companyId,
1746                    OrderByComparator orderByComparator)
1747                    throws NoSuchFileEntryException, SystemException {
1748                    List<DLFileEntry> list = findByCompanyId(companyId, 0, 1,
1749                                    orderByComparator);
1750    
1751                    if (list.isEmpty()) {
1752                            StringBundler msg = new StringBundler(4);
1753    
1754                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1755    
1756                            msg.append("companyId=");
1757                            msg.append(companyId);
1758    
1759                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1760    
1761                            throw new NoSuchFileEntryException(msg.toString());
1762                    }
1763                    else {
1764                            return list.get(0);
1765                    }
1766            }
1767    
1768            /**
1769             * Finds the last d l file entry in the ordered set where companyId = &#63;.
1770             *
1771             * <p>
1772             * 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.
1773             * </p>
1774             *
1775             * @param companyId the company id to search with
1776             * @param orderByComparator the comparator to order the set by
1777             * @return the last matching d l file entry
1778             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
1779             * @throws SystemException if a system exception occurred
1780             */
1781            public DLFileEntry findByCompanyId_Last(long companyId,
1782                    OrderByComparator orderByComparator)
1783                    throws NoSuchFileEntryException, SystemException {
1784                    int count = countByCompanyId(companyId);
1785    
1786                    List<DLFileEntry> list = findByCompanyId(companyId, count - 1, count,
1787                                    orderByComparator);
1788    
1789                    if (list.isEmpty()) {
1790                            StringBundler msg = new StringBundler(4);
1791    
1792                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1793    
1794                            msg.append("companyId=");
1795                            msg.append(companyId);
1796    
1797                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1798    
1799                            throw new NoSuchFileEntryException(msg.toString());
1800                    }
1801                    else {
1802                            return list.get(0);
1803                    }
1804            }
1805    
1806            /**
1807             * Finds the d l file entries before and after the current d l file entry in the ordered set where companyId = &#63;.
1808             *
1809             * <p>
1810             * 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.
1811             * </p>
1812             *
1813             * @param fileEntryId the primary key of the current d l file entry
1814             * @param companyId the company id to search with
1815             * @param orderByComparator the comparator to order the set by
1816             * @return the previous, current, and next d l file entry
1817             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a d l file entry with the primary key could not be found
1818             * @throws SystemException if a system exception occurred
1819             */
1820            public DLFileEntry[] findByCompanyId_PrevAndNext(long fileEntryId,
1821                    long companyId, OrderByComparator orderByComparator)
1822                    throws NoSuchFileEntryException, SystemException {
1823                    DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
1824    
1825                    Session session = null;
1826    
1827                    try {
1828                            session = openSession();
1829    
1830                            DLFileEntry[] array = new DLFileEntryImpl[3];
1831    
1832                            array[0] = getByCompanyId_PrevAndNext(session, dlFileEntry,
1833                                            companyId, orderByComparator, true);
1834    
1835                            array[1] = dlFileEntry;
1836    
1837                            array[2] = getByCompanyId_PrevAndNext(session, dlFileEntry,
1838                                            companyId, orderByComparator, false);
1839    
1840                            return array;
1841                    }
1842                    catch (Exception e) {
1843                            throw processException(e);
1844                    }
1845                    finally {
1846                            closeSession(session);
1847                    }
1848            }
1849    
1850            protected DLFileEntry getByCompanyId_PrevAndNext(Session session,
1851                    DLFileEntry dlFileEntry, long companyId,
1852                    OrderByComparator orderByComparator, boolean previous) {
1853                    StringBundler query = null;
1854    
1855                    if (orderByComparator != null) {
1856                            query = new StringBundler(6 +
1857                                            (orderByComparator.getOrderByFields().length * 6));
1858                    }
1859                    else {
1860                            query = new StringBundler(3);
1861                    }
1862    
1863                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
1864    
1865                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1866    
1867                    if (orderByComparator != null) {
1868                            String[] orderByFields = orderByComparator.getOrderByFields();
1869    
1870                            if (orderByFields.length > 0) {
1871                                    query.append(WHERE_AND);
1872                            }
1873    
1874                            for (int i = 0; i < orderByFields.length; i++) {
1875                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1876                                    query.append(orderByFields[i]);
1877    
1878                                    if ((i + 1) < orderByFields.length) {
1879                                            if (orderByComparator.isAscending() ^ previous) {
1880                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1881                                            }
1882                                            else {
1883                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1884                                            }
1885                                    }
1886                                    else {
1887                                            if (orderByComparator.isAscending() ^ previous) {
1888                                                    query.append(WHERE_GREATER_THAN);
1889                                            }
1890                                            else {
1891                                                    query.append(WHERE_LESSER_THAN);
1892                                            }
1893                                    }
1894                            }
1895    
1896                            query.append(ORDER_BY_CLAUSE);
1897    
1898                            for (int i = 0; i < orderByFields.length; i++) {
1899                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1900                                    query.append(orderByFields[i]);
1901    
1902                                    if ((i + 1) < orderByFields.length) {
1903                                            if (orderByComparator.isAscending() ^ previous) {
1904                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1905                                            }
1906                                            else {
1907                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1908                                            }
1909                                    }
1910                                    else {
1911                                            if (orderByComparator.isAscending() ^ previous) {
1912                                                    query.append(ORDER_BY_ASC);
1913                                            }
1914                                            else {
1915                                                    query.append(ORDER_BY_DESC);
1916                                            }
1917                                    }
1918                            }
1919                    }
1920    
1921                    else {
1922                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
1923                    }
1924    
1925                    String sql = query.toString();
1926    
1927                    Query q = session.createQuery(sql);
1928    
1929                    q.setFirstResult(0);
1930                    q.setMaxResults(2);
1931    
1932                    QueryPos qPos = QueryPos.getInstance(q);
1933    
1934                    qPos.add(companyId);
1935    
1936                    if (orderByComparator != null) {
1937                            Object[] values = orderByComparator.getOrderByValues(dlFileEntry);
1938    
1939                            for (Object value : values) {
1940                                    qPos.add(value);
1941                            }
1942                    }
1943    
1944                    List<DLFileEntry> list = q.list();
1945    
1946                    if (list.size() == 2) {
1947                            return list.get(1);
1948                    }
1949                    else {
1950                            return null;
1951                    }
1952            }
1953    
1954            /**
1955             * Finds all the d l file entries where groupId = &#63; and userId = &#63;.
1956             *
1957             * @param groupId the group id to search with
1958             * @param userId the user id to search with
1959             * @return the matching d l file entries
1960             * @throws SystemException if a system exception occurred
1961             */
1962            public List<DLFileEntry> findByG_U(long groupId, long userId)
1963                    throws SystemException {
1964                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1965                            null);
1966            }
1967    
1968            /**
1969             * Finds a range of all the d l file entries where groupId = &#63; and userId = &#63;.
1970             *
1971             * <p>
1972             * 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.
1973             * </p>
1974             *
1975             * @param groupId the group id to search with
1976             * @param userId the user id to search with
1977             * @param start the lower bound of the range of d l file entries to return
1978             * @param end the upper bound of the range of d l file entries to return (not inclusive)
1979             * @return the range of matching d l file entries
1980             * @throws SystemException if a system exception occurred
1981             */
1982            public List<DLFileEntry> findByG_U(long groupId, long userId, int start,
1983                    int end) throws SystemException {
1984                    return findByG_U(groupId, userId, start, end, null);
1985            }
1986    
1987            /**
1988             * Finds an ordered range of all the d l file entries where groupId = &#63; and userId = &#63;.
1989             *
1990             * <p>
1991             * 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.
1992             * </p>
1993             *
1994             * @param groupId the group id to search with
1995             * @param userId the user id to search with
1996             * @param start the lower bound of the range of d l file entries to return
1997             * @param end the upper bound of the range of d l file entries to return (not inclusive)
1998             * @param orderByComparator the comparator to order the results by
1999             * @return the ordered range of matching d l file entries
2000             * @throws SystemException if a system exception occurred
2001             */
2002            public List<DLFileEntry> findByG_U(long groupId, long userId, int start,
2003                    int end, OrderByComparator orderByComparator) throws SystemException {
2004                    Object[] finderArgs = new Object[] {
2005                                    groupId, userId,
2006                                    
2007                                    String.valueOf(start), String.valueOf(end),
2008                                    String.valueOf(orderByComparator)
2009                            };
2010    
2011                    List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
2012                                    finderArgs, this);
2013    
2014                    if (list == null) {
2015                            Session session = null;
2016    
2017                            try {
2018                                    session = openSession();
2019    
2020                                    StringBundler query = null;
2021    
2022                                    if (orderByComparator != null) {
2023                                            query = new StringBundler(4 +
2024                                                            (orderByComparator.getOrderByFields().length * 3));
2025                                    }
2026                                    else {
2027                                            query = new StringBundler(4);
2028                                    }
2029    
2030                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
2031    
2032                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2033    
2034                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
2035    
2036                                    if (orderByComparator != null) {
2037                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2038                                                    orderByComparator);
2039                                    }
2040    
2041                                    else {
2042                                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
2043                                    }
2044    
2045                                    String sql = query.toString();
2046    
2047                                    Query q = session.createQuery(sql);
2048    
2049                                    QueryPos qPos = QueryPos.getInstance(q);
2050    
2051                                    qPos.add(groupId);
2052    
2053                                    qPos.add(userId);
2054    
2055                                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
2056                                                    start, end);
2057                            }
2058                            catch (Exception e) {
2059                                    throw processException(e);
2060                            }
2061                            finally {
2062                                    if (list == null) {
2063                                            list = new ArrayList<DLFileEntry>();
2064                                    }
2065    
2066                                    cacheResult(list);
2067    
2068                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
2069                                            list);
2070    
2071                                    closeSession(session);
2072                            }
2073                    }
2074    
2075                    return list;
2076            }
2077    
2078            /**
2079             * Finds the first d l file entry in the ordered set where groupId = &#63; and userId = &#63;.
2080             *
2081             * <p>
2082             * 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.
2083             * </p>
2084             *
2085             * @param groupId the group id to search with
2086             * @param userId the user id to search with
2087             * @param orderByComparator the comparator to order the set by
2088             * @return the first matching d l file entry
2089             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
2090             * @throws SystemException if a system exception occurred
2091             */
2092            public DLFileEntry findByG_U_First(long groupId, long userId,
2093                    OrderByComparator orderByComparator)
2094                    throws NoSuchFileEntryException, SystemException {
2095                    List<DLFileEntry> list = findByG_U(groupId, userId, 0, 1,
2096                                    orderByComparator);
2097    
2098                    if (list.isEmpty()) {
2099                            StringBundler msg = new StringBundler(6);
2100    
2101                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2102    
2103                            msg.append("groupId=");
2104                            msg.append(groupId);
2105    
2106                            msg.append(", userId=");
2107                            msg.append(userId);
2108    
2109                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2110    
2111                            throw new NoSuchFileEntryException(msg.toString());
2112                    }
2113                    else {
2114                            return list.get(0);
2115                    }
2116            }
2117    
2118            /**
2119             * Finds the last d l file entry in the ordered set where groupId = &#63; and userId = &#63;.
2120             *
2121             * <p>
2122             * 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.
2123             * </p>
2124             *
2125             * @param groupId the group id to search with
2126             * @param userId the user id to search with
2127             * @param orderByComparator the comparator to order the set by
2128             * @return the last matching d l file entry
2129             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
2130             * @throws SystemException if a system exception occurred
2131             */
2132            public DLFileEntry findByG_U_Last(long groupId, long userId,
2133                    OrderByComparator orderByComparator)
2134                    throws NoSuchFileEntryException, SystemException {
2135                    int count = countByG_U(groupId, userId);
2136    
2137                    List<DLFileEntry> list = findByG_U(groupId, userId, count - 1, count,
2138                                    orderByComparator);
2139    
2140                    if (list.isEmpty()) {
2141                            StringBundler msg = new StringBundler(6);
2142    
2143                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2144    
2145                            msg.append("groupId=");
2146                            msg.append(groupId);
2147    
2148                            msg.append(", userId=");
2149                            msg.append(userId);
2150    
2151                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2152    
2153                            throw new NoSuchFileEntryException(msg.toString());
2154                    }
2155                    else {
2156                            return list.get(0);
2157                    }
2158            }
2159    
2160            /**
2161             * Finds the d l file entries before and after the current d l file entry in the ordered set where groupId = &#63; and userId = &#63;.
2162             *
2163             * <p>
2164             * 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.
2165             * </p>
2166             *
2167             * @param fileEntryId the primary key of the current d l file entry
2168             * @param groupId the group id to search with
2169             * @param userId the user id to search with
2170             * @param orderByComparator the comparator to order the set by
2171             * @return the previous, current, and next d l file entry
2172             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a d l file entry with the primary key could not be found
2173             * @throws SystemException if a system exception occurred
2174             */
2175            public DLFileEntry[] findByG_U_PrevAndNext(long fileEntryId, long groupId,
2176                    long userId, OrderByComparator orderByComparator)
2177                    throws NoSuchFileEntryException, SystemException {
2178                    DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
2179    
2180                    Session session = null;
2181    
2182                    try {
2183                            session = openSession();
2184    
2185                            DLFileEntry[] array = new DLFileEntryImpl[3];
2186    
2187                            array[0] = getByG_U_PrevAndNext(session, dlFileEntry, groupId,
2188                                            userId, orderByComparator, true);
2189    
2190                            array[1] = dlFileEntry;
2191    
2192                            array[2] = getByG_U_PrevAndNext(session, dlFileEntry, groupId,
2193                                            userId, orderByComparator, false);
2194    
2195                            return array;
2196                    }
2197                    catch (Exception e) {
2198                            throw processException(e);
2199                    }
2200                    finally {
2201                            closeSession(session);
2202                    }
2203            }
2204    
2205            protected DLFileEntry getByG_U_PrevAndNext(Session session,
2206                    DLFileEntry dlFileEntry, long groupId, long userId,
2207                    OrderByComparator orderByComparator, boolean previous) {
2208                    StringBundler query = null;
2209    
2210                    if (orderByComparator != null) {
2211                            query = new StringBundler(6 +
2212                                            (orderByComparator.getOrderByFields().length * 6));
2213                    }
2214                    else {
2215                            query = new StringBundler(3);
2216                    }
2217    
2218                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
2219    
2220                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2221    
2222                    query.append(_FINDER_COLUMN_G_U_USERID_2);
2223    
2224                    if (orderByComparator != null) {
2225                            String[] orderByFields = orderByComparator.getOrderByFields();
2226    
2227                            if (orderByFields.length > 0) {
2228                                    query.append(WHERE_AND);
2229                            }
2230    
2231                            for (int i = 0; i < orderByFields.length; i++) {
2232                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2233                                    query.append(orderByFields[i]);
2234    
2235                                    if ((i + 1) < orderByFields.length) {
2236                                            if (orderByComparator.isAscending() ^ previous) {
2237                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2238                                            }
2239                                            else {
2240                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2241                                            }
2242                                    }
2243                                    else {
2244                                            if (orderByComparator.isAscending() ^ previous) {
2245                                                    query.append(WHERE_GREATER_THAN);
2246                                            }
2247                                            else {
2248                                                    query.append(WHERE_LESSER_THAN);
2249                                            }
2250                                    }
2251                            }
2252    
2253                            query.append(ORDER_BY_CLAUSE);
2254    
2255                            for (int i = 0; i < orderByFields.length; i++) {
2256                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2257                                    query.append(orderByFields[i]);
2258    
2259                                    if ((i + 1) < orderByFields.length) {
2260                                            if (orderByComparator.isAscending() ^ previous) {
2261                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2262                                            }
2263                                            else {
2264                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2265                                            }
2266                                    }
2267                                    else {
2268                                            if (orderByComparator.isAscending() ^ previous) {
2269                                                    query.append(ORDER_BY_ASC);
2270                                            }
2271                                            else {
2272                                                    query.append(ORDER_BY_DESC);
2273                                            }
2274                                    }
2275                            }
2276                    }
2277    
2278                    else {
2279                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
2280                    }
2281    
2282                    String sql = query.toString();
2283    
2284                    Query q = session.createQuery(sql);
2285    
2286                    q.setFirstResult(0);
2287                    q.setMaxResults(2);
2288    
2289                    QueryPos qPos = QueryPos.getInstance(q);
2290    
2291                    qPos.add(groupId);
2292    
2293                    qPos.add(userId);
2294    
2295                    if (orderByComparator != null) {
2296                            Object[] values = orderByComparator.getOrderByValues(dlFileEntry);
2297    
2298                            for (Object value : values) {
2299                                    qPos.add(value);
2300                            }
2301                    }
2302    
2303                    List<DLFileEntry> list = q.list();
2304    
2305                    if (list.size() == 2) {
2306                            return list.get(1);
2307                    }
2308                    else {
2309                            return null;
2310                    }
2311            }
2312    
2313            /**
2314             * Filters by the user's permissions and finds all the d l file entries where groupId = &#63; and userId = &#63;.
2315             *
2316             * @param groupId the group id to search with
2317             * @param userId the user id to search with
2318             * @return the matching d l file entries that the user has permission to view
2319             * @throws SystemException if a system exception occurred
2320             */
2321            public List<DLFileEntry> filterFindByG_U(long groupId, long userId)
2322                    throws SystemException {
2323                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
2324                            QueryUtil.ALL_POS, null);
2325            }
2326    
2327            /**
2328             * Filters by the user's permissions and finds a range of all the d l file entries where groupId = &#63; and userId = &#63;.
2329             *
2330             * <p>
2331             * 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.
2332             * </p>
2333             *
2334             * @param groupId the group id to search with
2335             * @param userId the user id to search with
2336             * @param start the lower bound of the range of d l file entries to return
2337             * @param end the upper bound of the range of d l file entries to return (not inclusive)
2338             * @return the range of matching d l file entries that the user has permission to view
2339             * @throws SystemException if a system exception occurred
2340             */
2341            public List<DLFileEntry> filterFindByG_U(long groupId, long userId,
2342                    int start, int end) throws SystemException {
2343                    return filterFindByG_U(groupId, userId, start, end, null);
2344            }
2345    
2346            /**
2347             * Filters by the user's permissions and finds an ordered range of all the d l file entries where groupId = &#63; and userId = &#63;.
2348             *
2349             * <p>
2350             * 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.
2351             * </p>
2352             *
2353             * @param groupId the group id to search with
2354             * @param userId the user id to search with
2355             * @param start the lower bound of the range of d l file entries to return
2356             * @param end the upper bound of the range of d l file entries to return (not inclusive)
2357             * @param orderByComparator the comparator to order the results by
2358             * @return the ordered range of matching d l file entries that the user has permission to view
2359             * @throws SystemException if a system exception occurred
2360             */
2361            public List<DLFileEntry> filterFindByG_U(long groupId, long userId,
2362                    int start, int end, OrderByComparator orderByComparator)
2363                    throws SystemException {
2364                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2365                            return findByG_U(groupId, userId, start, end, orderByComparator);
2366                    }
2367    
2368                    Session session = null;
2369    
2370                    try {
2371                            session = openSession();
2372    
2373                            StringBundler query = null;
2374    
2375                            if (orderByComparator != null) {
2376                                    query = new StringBundler(4 +
2377                                                    (orderByComparator.getOrderByFields().length * 3));
2378                            }
2379                            else {
2380                                    query = new StringBundler(4);
2381                            }
2382    
2383                            if (getDB().isSupportsInlineDistinct()) {
2384                                    query.append(_FILTER_SQL_SELECT_DLFILEENTRY_WHERE);
2385                            }
2386                            else {
2387                                    query.append(_FILTER_SQL_SELECT_DLFILEENTRY_NO_INLINE_DISTINCT_WHERE);
2388                            }
2389    
2390                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2391    
2392                            query.append(_FINDER_COLUMN_G_U_USERID_2);
2393    
2394                            if (orderByComparator != null) {
2395                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2396                                            orderByComparator);
2397                            }
2398    
2399                            else {
2400                                    query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
2401                            }
2402    
2403                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2404                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
2405                                            _FILTER_COLUMN_USERID, groupId);
2406    
2407                            SQLQuery q = session.createSQLQuery(sql);
2408    
2409                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFileEntryImpl.class);
2410    
2411                            QueryPos qPos = QueryPos.getInstance(q);
2412    
2413                            qPos.add(groupId);
2414    
2415                            qPos.add(userId);
2416    
2417                            return (List<DLFileEntry>)QueryUtil.list(q, getDialect(), start, end);
2418                    }
2419                    catch (Exception e) {
2420                            throw processException(e);
2421                    }
2422                    finally {
2423                            closeSession(session);
2424                    }
2425            }
2426    
2427            /**
2428             * Finds all the d l file entries where groupId = &#63; and folderId = &#63;.
2429             *
2430             * @param groupId the group id to search with
2431             * @param folderId the folder id to search with
2432             * @return the matching d l file entries
2433             * @throws SystemException if a system exception occurred
2434             */
2435            public List<DLFileEntry> findByG_F(long groupId, long folderId)
2436                    throws SystemException {
2437                    return findByG_F(groupId, folderId, QueryUtil.ALL_POS,
2438                            QueryUtil.ALL_POS, null);
2439            }
2440    
2441            /**
2442             * Finds a range of all the d l file entries where groupId = &#63; and folderId = &#63;.
2443             *
2444             * <p>
2445             * 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.
2446             * </p>
2447             *
2448             * @param groupId the group id to search with
2449             * @param folderId the folder id to search with
2450             * @param start the lower bound of the range of d l file entries to return
2451             * @param end the upper bound of the range of d l file entries to return (not inclusive)
2452             * @return the range of matching d l file entries
2453             * @throws SystemException if a system exception occurred
2454             */
2455            public List<DLFileEntry> findByG_F(long groupId, long folderId, int start,
2456                    int end) throws SystemException {
2457                    return findByG_F(groupId, folderId, start, end, null);
2458            }
2459    
2460            /**
2461             * Finds an ordered range of all the d l file entries where groupId = &#63; and folderId = &#63;.
2462             *
2463             * <p>
2464             * 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.
2465             * </p>
2466             *
2467             * @param groupId the group id to search with
2468             * @param folderId the folder id to search with
2469             * @param start the lower bound of the range of d l file entries to return
2470             * @param end the upper bound of the range of d l file entries to return (not inclusive)
2471             * @param orderByComparator the comparator to order the results by
2472             * @return the ordered range of matching d l file entries
2473             * @throws SystemException if a system exception occurred
2474             */
2475            public List<DLFileEntry> findByG_F(long groupId, long folderId, int start,
2476                    int end, OrderByComparator orderByComparator) throws SystemException {
2477                    Object[] finderArgs = new Object[] {
2478                                    groupId, folderId,
2479                                    
2480                                    String.valueOf(start), String.valueOf(end),
2481                                    String.valueOf(orderByComparator)
2482                            };
2483    
2484                    List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F,
2485                                    finderArgs, this);
2486    
2487                    if (list == null) {
2488                            Session session = null;
2489    
2490                            try {
2491                                    session = openSession();
2492    
2493                                    StringBundler query = null;
2494    
2495                                    if (orderByComparator != null) {
2496                                            query = new StringBundler(4 +
2497                                                            (orderByComparator.getOrderByFields().length * 3));
2498                                    }
2499                                    else {
2500                                            query = new StringBundler(4);
2501                                    }
2502    
2503                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
2504    
2505                                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2506    
2507                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
2508    
2509                                    if (orderByComparator != null) {
2510                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2511                                                    orderByComparator);
2512                                    }
2513    
2514                                    else {
2515                                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
2516                                    }
2517    
2518                                    String sql = query.toString();
2519    
2520                                    Query q = session.createQuery(sql);
2521    
2522                                    QueryPos qPos = QueryPos.getInstance(q);
2523    
2524                                    qPos.add(groupId);
2525    
2526                                    qPos.add(folderId);
2527    
2528                                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
2529                                                    start, end);
2530                            }
2531                            catch (Exception e) {
2532                                    throw processException(e);
2533                            }
2534                            finally {
2535                                    if (list == null) {
2536                                            list = new ArrayList<DLFileEntry>();
2537                                    }
2538    
2539                                    cacheResult(list);
2540    
2541                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F, finderArgs,
2542                                            list);
2543    
2544                                    closeSession(session);
2545                            }
2546                    }
2547    
2548                    return list;
2549            }
2550    
2551            /**
2552             * Finds the first d l file entry in the ordered set where groupId = &#63; and folderId = &#63;.
2553             *
2554             * <p>
2555             * 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.
2556             * </p>
2557             *
2558             * @param groupId the group id to search with
2559             * @param folderId the folder id to search with
2560             * @param orderByComparator the comparator to order the set by
2561             * @return the first matching d l file entry
2562             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
2563             * @throws SystemException if a system exception occurred
2564             */
2565            public DLFileEntry findByG_F_First(long groupId, long folderId,
2566                    OrderByComparator orderByComparator)
2567                    throws NoSuchFileEntryException, SystemException {
2568                    List<DLFileEntry> list = findByG_F(groupId, folderId, 0, 1,
2569                                    orderByComparator);
2570    
2571                    if (list.isEmpty()) {
2572                            StringBundler msg = new StringBundler(6);
2573    
2574                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2575    
2576                            msg.append("groupId=");
2577                            msg.append(groupId);
2578    
2579                            msg.append(", folderId=");
2580                            msg.append(folderId);
2581    
2582                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2583    
2584                            throw new NoSuchFileEntryException(msg.toString());
2585                    }
2586                    else {
2587                            return list.get(0);
2588                    }
2589            }
2590    
2591            /**
2592             * Finds the last d l file entry in the ordered set where groupId = &#63; and folderId = &#63;.
2593             *
2594             * <p>
2595             * 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.
2596             * </p>
2597             *
2598             * @param groupId the group id to search with
2599             * @param folderId the folder id to search with
2600             * @param orderByComparator the comparator to order the set by
2601             * @return the last matching d l file entry
2602             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
2603             * @throws SystemException if a system exception occurred
2604             */
2605            public DLFileEntry findByG_F_Last(long groupId, long folderId,
2606                    OrderByComparator orderByComparator)
2607                    throws NoSuchFileEntryException, SystemException {
2608                    int count = countByG_F(groupId, folderId);
2609    
2610                    List<DLFileEntry> list = findByG_F(groupId, folderId, count - 1, count,
2611                                    orderByComparator);
2612    
2613                    if (list.isEmpty()) {
2614                            StringBundler msg = new StringBundler(6);
2615    
2616                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2617    
2618                            msg.append("groupId=");
2619                            msg.append(groupId);
2620    
2621                            msg.append(", folderId=");
2622                            msg.append(folderId);
2623    
2624                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2625    
2626                            throw new NoSuchFileEntryException(msg.toString());
2627                    }
2628                    else {
2629                            return list.get(0);
2630                    }
2631            }
2632    
2633            /**
2634             * Finds the d l file entries before and after the current d l file entry in the ordered set where groupId = &#63; and folderId = &#63;.
2635             *
2636             * <p>
2637             * 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.
2638             * </p>
2639             *
2640             * @param fileEntryId the primary key of the current d l file entry
2641             * @param groupId the group id to search with
2642             * @param folderId the folder id to search with
2643             * @param orderByComparator the comparator to order the set by
2644             * @return the previous, current, and next d l file entry
2645             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a d l file entry with the primary key could not be found
2646             * @throws SystemException if a system exception occurred
2647             */
2648            public DLFileEntry[] findByG_F_PrevAndNext(long fileEntryId, long groupId,
2649                    long folderId, OrderByComparator orderByComparator)
2650                    throws NoSuchFileEntryException, SystemException {
2651                    DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
2652    
2653                    Session session = null;
2654    
2655                    try {
2656                            session = openSession();
2657    
2658                            DLFileEntry[] array = new DLFileEntryImpl[3];
2659    
2660                            array[0] = getByG_F_PrevAndNext(session, dlFileEntry, groupId,
2661                                            folderId, orderByComparator, true);
2662    
2663                            array[1] = dlFileEntry;
2664    
2665                            array[2] = getByG_F_PrevAndNext(session, dlFileEntry, groupId,
2666                                            folderId, orderByComparator, false);
2667    
2668                            return array;
2669                    }
2670                    catch (Exception e) {
2671                            throw processException(e);
2672                    }
2673                    finally {
2674                            closeSession(session);
2675                    }
2676            }
2677    
2678            protected DLFileEntry getByG_F_PrevAndNext(Session session,
2679                    DLFileEntry dlFileEntry, long groupId, long folderId,
2680                    OrderByComparator orderByComparator, boolean previous) {
2681                    StringBundler query = null;
2682    
2683                    if (orderByComparator != null) {
2684                            query = new StringBundler(6 +
2685                                            (orderByComparator.getOrderByFields().length * 6));
2686                    }
2687                    else {
2688                            query = new StringBundler(3);
2689                    }
2690    
2691                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
2692    
2693                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
2694    
2695                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
2696    
2697                    if (orderByComparator != null) {
2698                            String[] orderByFields = orderByComparator.getOrderByFields();
2699    
2700                            if (orderByFields.length > 0) {
2701                                    query.append(WHERE_AND);
2702                            }
2703    
2704                            for (int i = 0; i < orderByFields.length; i++) {
2705                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2706                                    query.append(orderByFields[i]);
2707    
2708                                    if ((i + 1) < orderByFields.length) {
2709                                            if (orderByComparator.isAscending() ^ previous) {
2710                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2711                                            }
2712                                            else {
2713                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2714                                            }
2715                                    }
2716                                    else {
2717                                            if (orderByComparator.isAscending() ^ previous) {
2718                                                    query.append(WHERE_GREATER_THAN);
2719                                            }
2720                                            else {
2721                                                    query.append(WHERE_LESSER_THAN);
2722                                            }
2723                                    }
2724                            }
2725    
2726                            query.append(ORDER_BY_CLAUSE);
2727    
2728                            for (int i = 0; i < orderByFields.length; i++) {
2729                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2730                                    query.append(orderByFields[i]);
2731    
2732                                    if ((i + 1) < orderByFields.length) {
2733                                            if (orderByComparator.isAscending() ^ previous) {
2734                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2735                                            }
2736                                            else {
2737                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2738                                            }
2739                                    }
2740                                    else {
2741                                            if (orderByComparator.isAscending() ^ previous) {
2742                                                    query.append(ORDER_BY_ASC);
2743                                            }
2744                                            else {
2745                                                    query.append(ORDER_BY_DESC);
2746                                            }
2747                                    }
2748                            }
2749                    }
2750    
2751                    else {
2752                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
2753                    }
2754    
2755                    String sql = query.toString();
2756    
2757                    Query q = session.createQuery(sql);
2758    
2759                    q.setFirstResult(0);
2760                    q.setMaxResults(2);
2761    
2762                    QueryPos qPos = QueryPos.getInstance(q);
2763    
2764                    qPos.add(groupId);
2765    
2766                    qPos.add(folderId);
2767    
2768                    if (orderByComparator != null) {
2769                            Object[] values = orderByComparator.getOrderByValues(dlFileEntry);
2770    
2771                            for (Object value : values) {
2772                                    qPos.add(value);
2773                            }
2774                    }
2775    
2776                    List<DLFileEntry> list = q.list();
2777    
2778                    if (list.size() == 2) {
2779                            return list.get(1);
2780                    }
2781                    else {
2782                            return null;
2783                    }
2784            }
2785    
2786            /**
2787             * Finds all the d l file entries where groupId = &#63; and folderId = any &#63;.
2788             *
2789             * <p>
2790             * 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.
2791             * </p>
2792             *
2793             * @param groupId the group id to search with
2794             * @param folderIds the folder ids to search with
2795             * @return the matching d l file entries
2796             * @throws SystemException if a system exception occurred
2797             */
2798            public List<DLFileEntry> findByG_F(long groupId, long[] folderIds)
2799                    throws SystemException {
2800                    return findByG_F(groupId, folderIds, QueryUtil.ALL_POS,
2801                            QueryUtil.ALL_POS, null);
2802            }
2803    
2804            /**
2805             * Finds a range of all the d l file entries where groupId = &#63; and folderId = any &#63;.
2806             *
2807             * <p>
2808             * 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.
2809             * </p>
2810             *
2811             * @param groupId the group id to search with
2812             * @param folderIds the folder ids to search with
2813             * @param start the lower bound of the range of d l file entries to return
2814             * @param end the upper bound of the range of d l file entries to return (not inclusive)
2815             * @return the range of matching d l file entries
2816             * @throws SystemException if a system exception occurred
2817             */
2818            public List<DLFileEntry> findByG_F(long groupId, long[] folderIds,
2819                    int start, int end) throws SystemException {
2820                    return findByG_F(groupId, folderIds, start, end, null);
2821            }
2822    
2823            /**
2824             * Finds an ordered range of all the d l file entries where groupId = &#63; and folderId = any &#63;.
2825             *
2826             * <p>
2827             * 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.
2828             * </p>
2829             *
2830             * @param groupId the group id to search with
2831             * @param folderIds the folder ids to search with
2832             * @param start the lower bound of the range of d l file entries to return
2833             * @param end the upper bound of the range of d l file entries to return (not inclusive)
2834             * @param orderByComparator the comparator to order the results by
2835             * @return the ordered range of matching d l file entries
2836             * @throws SystemException if a system exception occurred
2837             */
2838            public List<DLFileEntry> findByG_F(long groupId, long[] folderIds,
2839                    int start, int end, OrderByComparator orderByComparator)
2840                    throws SystemException {
2841                    Object[] finderArgs = new Object[] {
2842                                    groupId, StringUtil.merge(folderIds),
2843                                    
2844                                    String.valueOf(start), String.valueOf(end),
2845                                    String.valueOf(orderByComparator)
2846                            };
2847    
2848                    List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F,
2849                                    finderArgs, this);
2850    
2851                    if (list == null) {
2852                            Session session = null;
2853    
2854                            try {
2855                                    session = openSession();
2856    
2857                                    StringBundler query = new StringBundler();
2858    
2859                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
2860    
2861                                    boolean conjunctionable = false;
2862    
2863                                    if (conjunctionable) {
2864                                            query.append(WHERE_AND);
2865                                    }
2866    
2867                                    query.append(_FINDER_COLUMN_G_F_GROUPID_5);
2868    
2869                                    conjunctionable = true;
2870    
2871                                    if ((folderIds == null) || (folderIds.length > 0)) {
2872                                            if (conjunctionable) {
2873                                                    query.append(WHERE_AND);
2874                                            }
2875    
2876                                            query.append(StringPool.OPEN_PARENTHESIS);
2877    
2878                                            for (int i = 0; i < folderIds.length; i++) {
2879                                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
2880    
2881                                                    if ((i + 1) < folderIds.length) {
2882                                                            query.append(WHERE_OR);
2883                                                    }
2884                                            }
2885    
2886                                            query.append(StringPool.CLOSE_PARENTHESIS);
2887    
2888                                            conjunctionable = true;
2889                                    }
2890    
2891                                    if (orderByComparator != null) {
2892                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2893                                                    orderByComparator);
2894                                    }
2895    
2896                                    else {
2897                                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
2898                                    }
2899    
2900                                    String sql = query.toString();
2901    
2902                                    Query q = session.createQuery(sql);
2903    
2904                                    QueryPos qPos = QueryPos.getInstance(q);
2905    
2906                                    qPos.add(groupId);
2907    
2908                                    if (folderIds != null) {
2909                                            qPos.add(folderIds);
2910                                    }
2911    
2912                                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
2913                                                    start, end);
2914                            }
2915                            catch (Exception e) {
2916                                    throw processException(e);
2917                            }
2918                            finally {
2919                                    if (list == null) {
2920                                            list = new ArrayList<DLFileEntry>();
2921                                    }
2922    
2923                                    cacheResult(list);
2924    
2925                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F, finderArgs,
2926                                            list);
2927    
2928                                    closeSession(session);
2929                            }
2930                    }
2931    
2932                    return list;
2933            }
2934    
2935            /**
2936             * Filters by the user's permissions and finds all the d l file entries where groupId = &#63; and folderId = &#63;.
2937             *
2938             * @param groupId the group id to search with
2939             * @param folderId the folder id to search with
2940             * @return the matching d l file entries that the user has permission to view
2941             * @throws SystemException if a system exception occurred
2942             */
2943            public List<DLFileEntry> filterFindByG_F(long groupId, long folderId)
2944                    throws SystemException {
2945                    return filterFindByG_F(groupId, folderId, QueryUtil.ALL_POS,
2946                            QueryUtil.ALL_POS, null);
2947            }
2948    
2949            /**
2950             * Filters by the user's permissions and finds a range of all the d l file entries where groupId = &#63; and folderId = &#63;.
2951             *
2952             * <p>
2953             * 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.
2954             * </p>
2955             *
2956             * @param groupId the group id to search with
2957             * @param folderId the folder id to search with
2958             * @param start the lower bound of the range of d l file entries to return
2959             * @param end the upper bound of the range of d l file entries to return (not inclusive)
2960             * @return the range of matching d l file entries that the user has permission to view
2961             * @throws SystemException if a system exception occurred
2962             */
2963            public List<DLFileEntry> filterFindByG_F(long groupId, long folderId,
2964                    int start, int end) throws SystemException {
2965                    return filterFindByG_F(groupId, folderId, start, end, null);
2966            }
2967    
2968            /**
2969             * Filters by the user's permissions and finds an ordered range of all the d l file entries where groupId = &#63; and folderId = &#63;.
2970             *
2971             * <p>
2972             * 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.
2973             * </p>
2974             *
2975             * @param groupId the group id to search with
2976             * @param folderId the folder id to search with
2977             * @param start the lower bound of the range of d l file entries to return
2978             * @param end the upper bound of the range of d l file entries to return (not inclusive)
2979             * @param orderByComparator the comparator to order the results by
2980             * @return the ordered range of matching d l file entries that the user has permission to view
2981             * @throws SystemException if a system exception occurred
2982             */
2983            public List<DLFileEntry> filterFindByG_F(long groupId, long folderId,
2984                    int start, int end, OrderByComparator orderByComparator)
2985                    throws SystemException {
2986                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2987                            return findByG_F(groupId, folderId, start, end, orderByComparator);
2988                    }
2989    
2990                    Session session = null;
2991    
2992                    try {
2993                            session = openSession();
2994    
2995                            StringBundler query = null;
2996    
2997                            if (orderByComparator != null) {
2998                                    query = new StringBundler(4 +
2999                                                    (orderByComparator.getOrderByFields().length * 3));
3000                            }
3001                            else {
3002                                    query = new StringBundler(4);
3003                            }
3004    
3005                            if (getDB().isSupportsInlineDistinct()) {
3006                                    query.append(_FILTER_SQL_SELECT_DLFILEENTRY_WHERE);
3007                            }
3008                            else {
3009                                    query.append(_FILTER_SQL_SELECT_DLFILEENTRY_NO_INLINE_DISTINCT_WHERE);
3010                            }
3011    
3012                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
3013    
3014                            query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
3015    
3016                            if (orderByComparator != null) {
3017                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3018                                            orderByComparator);
3019                            }
3020    
3021                            else {
3022                                    query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
3023                            }
3024    
3025                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3026                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
3027                                            _FILTER_COLUMN_USERID, groupId);
3028    
3029                            SQLQuery q = session.createSQLQuery(sql);
3030    
3031                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFileEntryImpl.class);
3032    
3033                            QueryPos qPos = QueryPos.getInstance(q);
3034    
3035                            qPos.add(groupId);
3036    
3037                            qPos.add(folderId);
3038    
3039                            return (List<DLFileEntry>)QueryUtil.list(q, getDialect(), start, end);
3040                    }
3041                    catch (Exception e) {
3042                            throw processException(e);
3043                    }
3044                    finally {
3045                            closeSession(session);
3046                    }
3047            }
3048    
3049            /**
3050             * Filters by the user's permissions and finds all the d l file entries where groupId = &#63; and folderId = any &#63;.
3051             *
3052             * <p>
3053             * 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.
3054             * </p>
3055             *
3056             * @param groupId the group id to search with
3057             * @param folderIds the folder ids to search with
3058             * @return the matching d l file entries that the user has permission to view
3059             * @throws SystemException if a system exception occurred
3060             */
3061            public List<DLFileEntry> filterFindByG_F(long groupId, long[] folderIds)
3062                    throws SystemException {
3063                    return filterFindByG_F(groupId, folderIds, QueryUtil.ALL_POS,
3064                            QueryUtil.ALL_POS, null);
3065            }
3066    
3067            /**
3068             * Filters by the user's permissions and finds a range of all the d l file entries where groupId = &#63; and folderId = any &#63;.
3069             *
3070             * <p>
3071             * 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.
3072             * </p>
3073             *
3074             * @param groupId the group id to search with
3075             * @param folderIds the folder ids to search with
3076             * @param start the lower bound of the range of d l file entries to return
3077             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3078             * @return the range of matching d l file entries that the user has permission to view
3079             * @throws SystemException if a system exception occurred
3080             */
3081            public List<DLFileEntry> filterFindByG_F(long groupId, long[] folderIds,
3082                    int start, int end) throws SystemException {
3083                    return filterFindByG_F(groupId, folderIds, start, end, null);
3084            }
3085    
3086            /**
3087             * Filters by the user's permissions and finds an ordered range of all the d l file entries where groupId = &#63; and folderId = any &#63;.
3088             *
3089             * <p>
3090             * 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.
3091             * </p>
3092             *
3093             * @param groupId the group id to search with
3094             * @param folderIds the folder ids to search with
3095             * @param start the lower bound of the range of d l file entries to return
3096             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3097             * @param orderByComparator the comparator to order the results by
3098             * @return the ordered range of matching d l file entries that the user has permission to view
3099             * @throws SystemException if a system exception occurred
3100             */
3101            public List<DLFileEntry> filterFindByG_F(long groupId, long[] folderIds,
3102                    int start, int end, OrderByComparator orderByComparator)
3103                    throws SystemException {
3104                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3105                            return findByG_F(groupId, folderIds, start, end, orderByComparator);
3106                    }
3107    
3108                    Session session = null;
3109    
3110                    try {
3111                            session = openSession();
3112    
3113                            StringBundler query = new StringBundler();
3114    
3115                            query.append(_FILTER_SQL_SELECT_DLFILEENTRY_WHERE);
3116    
3117                            boolean conjunctionable = false;
3118    
3119                            if (conjunctionable) {
3120                                    query.append(WHERE_AND);
3121                            }
3122    
3123                            query.append(_FINDER_COLUMN_G_F_GROUPID_5);
3124    
3125                            conjunctionable = true;
3126    
3127                            if ((folderIds == null) || (folderIds.length > 0)) {
3128                                    if (conjunctionable) {
3129                                            query.append(WHERE_AND);
3130                                    }
3131    
3132                                    query.append(StringPool.OPEN_PARENTHESIS);
3133    
3134                                    for (int i = 0; i < folderIds.length; i++) {
3135                                            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
3136    
3137                                            if ((i + 1) < folderIds.length) {
3138                                                    query.append(WHERE_OR);
3139                                            }
3140                                    }
3141    
3142                                    query.append(StringPool.CLOSE_PARENTHESIS);
3143    
3144                                    conjunctionable = true;
3145                            }
3146    
3147                            if (orderByComparator != null) {
3148                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3149                                            orderByComparator);
3150                            }
3151    
3152                            else {
3153                                    query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
3154                            }
3155    
3156                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3157                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
3158                                            _FILTER_COLUMN_USERID, groupId);
3159    
3160                            SQLQuery q = session.createSQLQuery(sql);
3161    
3162                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFileEntryImpl.class);
3163    
3164                            QueryPos qPos = QueryPos.getInstance(q);
3165    
3166                            qPos.add(groupId);
3167    
3168                            if (folderIds != null) {
3169                                    qPos.add(folderIds);
3170                            }
3171    
3172                            return (List<DLFileEntry>)QueryUtil.list(q, getDialect(), start, end);
3173                    }
3174                    catch (Exception e) {
3175                            throw processException(e);
3176                    }
3177                    finally {
3178                            closeSession(session);
3179                    }
3180            }
3181    
3182            /**
3183             * Finds all the d l file entries where groupId = &#63; and userId = &#63; and folderId = &#63;.
3184             *
3185             * @param groupId the group id to search with
3186             * @param userId the user id to search with
3187             * @param folderId the folder id to search with
3188             * @return the matching d l file entries
3189             * @throws SystemException if a system exception occurred
3190             */
3191            public List<DLFileEntry> findByG_U_F(long groupId, long userId,
3192                    long folderId) throws SystemException {
3193                    return findByG_U_F(groupId, userId, folderId, QueryUtil.ALL_POS,
3194                            QueryUtil.ALL_POS, null);
3195            }
3196    
3197            /**
3198             * Finds a range of all the d l file entries where groupId = &#63; and userId = &#63; and folderId = &#63;.
3199             *
3200             * <p>
3201             * 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.
3202             * </p>
3203             *
3204             * @param groupId the group id to search with
3205             * @param userId the user id to search with
3206             * @param folderId the folder id to search with
3207             * @param start the lower bound of the range of d l file entries to return
3208             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3209             * @return the range of matching d l file entries
3210             * @throws SystemException if a system exception occurred
3211             */
3212            public List<DLFileEntry> findByG_U_F(long groupId, long userId,
3213                    long folderId, int start, int end) throws SystemException {
3214                    return findByG_U_F(groupId, userId, folderId, start, end, null);
3215            }
3216    
3217            /**
3218             * Finds an ordered range of all the d l file entries where groupId = &#63; and userId = &#63; and folderId = &#63;.
3219             *
3220             * <p>
3221             * 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.
3222             * </p>
3223             *
3224             * @param groupId the group id to search with
3225             * @param userId the user id to search with
3226             * @param folderId the folder id to search with
3227             * @param start the lower bound of the range of d l file entries to return
3228             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3229             * @param orderByComparator the comparator to order the results by
3230             * @return the ordered range of matching d l file entries
3231             * @throws SystemException if a system exception occurred
3232             */
3233            public List<DLFileEntry> findByG_U_F(long groupId, long userId,
3234                    long folderId, int start, int end, OrderByComparator orderByComparator)
3235                    throws SystemException {
3236                    Object[] finderArgs = new Object[] {
3237                                    groupId, userId, folderId,
3238                                    
3239                                    String.valueOf(start), String.valueOf(end),
3240                                    String.valueOf(orderByComparator)
3241                            };
3242    
3243                    List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U_F,
3244                                    finderArgs, this);
3245    
3246                    if (list == null) {
3247                            Session session = null;
3248    
3249                            try {
3250                                    session = openSession();
3251    
3252                                    StringBundler query = null;
3253    
3254                                    if (orderByComparator != null) {
3255                                            query = new StringBundler(5 +
3256                                                            (orderByComparator.getOrderByFields().length * 3));
3257                                    }
3258                                    else {
3259                                            query = new StringBundler(5);
3260                                    }
3261    
3262                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
3263    
3264                                    query.append(_FINDER_COLUMN_G_U_F_GROUPID_2);
3265    
3266                                    query.append(_FINDER_COLUMN_G_U_F_USERID_2);
3267    
3268                                    query.append(_FINDER_COLUMN_G_U_F_FOLDERID_2);
3269    
3270                                    if (orderByComparator != null) {
3271                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3272                                                    orderByComparator);
3273                                    }
3274    
3275                                    else {
3276                                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
3277                                    }
3278    
3279                                    String sql = query.toString();
3280    
3281                                    Query q = session.createQuery(sql);
3282    
3283                                    QueryPos qPos = QueryPos.getInstance(q);
3284    
3285                                    qPos.add(groupId);
3286    
3287                                    qPos.add(userId);
3288    
3289                                    qPos.add(folderId);
3290    
3291                                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
3292                                                    start, end);
3293                            }
3294                            catch (Exception e) {
3295                                    throw processException(e);
3296                            }
3297                            finally {
3298                                    if (list == null) {
3299                                            list = new ArrayList<DLFileEntry>();
3300                                    }
3301    
3302                                    cacheResult(list);
3303    
3304                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U_F,
3305                                            finderArgs, list);
3306    
3307                                    closeSession(session);
3308                            }
3309                    }
3310    
3311                    return list;
3312            }
3313    
3314            /**
3315             * Finds the first d l file entry in the ordered set where groupId = &#63; and userId = &#63; and folderId = &#63;.
3316             *
3317             * <p>
3318             * 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.
3319             * </p>
3320             *
3321             * @param groupId the group id to search with
3322             * @param userId the user id to search with
3323             * @param folderId the folder id to search with
3324             * @param orderByComparator the comparator to order the set by
3325             * @return the first matching d l file entry
3326             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
3327             * @throws SystemException if a system exception occurred
3328             */
3329            public DLFileEntry findByG_U_F_First(long groupId, long userId,
3330                    long folderId, OrderByComparator orderByComparator)
3331                    throws NoSuchFileEntryException, SystemException {
3332                    List<DLFileEntry> list = findByG_U_F(groupId, userId, folderId, 0, 1,
3333                                    orderByComparator);
3334    
3335                    if (list.isEmpty()) {
3336                            StringBundler msg = new StringBundler(8);
3337    
3338                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3339    
3340                            msg.append("groupId=");
3341                            msg.append(groupId);
3342    
3343                            msg.append(", userId=");
3344                            msg.append(userId);
3345    
3346                            msg.append(", folderId=");
3347                            msg.append(folderId);
3348    
3349                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3350    
3351                            throw new NoSuchFileEntryException(msg.toString());
3352                    }
3353                    else {
3354                            return list.get(0);
3355                    }
3356            }
3357    
3358            /**
3359             * Finds the last d l file entry in the ordered set where groupId = &#63; and userId = &#63; and folderId = &#63;.
3360             *
3361             * <p>
3362             * 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.
3363             * </p>
3364             *
3365             * @param groupId the group id to search with
3366             * @param userId the user id to search with
3367             * @param folderId the folder id to search with
3368             * @param orderByComparator the comparator to order the set by
3369             * @return the last matching d l file entry
3370             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
3371             * @throws SystemException if a system exception occurred
3372             */
3373            public DLFileEntry findByG_U_F_Last(long groupId, long userId,
3374                    long folderId, OrderByComparator orderByComparator)
3375                    throws NoSuchFileEntryException, SystemException {
3376                    int count = countByG_U_F(groupId, userId, folderId);
3377    
3378                    List<DLFileEntry> list = findByG_U_F(groupId, userId, folderId,
3379                                    count - 1, count, orderByComparator);
3380    
3381                    if (list.isEmpty()) {
3382                            StringBundler msg = new StringBundler(8);
3383    
3384                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3385    
3386                            msg.append("groupId=");
3387                            msg.append(groupId);
3388    
3389                            msg.append(", userId=");
3390                            msg.append(userId);
3391    
3392                            msg.append(", folderId=");
3393                            msg.append(folderId);
3394    
3395                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3396    
3397                            throw new NoSuchFileEntryException(msg.toString());
3398                    }
3399                    else {
3400                            return list.get(0);
3401                    }
3402            }
3403    
3404            /**
3405             * Finds the d l file entries before and after the current d l file entry in the ordered set where groupId = &#63; and userId = &#63; and folderId = &#63;.
3406             *
3407             * <p>
3408             * 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.
3409             * </p>
3410             *
3411             * @param fileEntryId the primary key of the current d l file entry
3412             * @param groupId the group id to search with
3413             * @param userId the user id to search with
3414             * @param folderId the folder id to search with
3415             * @param orderByComparator the comparator to order the set by
3416             * @return the previous, current, and next d l file entry
3417             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a d l file entry with the primary key could not be found
3418             * @throws SystemException if a system exception occurred
3419             */
3420            public DLFileEntry[] findByG_U_F_PrevAndNext(long fileEntryId,
3421                    long groupId, long userId, long folderId,
3422                    OrderByComparator orderByComparator)
3423                    throws NoSuchFileEntryException, SystemException {
3424                    DLFileEntry dlFileEntry = findByPrimaryKey(fileEntryId);
3425    
3426                    Session session = null;
3427    
3428                    try {
3429                            session = openSession();
3430    
3431                            DLFileEntry[] array = new DLFileEntryImpl[3];
3432    
3433                            array[0] = getByG_U_F_PrevAndNext(session, dlFileEntry, groupId,
3434                                            userId, folderId, orderByComparator, true);
3435    
3436                            array[1] = dlFileEntry;
3437    
3438                            array[2] = getByG_U_F_PrevAndNext(session, dlFileEntry, groupId,
3439                                            userId, folderId, orderByComparator, false);
3440    
3441                            return array;
3442                    }
3443                    catch (Exception e) {
3444                            throw processException(e);
3445                    }
3446                    finally {
3447                            closeSession(session);
3448                    }
3449            }
3450    
3451            protected DLFileEntry getByG_U_F_PrevAndNext(Session session,
3452                    DLFileEntry dlFileEntry, long groupId, long userId, long folderId,
3453                    OrderByComparator orderByComparator, boolean previous) {
3454                    StringBundler query = null;
3455    
3456                    if (orderByComparator != null) {
3457                            query = new StringBundler(6 +
3458                                            (orderByComparator.getOrderByFields().length * 6));
3459                    }
3460                    else {
3461                            query = new StringBundler(3);
3462                    }
3463    
3464                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
3465    
3466                    query.append(_FINDER_COLUMN_G_U_F_GROUPID_2);
3467    
3468                    query.append(_FINDER_COLUMN_G_U_F_USERID_2);
3469    
3470                    query.append(_FINDER_COLUMN_G_U_F_FOLDERID_2);
3471    
3472                    if (orderByComparator != null) {
3473                            String[] orderByFields = orderByComparator.getOrderByFields();
3474    
3475                            if (orderByFields.length > 0) {
3476                                    query.append(WHERE_AND);
3477                            }
3478    
3479                            for (int i = 0; i < orderByFields.length; i++) {
3480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3481                                    query.append(orderByFields[i]);
3482    
3483                                    if ((i + 1) < orderByFields.length) {
3484                                            if (orderByComparator.isAscending() ^ previous) {
3485                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3486                                            }
3487                                            else {
3488                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3489                                            }
3490                                    }
3491                                    else {
3492                                            if (orderByComparator.isAscending() ^ previous) {
3493                                                    query.append(WHERE_GREATER_THAN);
3494                                            }
3495                                            else {
3496                                                    query.append(WHERE_LESSER_THAN);
3497                                            }
3498                                    }
3499                            }
3500    
3501                            query.append(ORDER_BY_CLAUSE);
3502    
3503                            for (int i = 0; i < orderByFields.length; i++) {
3504                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3505                                    query.append(orderByFields[i]);
3506    
3507                                    if ((i + 1) < orderByFields.length) {
3508                                            if (orderByComparator.isAscending() ^ previous) {
3509                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3510                                            }
3511                                            else {
3512                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3513                                            }
3514                                    }
3515                                    else {
3516                                            if (orderByComparator.isAscending() ^ previous) {
3517                                                    query.append(ORDER_BY_ASC);
3518                                            }
3519                                            else {
3520                                                    query.append(ORDER_BY_DESC);
3521                                            }
3522                                    }
3523                            }
3524                    }
3525    
3526                    else {
3527                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
3528                    }
3529    
3530                    String sql = query.toString();
3531    
3532                    Query q = session.createQuery(sql);
3533    
3534                    q.setFirstResult(0);
3535                    q.setMaxResults(2);
3536    
3537                    QueryPos qPos = QueryPos.getInstance(q);
3538    
3539                    qPos.add(groupId);
3540    
3541                    qPos.add(userId);
3542    
3543                    qPos.add(folderId);
3544    
3545                    if (orderByComparator != null) {
3546                            Object[] values = orderByComparator.getOrderByValues(dlFileEntry);
3547    
3548                            for (Object value : values) {
3549                                    qPos.add(value);
3550                            }
3551                    }
3552    
3553                    List<DLFileEntry> list = q.list();
3554    
3555                    if (list.size() == 2) {
3556                            return list.get(1);
3557                    }
3558                    else {
3559                            return null;
3560                    }
3561            }
3562    
3563            /**
3564             * Finds all the d l file entries where groupId = &#63; and userId = &#63; and folderId = any &#63;.
3565             *
3566             * <p>
3567             * 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.
3568             * </p>
3569             *
3570             * @param groupId the group id to search with
3571             * @param userId the user id to search with
3572             * @param folderIds the folder ids to search with
3573             * @return the matching d l file entries
3574             * @throws SystemException if a system exception occurred
3575             */
3576            public List<DLFileEntry> findByG_U_F(long groupId, long userId,
3577                    long[] folderIds) throws SystemException {
3578                    return findByG_U_F(groupId, userId, folderIds, QueryUtil.ALL_POS,
3579                            QueryUtil.ALL_POS, null);
3580            }
3581    
3582            /**
3583             * Finds a range of all the d l file entries where groupId = &#63; and userId = &#63; and folderId = any &#63;.
3584             *
3585             * <p>
3586             * 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.
3587             * </p>
3588             *
3589             * @param groupId the group id to search with
3590             * @param userId the user id to search with
3591             * @param folderIds the folder ids to search with
3592             * @param start the lower bound of the range of d l file entries to return
3593             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3594             * @return the range of matching d l file entries
3595             * @throws SystemException if a system exception occurred
3596             */
3597            public List<DLFileEntry> findByG_U_F(long groupId, long userId,
3598                    long[] folderIds, int start, int end) throws SystemException {
3599                    return findByG_U_F(groupId, userId, folderIds, start, end, null);
3600            }
3601    
3602            /**
3603             * Finds an ordered range of all the d l file entries where groupId = &#63; and userId = &#63; and folderId = any &#63;.
3604             *
3605             * <p>
3606             * 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.
3607             * </p>
3608             *
3609             * @param groupId the group id to search with
3610             * @param userId the user id to search with
3611             * @param folderIds the folder ids to search with
3612             * @param start the lower bound of the range of d l file entries to return
3613             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3614             * @param orderByComparator the comparator to order the results by
3615             * @return the ordered range of matching d l file entries
3616             * @throws SystemException if a system exception occurred
3617             */
3618            public List<DLFileEntry> findByG_U_F(long groupId, long userId,
3619                    long[] folderIds, int start, int end,
3620                    OrderByComparator orderByComparator) throws SystemException {
3621                    Object[] finderArgs = new Object[] {
3622                                    groupId, userId, StringUtil.merge(folderIds),
3623                                    
3624                                    String.valueOf(start), String.valueOf(end),
3625                                    String.valueOf(orderByComparator)
3626                            };
3627    
3628                    List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U_F,
3629                                    finderArgs, this);
3630    
3631                    if (list == null) {
3632                            Session session = null;
3633    
3634                            try {
3635                                    session = openSession();
3636    
3637                                    StringBundler query = new StringBundler();
3638    
3639                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
3640    
3641                                    boolean conjunctionable = false;
3642    
3643                                    if (conjunctionable) {
3644                                            query.append(WHERE_AND);
3645                                    }
3646    
3647                                    query.append(_FINDER_COLUMN_G_U_F_GROUPID_5);
3648    
3649                                    conjunctionable = true;
3650    
3651                                    if (conjunctionable) {
3652                                            query.append(WHERE_AND);
3653                                    }
3654    
3655                                    query.append(_FINDER_COLUMN_G_U_F_USERID_5);
3656    
3657                                    conjunctionable = true;
3658    
3659                                    if ((folderIds == null) || (folderIds.length > 0)) {
3660                                            if (conjunctionable) {
3661                                                    query.append(WHERE_AND);
3662                                            }
3663    
3664                                            query.append(StringPool.OPEN_PARENTHESIS);
3665    
3666                                            for (int i = 0; i < folderIds.length; i++) {
3667                                                    query.append(_FINDER_COLUMN_G_U_F_FOLDERID_5);
3668    
3669                                                    if ((i + 1) < folderIds.length) {
3670                                                            query.append(WHERE_OR);
3671                                                    }
3672                                            }
3673    
3674                                            query.append(StringPool.CLOSE_PARENTHESIS);
3675    
3676                                            conjunctionable = true;
3677                                    }
3678    
3679                                    if (orderByComparator != null) {
3680                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3681                                                    orderByComparator);
3682                                    }
3683    
3684                                    else {
3685                                            query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
3686                                    }
3687    
3688                                    String sql = query.toString();
3689    
3690                                    Query q = session.createQuery(sql);
3691    
3692                                    QueryPos qPos = QueryPos.getInstance(q);
3693    
3694                                    qPos.add(groupId);
3695    
3696                                    qPos.add(userId);
3697    
3698                                    if (folderIds != null) {
3699                                            qPos.add(folderIds);
3700                                    }
3701    
3702                                    list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
3703                                                    start, end);
3704                            }
3705                            catch (Exception e) {
3706                                    throw processException(e);
3707                            }
3708                            finally {
3709                                    if (list == null) {
3710                                            list = new ArrayList<DLFileEntry>();
3711                                    }
3712    
3713                                    cacheResult(list);
3714    
3715                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U_F,
3716                                            finderArgs, list);
3717    
3718                                    closeSession(session);
3719                            }
3720                    }
3721    
3722                    return list;
3723            }
3724    
3725            /**
3726             * Filters by the user's permissions and finds all the d l file entries where groupId = &#63; and userId = &#63; and folderId = &#63;.
3727             *
3728             * @param groupId the group id to search with
3729             * @param userId the user id to search with
3730             * @param folderId the folder id to search with
3731             * @return the matching d l file entries that the user has permission to view
3732             * @throws SystemException if a system exception occurred
3733             */
3734            public List<DLFileEntry> filterFindByG_U_F(long groupId, long userId,
3735                    long folderId) throws SystemException {
3736                    return filterFindByG_U_F(groupId, userId, folderId, QueryUtil.ALL_POS,
3737                            QueryUtil.ALL_POS, null);
3738            }
3739    
3740            /**
3741             * Filters by the user's permissions and finds a range of all the d l file entries where groupId = &#63; and userId = &#63; and folderId = &#63;.
3742             *
3743             * <p>
3744             * 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.
3745             * </p>
3746             *
3747             * @param groupId the group id to search with
3748             * @param userId the user id to search with
3749             * @param folderId the folder id to search with
3750             * @param start the lower bound of the range of d l file entries to return
3751             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3752             * @return the range of matching d l file entries that the user has permission to view
3753             * @throws SystemException if a system exception occurred
3754             */
3755            public List<DLFileEntry> filterFindByG_U_F(long groupId, long userId,
3756                    long folderId, int start, int end) throws SystemException {
3757                    return filterFindByG_U_F(groupId, userId, folderId, start, end, null);
3758            }
3759    
3760            /**
3761             * Filters by the user's permissions and finds an ordered range of all the d l file entries where groupId = &#63; and userId = &#63; and folderId = &#63;.
3762             *
3763             * <p>
3764             * 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.
3765             * </p>
3766             *
3767             * @param groupId the group id to search with
3768             * @param userId the user id to search with
3769             * @param folderId the folder id to search with
3770             * @param start the lower bound of the range of d l file entries to return
3771             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3772             * @param orderByComparator the comparator to order the results by
3773             * @return the ordered range of matching d l file entries that the user has permission to view
3774             * @throws SystemException if a system exception occurred
3775             */
3776            public List<DLFileEntry> filterFindByG_U_F(long groupId, long userId,
3777                    long folderId, int start, int end, OrderByComparator orderByComparator)
3778                    throws SystemException {
3779                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3780                            return findByG_U_F(groupId, userId, folderId, start, end,
3781                                    orderByComparator);
3782                    }
3783    
3784                    Session session = null;
3785    
3786                    try {
3787                            session = openSession();
3788    
3789                            StringBundler query = null;
3790    
3791                            if (orderByComparator != null) {
3792                                    query = new StringBundler(5 +
3793                                                    (orderByComparator.getOrderByFields().length * 3));
3794                            }
3795                            else {
3796                                    query = new StringBundler(5);
3797                            }
3798    
3799                            if (getDB().isSupportsInlineDistinct()) {
3800                                    query.append(_FILTER_SQL_SELECT_DLFILEENTRY_WHERE);
3801                            }
3802                            else {
3803                                    query.append(_FILTER_SQL_SELECT_DLFILEENTRY_NO_INLINE_DISTINCT_WHERE);
3804                            }
3805    
3806                            query.append(_FINDER_COLUMN_G_U_F_GROUPID_2);
3807    
3808                            query.append(_FINDER_COLUMN_G_U_F_USERID_2);
3809    
3810                            query.append(_FINDER_COLUMN_G_U_F_FOLDERID_2);
3811    
3812                            if (orderByComparator != null) {
3813                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3814                                            orderByComparator);
3815                            }
3816    
3817                            else {
3818                                    query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
3819                            }
3820    
3821                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3822                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
3823                                            _FILTER_COLUMN_USERID, groupId);
3824    
3825                            SQLQuery q = session.createSQLQuery(sql);
3826    
3827                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFileEntryImpl.class);
3828    
3829                            QueryPos qPos = QueryPos.getInstance(q);
3830    
3831                            qPos.add(groupId);
3832    
3833                            qPos.add(userId);
3834    
3835                            qPos.add(folderId);
3836    
3837                            return (List<DLFileEntry>)QueryUtil.list(q, getDialect(), start, end);
3838                    }
3839                    catch (Exception e) {
3840                            throw processException(e);
3841                    }
3842                    finally {
3843                            closeSession(session);
3844                    }
3845            }
3846    
3847            /**
3848             * Filters by the user's permissions and finds all the d l file entries where groupId = &#63; and userId = &#63; and folderId = any &#63;.
3849             *
3850             * <p>
3851             * 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.
3852             * </p>
3853             *
3854             * @param groupId the group id to search with
3855             * @param userId the user id to search with
3856             * @param folderIds the folder ids to search with
3857             * @return the matching d l file entries that the user has permission to view
3858             * @throws SystemException if a system exception occurred
3859             */
3860            public List<DLFileEntry> filterFindByG_U_F(long groupId, long userId,
3861                    long[] folderIds) throws SystemException {
3862                    return filterFindByG_U_F(groupId, userId, folderIds, QueryUtil.ALL_POS,
3863                            QueryUtil.ALL_POS, null);
3864            }
3865    
3866            /**
3867             * Filters by the user's permissions and finds a range of all the d l file entries where groupId = &#63; and userId = &#63; and folderId = any &#63;.
3868             *
3869             * <p>
3870             * 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.
3871             * </p>
3872             *
3873             * @param groupId the group id to search with
3874             * @param userId the user id to search with
3875             * @param folderIds the folder ids to search with
3876             * @param start the lower bound of the range of d l file entries to return
3877             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3878             * @return the range of matching d l file entries that the user has permission to view
3879             * @throws SystemException if a system exception occurred
3880             */
3881            public List<DLFileEntry> filterFindByG_U_F(long groupId, long userId,
3882                    long[] folderIds, int start, int end) throws SystemException {
3883                    return filterFindByG_U_F(groupId, userId, folderIds, start, end, null);
3884            }
3885    
3886            /**
3887             * Filters by the user's permissions and finds an ordered range of all the d l file entries where groupId = &#63; and userId = &#63; and folderId = any &#63;.
3888             *
3889             * <p>
3890             * 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.
3891             * </p>
3892             *
3893             * @param groupId the group id to search with
3894             * @param userId the user id to search with
3895             * @param folderIds the folder ids to search with
3896             * @param start the lower bound of the range of d l file entries to return
3897             * @param end the upper bound of the range of d l file entries to return (not inclusive)
3898             * @param orderByComparator the comparator to order the results by
3899             * @return the ordered range of matching d l file entries that the user has permission to view
3900             * @throws SystemException if a system exception occurred
3901             */
3902            public List<DLFileEntry> filterFindByG_U_F(long groupId, long userId,
3903                    long[] folderIds, int start, int end,
3904                    OrderByComparator orderByComparator) throws SystemException {
3905                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3906                            return findByG_U_F(groupId, userId, folderIds, start, end,
3907                                    orderByComparator);
3908                    }
3909    
3910                    Session session = null;
3911    
3912                    try {
3913                            session = openSession();
3914    
3915                            StringBundler query = new StringBundler();
3916    
3917                            query.append(_FILTER_SQL_SELECT_DLFILEENTRY_WHERE);
3918    
3919                            boolean conjunctionable = false;
3920    
3921                            if (conjunctionable) {
3922                                    query.append(WHERE_AND);
3923                            }
3924    
3925                            query.append(_FINDER_COLUMN_G_U_F_GROUPID_5);
3926    
3927                            conjunctionable = true;
3928    
3929                            if (conjunctionable) {
3930                                    query.append(WHERE_AND);
3931                            }
3932    
3933                            query.append(_FINDER_COLUMN_G_U_F_USERID_5);
3934    
3935                            conjunctionable = true;
3936    
3937                            if ((folderIds == null) || (folderIds.length > 0)) {
3938                                    if (conjunctionable) {
3939                                            query.append(WHERE_AND);
3940                                    }
3941    
3942                                    query.append(StringPool.OPEN_PARENTHESIS);
3943    
3944                                    for (int i = 0; i < folderIds.length; i++) {
3945                                            query.append(_FINDER_COLUMN_G_U_F_FOLDERID_5);
3946    
3947                                            if ((i + 1) < folderIds.length) {
3948                                                    query.append(WHERE_OR);
3949                                            }
3950                                    }
3951    
3952                                    query.append(StringPool.CLOSE_PARENTHESIS);
3953    
3954                                    conjunctionable = true;
3955                            }
3956    
3957                            if (orderByComparator != null) {
3958                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3959                                            orderByComparator);
3960                            }
3961    
3962                            else {
3963                                    query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
3964                            }
3965    
3966                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3967                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
3968                                            _FILTER_COLUMN_USERID, groupId);
3969    
3970                            SQLQuery q = session.createSQLQuery(sql);
3971    
3972                            q.addEntity(_FILTER_ENTITY_ALIAS, DLFileEntryImpl.class);
3973    
3974                            QueryPos qPos = QueryPos.getInstance(q);
3975    
3976                            qPos.add(groupId);
3977    
3978                            qPos.add(userId);
3979    
3980                            if (folderIds != null) {
3981                                    qPos.add(folderIds);
3982                            }
3983    
3984                            return (List<DLFileEntry>)QueryUtil.list(q, getDialect(), start, end);
3985                    }
3986                    catch (Exception e) {
3987                            throw processException(e);
3988                    }
3989                    finally {
3990                            closeSession(session);
3991                    }
3992            }
3993    
3994            /**
3995             * Finds the d l 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.
3996             *
3997             * @param groupId the group id to search with
3998             * @param folderId the folder id to search with
3999             * @param name the name to search with
4000             * @return the matching d l file entry
4001             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
4002             * @throws SystemException if a system exception occurred
4003             */
4004            public DLFileEntry findByG_F_N(long groupId, long folderId, String name)
4005                    throws NoSuchFileEntryException, SystemException {
4006                    DLFileEntry dlFileEntry = fetchByG_F_N(groupId, folderId, name);
4007    
4008                    if (dlFileEntry == null) {
4009                            StringBundler msg = new StringBundler(8);
4010    
4011                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4012    
4013                            msg.append("groupId=");
4014                            msg.append(groupId);
4015    
4016                            msg.append(", folderId=");
4017                            msg.append(folderId);
4018    
4019                            msg.append(", name=");
4020                            msg.append(name);
4021    
4022                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4023    
4024                            if (_log.isWarnEnabled()) {
4025                                    _log.warn(msg.toString());
4026                            }
4027    
4028                            throw new NoSuchFileEntryException(msg.toString());
4029                    }
4030    
4031                    return dlFileEntry;
4032            }
4033    
4034            /**
4035             * Finds the d l 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.
4036             *
4037             * @param groupId the group id to search with
4038             * @param folderId the folder id to search with
4039             * @param name the name to search with
4040             * @return the matching d l file entry, or <code>null</code> if a matching d l file entry could not be found
4041             * @throws SystemException if a system exception occurred
4042             */
4043            public DLFileEntry fetchByG_F_N(long groupId, long folderId, String name)
4044                    throws SystemException {
4045                    return fetchByG_F_N(groupId, folderId, name, true);
4046            }
4047    
4048            /**
4049             * Finds the d l 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.
4050             *
4051             * @param groupId the group id to search with
4052             * @param folderId the folder id to search with
4053             * @param name the name to search with
4054             * @return the matching d l file entry, or <code>null</code> if a matching d l file entry could not be found
4055             * @throws SystemException if a system exception occurred
4056             */
4057            public DLFileEntry fetchByG_F_N(long groupId, long folderId, String name,
4058                    boolean retrieveFromCache) throws SystemException {
4059                    Object[] finderArgs = new Object[] { groupId, folderId, name };
4060    
4061                    Object result = null;
4062    
4063                    if (retrieveFromCache) {
4064                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_F_N,
4065                                            finderArgs, this);
4066                    }
4067    
4068                    if (result == null) {
4069                            Session session = null;
4070    
4071                            try {
4072                                    session = openSession();
4073    
4074                                    StringBundler query = new StringBundler(5);
4075    
4076                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
4077    
4078                                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
4079    
4080                                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
4081    
4082                                    if (name == null) {
4083                                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
4084                                    }
4085                                    else {
4086                                            if (name.equals(StringPool.BLANK)) {
4087                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
4088                                            }
4089                                            else {
4090                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
4091                                            }
4092                                    }
4093    
4094                                    query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
4095    
4096                                    String sql = query.toString();
4097    
4098                                    Query q = session.createQuery(sql);
4099    
4100                                    QueryPos qPos = QueryPos.getInstance(q);
4101    
4102                                    qPos.add(groupId);
4103    
4104                                    qPos.add(folderId);
4105    
4106                                    if (name != null) {
4107                                            qPos.add(name);
4108                                    }
4109    
4110                                    List<DLFileEntry> list = q.list();
4111    
4112                                    result = list;
4113    
4114                                    DLFileEntry dlFileEntry = null;
4115    
4116                                    if (list.isEmpty()) {
4117                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N,
4118                                                    finderArgs, list);
4119                                    }
4120                                    else {
4121                                            dlFileEntry = list.get(0);
4122    
4123                                            cacheResult(dlFileEntry);
4124    
4125                                            if ((dlFileEntry.getGroupId() != groupId) ||
4126                                                            (dlFileEntry.getFolderId() != folderId) ||
4127                                                            (dlFileEntry.getName() == null) ||
4128                                                            !dlFileEntry.getName().equals(name)) {
4129                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N,
4130                                                            finderArgs, dlFileEntry);
4131                                            }
4132                                    }
4133    
4134                                    return dlFileEntry;
4135                            }
4136                            catch (Exception e) {
4137                                    throw processException(e);
4138                            }
4139                            finally {
4140                                    if (result == null) {
4141                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N,
4142                                                    finderArgs, new ArrayList<DLFileEntry>());
4143                                    }
4144    
4145                                    closeSession(session);
4146                            }
4147                    }
4148                    else {
4149                            if (result instanceof List<?>) {
4150                                    return null;
4151                            }
4152                            else {
4153                                    return (DLFileEntry)result;
4154                            }
4155                    }
4156            }
4157    
4158            /**
4159             * Finds the d l 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.
4160             *
4161             * @param groupId the group id to search with
4162             * @param folderId the folder id to search with
4163             * @param title the title to search with
4164             * @return the matching d l file entry
4165             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryException if a matching d l file entry could not be found
4166             * @throws SystemException if a system exception occurred
4167             */
4168            public DLFileEntry findByG_F_T(long groupId, long folderId, String title)
4169                    throws NoSuchFileEntryException, SystemException {
4170                    DLFileEntry dlFileEntry = fetchByG_F_T(groupId, folderId, title);
4171    
4172                    if (dlFileEntry == null) {
4173                            StringBundler msg = new StringBundler(8);
4174    
4175                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4176    
4177                            msg.append("groupId=");
4178                            msg.append(groupId);
4179    
4180                            msg.append(", folderId=");
4181                            msg.append(folderId);
4182    
4183                            msg.append(", title=");
4184                            msg.append(title);
4185    
4186                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4187    
4188                            if (_log.isWarnEnabled()) {
4189                                    _log.warn(msg.toString());
4190                            }
4191    
4192                            throw new NoSuchFileEntryException(msg.toString());
4193                    }
4194    
4195                    return dlFileEntry;
4196            }
4197    
4198            /**
4199             * Finds the d l 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.
4200             *
4201             * @param groupId the group id to search with
4202             * @param folderId the folder id to search with
4203             * @param title the title to search with
4204             * @return the matching d l file entry, or <code>null</code> if a matching d l file entry could not be found
4205             * @throws SystemException if a system exception occurred
4206             */
4207            public DLFileEntry fetchByG_F_T(long groupId, long folderId, String title)
4208                    throws SystemException {
4209                    return fetchByG_F_T(groupId, folderId, title, true);
4210            }
4211    
4212            /**
4213             * Finds the d l 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.
4214             *
4215             * @param groupId the group id to search with
4216             * @param folderId the folder id to search with
4217             * @param title the title to search with
4218             * @return the matching d l file entry, or <code>null</code> if a matching d l file entry could not be found
4219             * @throws SystemException if a system exception occurred
4220             */
4221            public DLFileEntry fetchByG_F_T(long groupId, long folderId, String title,
4222                    boolean retrieveFromCache) throws SystemException {
4223                    Object[] finderArgs = new Object[] { groupId, folderId, title };
4224    
4225                    Object result = null;
4226    
4227                    if (retrieveFromCache) {
4228                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_F_T,
4229                                            finderArgs, this);
4230                    }
4231    
4232                    if (result == null) {
4233                            Session session = null;
4234    
4235                            try {
4236                                    session = openSession();
4237    
4238                                    StringBundler query = new StringBundler(5);
4239    
4240                                    query.append(_SQL_SELECT_DLFILEENTRY_WHERE);
4241    
4242                                    query.append(_FINDER_COLUMN_G_F_T_GROUPID_2);
4243    
4244                                    query.append(_FINDER_COLUMN_G_F_T_FOLDERID_2);
4245    
4246                                    if (title == null) {
4247                                            query.append(_FINDER_COLUMN_G_F_T_TITLE_1);
4248                                    }
4249                                    else {
4250                                            if (title.equals(StringPool.BLANK)) {
4251                                                    query.append(_FINDER_COLUMN_G_F_T_TITLE_3);
4252                                            }
4253                                            else {
4254                                                    query.append(_FINDER_COLUMN_G_F_T_TITLE_2);
4255                                            }
4256                                    }
4257    
4258                                    query.append(DLFileEntryModelImpl.ORDER_BY_JPQL);
4259    
4260                                    String sql = query.toString();
4261    
4262                                    Query q = session.createQuery(sql);
4263    
4264                                    QueryPos qPos = QueryPos.getInstance(q);
4265    
4266                                    qPos.add(groupId);
4267    
4268                                    qPos.add(folderId);
4269    
4270                                    if (title != null) {
4271                                            qPos.add(title);
4272                                    }
4273    
4274                                    List<DLFileEntry> list = q.list();
4275    
4276                                    result = list;
4277    
4278                                    DLFileEntry dlFileEntry = null;
4279    
4280                                    if (list.isEmpty()) {
4281                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_T,
4282                                                    finderArgs, list);
4283                                    }
4284                                    else {
4285                                            dlFileEntry = list.get(0);
4286    
4287                                            cacheResult(dlFileEntry);
4288    
4289                                            if ((dlFileEntry.getGroupId() != groupId) ||
4290                                                            (dlFileEntry.getFolderId() != folderId) ||
4291                                                            (dlFileEntry.getTitle() == null) ||
4292                                                            !dlFileEntry.getTitle().equals(title)) {
4293                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_T,
4294                                                            finderArgs, dlFileEntry);
4295                                            }
4296                                    }
4297    
4298                                    return dlFileEntry;
4299                            }
4300                            catch (Exception e) {
4301                                    throw processException(e);
4302                            }
4303                            finally {
4304                                    if (result == null) {
4305                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_T,
4306                                                    finderArgs, new ArrayList<DLFileEntry>());
4307                                    }
4308    
4309                                    closeSession(session);
4310                            }
4311                    }
4312                    else {
4313                            if (result instanceof List<?>) {
4314                                    return null;
4315                            }
4316                            else {
4317                                    return (DLFileEntry)result;
4318                            }
4319                    }
4320            }
4321    
4322            /**
4323             * Finds all the d l file entries.
4324             *
4325             * @return the d l file entries
4326             * @throws SystemException if a system exception occurred
4327             */
4328            public List<DLFileEntry> findAll() throws SystemException {
4329                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4330            }
4331    
4332            /**
4333             * Finds a range of all the d l file entries.
4334             *
4335             * <p>
4336             * 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.
4337             * </p>
4338             *
4339             * @param start the lower bound of the range of d l file entries to return
4340             * @param end the upper bound of the range of d l file entries to return (not inclusive)
4341             * @return the range of d l file entries
4342             * @throws SystemException if a system exception occurred
4343             */
4344            public List<DLFileEntry> findAll(int start, int end)
4345                    throws SystemException {
4346                    return findAll(start, end, null);
4347            }
4348    
4349            /**
4350             * Finds an ordered range of all the d l file entries.
4351             *
4352             * <p>
4353             * 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.
4354             * </p>
4355             *
4356             * @param start the lower bound of the range of d l file entries to return
4357             * @param end the upper bound of the range of d l file entries to return (not inclusive)
4358             * @param orderByComparator the comparator to order the results by
4359             * @return the ordered range of d l file entries
4360             * @throws SystemException if a system exception occurred
4361             */
4362            public List<DLFileEntry> findAll(int start, int end,
4363                    OrderByComparator orderByComparator) throws SystemException {
4364                    Object[] finderArgs = new Object[] {
4365                                    String.valueOf(start), String.valueOf(end),
4366                                    String.valueOf(orderByComparator)
4367                            };
4368    
4369                    List<DLFileEntry> list = (List<DLFileEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
4370                                    finderArgs, this);
4371    
4372                    if (list == null) {
4373                            Session session = null;
4374    
4375                            try {
4376                                    session = openSession();
4377    
4378                                    StringBundler query = null;
4379                                    String sql = null;
4380    
4381                                    if (orderByComparator != null) {
4382                                            query = new StringBundler(2 +
4383                                                            (orderByComparator.getOrderByFields().length * 3));
4384    
4385                                            query.append(_SQL_SELECT_DLFILEENTRY);
4386    
4387                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4388                                                    orderByComparator);
4389    
4390                                            sql = query.toString();
4391                                    }
4392                                    else {
4393                                            sql = _SQL_SELECT_DLFILEENTRY.concat(DLFileEntryModelImpl.ORDER_BY_JPQL);
4394                                    }
4395    
4396                                    Query q = session.createQuery(sql);
4397    
4398                                    if (orderByComparator == null) {
4399                                            list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
4400                                                            start, end, false);
4401    
4402                                            Collections.sort(list);
4403                                    }
4404                                    else {
4405                                            list = (List<DLFileEntry>)QueryUtil.list(q, getDialect(),
4406                                                            start, end);
4407                                    }
4408                            }
4409                            catch (Exception e) {
4410                                    throw processException(e);
4411                            }
4412                            finally {
4413                                    if (list == null) {
4414                                            list = new ArrayList<DLFileEntry>();
4415                                    }
4416    
4417                                    cacheResult(list);
4418    
4419                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
4420    
4421                                    closeSession(session);
4422                            }
4423                    }
4424    
4425                    return list;
4426            }
4427    
4428            /**
4429             * Removes all the d l file entries where uuid = &#63; from the database.
4430             *
4431             * @param uuid the uuid to search with
4432             * @throws SystemException if a system exception occurred
4433             */
4434            public void removeByUuid(String uuid) throws SystemException {
4435                    for (DLFileEntry dlFileEntry : findByUuid(uuid)) {
4436                            remove(dlFileEntry);
4437                    }
4438            }
4439    
4440            /**
4441             * Removes the d l file entry where uuid = &#63; and groupId = &#63; from the database.
4442             *
4443             * @param uuid the uuid to search with
4444             * @param groupId the group id to search with
4445             * @throws SystemException if a system exception occurred
4446             */
4447            public void removeByUUID_G(String uuid, long groupId)
4448                    throws NoSuchFileEntryException, SystemException {
4449                    DLFileEntry dlFileEntry = findByUUID_G(uuid, groupId);
4450    
4451                    remove(dlFileEntry);
4452            }
4453    
4454            /**
4455             * Removes all the d l file entries where groupId = &#63; from the database.
4456             *
4457             * @param groupId the group id to search with
4458             * @throws SystemException if a system exception occurred
4459             */
4460            public void removeByGroupId(long groupId) throws SystemException {
4461                    for (DLFileEntry dlFileEntry : findByGroupId(groupId)) {
4462                            remove(dlFileEntry);
4463                    }
4464            }
4465    
4466            /**
4467             * Removes all the d l file entries where companyId = &#63; from the database.
4468             *
4469             * @param companyId the company id to search with
4470             * @throws SystemException if a system exception occurred
4471             */
4472            public void removeByCompanyId(long companyId) throws SystemException {
4473                    for (DLFileEntry dlFileEntry : findByCompanyId(companyId)) {
4474                            remove(dlFileEntry);
4475                    }
4476            }
4477    
4478            /**
4479             * Removes all the d l file entries where groupId = &#63; and userId = &#63; from the database.
4480             *
4481             * @param groupId the group id to search with
4482             * @param userId the user id to search with
4483             * @throws SystemException if a system exception occurred
4484             */
4485            public void removeByG_U(long groupId, long userId)
4486                    throws SystemException {
4487                    for (DLFileEntry dlFileEntry : findByG_U(groupId, userId)) {
4488                            remove(dlFileEntry);
4489                    }
4490            }
4491    
4492            /**
4493             * Removes all the d l file entries where groupId = &#63; and folderId = &#63; from the database.
4494             *
4495             * @param groupId the group id to search with
4496             * @param folderId the folder id to search with
4497             * @throws SystemException if a system exception occurred
4498             */
4499            public void removeByG_F(long groupId, long folderId)
4500                    throws SystemException {
4501                    for (DLFileEntry dlFileEntry : findByG_F(groupId, folderId)) {
4502                            remove(dlFileEntry);
4503                    }
4504            }
4505    
4506            /**
4507             * Removes all the d l file entries where groupId = &#63; and userId = &#63; and folderId = &#63; from the database.
4508             *
4509             * @param groupId the group id to search with
4510             * @param userId the user id to search with
4511             * @param folderId the folder id to search with
4512             * @throws SystemException if a system exception occurred
4513             */
4514            public void removeByG_U_F(long groupId, long userId, long folderId)
4515                    throws SystemException {
4516                    for (DLFileEntry dlFileEntry : findByG_U_F(groupId, userId, folderId)) {
4517                            remove(dlFileEntry);
4518                    }
4519            }
4520    
4521            /**
4522             * Removes the d l file entry where groupId = &#63; and folderId = &#63; and name = &#63; from the database.
4523             *
4524             * @param groupId the group id to search with
4525             * @param folderId the folder id to search with
4526             * @param name the name to search with
4527             * @throws SystemException if a system exception occurred
4528             */
4529            public void removeByG_F_N(long groupId, long folderId, String name)
4530                    throws NoSuchFileEntryException, SystemException {
4531                    DLFileEntry dlFileEntry = findByG_F_N(groupId, folderId, name);
4532    
4533                    remove(dlFileEntry);
4534            }
4535    
4536            /**
4537             * Removes the d l file entry where groupId = &#63; and folderId = &#63; and title = &#63; from the database.
4538             *
4539             * @param groupId the group id to search with
4540             * @param folderId the folder id to search with
4541             * @param title the title to search with
4542             * @throws SystemException if a system exception occurred
4543             */
4544            public void removeByG_F_T(long groupId, long folderId, String title)
4545                    throws NoSuchFileEntryException, SystemException {
4546                    DLFileEntry dlFileEntry = findByG_F_T(groupId, folderId, title);
4547    
4548                    remove(dlFileEntry);
4549            }
4550    
4551            /**
4552             * Removes all the d l file entries from the database.
4553             *
4554             * @throws SystemException if a system exception occurred
4555             */
4556            public void removeAll() throws SystemException {
4557                    for (DLFileEntry dlFileEntry : findAll()) {
4558                            remove(dlFileEntry);
4559                    }
4560            }
4561    
4562            /**
4563             * Counts all the d l file entries where uuid = &#63;.
4564             *
4565             * @param uuid the uuid to search with
4566             * @return the number of matching d l file entries
4567             * @throws SystemException if a system exception occurred
4568             */
4569            public int countByUuid(String uuid) throws SystemException {
4570                    Object[] finderArgs = new Object[] { uuid };
4571    
4572                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4573                                    finderArgs, this);
4574    
4575                    if (count == null) {
4576                            Session session = null;
4577    
4578                            try {
4579                                    session = openSession();
4580    
4581                                    StringBundler query = new StringBundler(2);
4582    
4583                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
4584    
4585                                    if (uuid == null) {
4586                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
4587                                    }
4588                                    else {
4589                                            if (uuid.equals(StringPool.BLANK)) {
4590                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
4591                                            }
4592                                            else {
4593                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
4594                                            }
4595                                    }
4596    
4597                                    String sql = query.toString();
4598    
4599                                    Query q = session.createQuery(sql);
4600    
4601                                    QueryPos qPos = QueryPos.getInstance(q);
4602    
4603                                    if (uuid != null) {
4604                                            qPos.add(uuid);
4605                                    }
4606    
4607                                    count = (Long)q.uniqueResult();
4608                            }
4609                            catch (Exception e) {
4610                                    throw processException(e);
4611                            }
4612                            finally {
4613                                    if (count == null) {
4614                                            count = Long.valueOf(0);
4615                                    }
4616    
4617                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4618                                            finderArgs, count);
4619    
4620                                    closeSession(session);
4621                            }
4622                    }
4623    
4624                    return count.intValue();
4625            }
4626    
4627            /**
4628             * Counts all the d l file entries where uuid = &#63; and groupId = &#63;.
4629             *
4630             * @param uuid the uuid to search with
4631             * @param groupId the group id to search with
4632             * @return the number of matching d l file entries
4633             * @throws SystemException if a system exception occurred
4634             */
4635            public int countByUUID_G(String uuid, long groupId)
4636                    throws SystemException {
4637                    Object[] finderArgs = new Object[] { uuid, groupId };
4638    
4639                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
4640                                    finderArgs, this);
4641    
4642                    if (count == null) {
4643                            Session session = null;
4644    
4645                            try {
4646                                    session = openSession();
4647    
4648                                    StringBundler query = new StringBundler(3);
4649    
4650                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
4651    
4652                                    if (uuid == null) {
4653                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
4654                                    }
4655                                    else {
4656                                            if (uuid.equals(StringPool.BLANK)) {
4657                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
4658                                            }
4659                                            else {
4660                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
4661                                            }
4662                                    }
4663    
4664                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
4665    
4666                                    String sql = query.toString();
4667    
4668                                    Query q = session.createQuery(sql);
4669    
4670                                    QueryPos qPos = QueryPos.getInstance(q);
4671    
4672                                    if (uuid != null) {
4673                                            qPos.add(uuid);
4674                                    }
4675    
4676                                    qPos.add(groupId);
4677    
4678                                    count = (Long)q.uniqueResult();
4679                            }
4680                            catch (Exception e) {
4681                                    throw processException(e);
4682                            }
4683                            finally {
4684                                    if (count == null) {
4685                                            count = Long.valueOf(0);
4686                                    }
4687    
4688                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
4689                                            finderArgs, count);
4690    
4691                                    closeSession(session);
4692                            }
4693                    }
4694    
4695                    return count.intValue();
4696            }
4697    
4698            /**
4699             * Counts all the d l file entries where groupId = &#63;.
4700             *
4701             * @param groupId the group id to search with
4702             * @return the number of matching d l file entries
4703             * @throws SystemException if a system exception occurred
4704             */
4705            public int countByGroupId(long groupId) throws SystemException {
4706                    Object[] finderArgs = new Object[] { groupId };
4707    
4708                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
4709                                    finderArgs, this);
4710    
4711                    if (count == null) {
4712                            Session session = null;
4713    
4714                            try {
4715                                    session = openSession();
4716    
4717                                    StringBundler query = new StringBundler(2);
4718    
4719                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
4720    
4721                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4722    
4723                                    String sql = query.toString();
4724    
4725                                    Query q = session.createQuery(sql);
4726    
4727                                    QueryPos qPos = QueryPos.getInstance(q);
4728    
4729                                    qPos.add(groupId);
4730    
4731                                    count = (Long)q.uniqueResult();
4732                            }
4733                            catch (Exception e) {
4734                                    throw processException(e);
4735                            }
4736                            finally {
4737                                    if (count == null) {
4738                                            count = Long.valueOf(0);
4739                                    }
4740    
4741                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
4742                                            finderArgs, count);
4743    
4744                                    closeSession(session);
4745                            }
4746                    }
4747    
4748                    return count.intValue();
4749            }
4750    
4751            /**
4752             * Filters by the user's permissions and counts all the d l file entries where groupId = &#63;.
4753             *
4754             * @param groupId the group id to search with
4755             * @return the number of matching d l file entries that the user has permission to view
4756             * @throws SystemException if a system exception occurred
4757             */
4758            public int filterCountByGroupId(long groupId) throws SystemException {
4759                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4760                            return countByGroupId(groupId);
4761                    }
4762    
4763                    Session session = null;
4764    
4765                    try {
4766                            session = openSession();
4767    
4768                            StringBundler query = new StringBundler(2);
4769    
4770                            query.append(_FILTER_SQL_COUNT_DLFILEENTRY_WHERE);
4771    
4772                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4773    
4774                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4775                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
4776                                            _FILTER_COLUMN_USERID, groupId);
4777    
4778                            SQLQuery q = session.createSQLQuery(sql);
4779    
4780                            q.addScalar(COUNT_COLUMN_NAME,
4781                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4782    
4783                            QueryPos qPos = QueryPos.getInstance(q);
4784    
4785                            qPos.add(groupId);
4786    
4787                            Long count = (Long)q.uniqueResult();
4788    
4789                            return count.intValue();
4790                    }
4791                    catch (Exception e) {
4792                            throw processException(e);
4793                    }
4794                    finally {
4795                            closeSession(session);
4796                    }
4797            }
4798    
4799            /**
4800             * Counts all the d l file entries where companyId = &#63;.
4801             *
4802             * @param companyId the company id to search with
4803             * @return the number of matching d l file entries
4804             * @throws SystemException if a system exception occurred
4805             */
4806            public int countByCompanyId(long companyId) throws SystemException {
4807                    Object[] finderArgs = new Object[] { companyId };
4808    
4809                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4810                                    finderArgs, this);
4811    
4812                    if (count == null) {
4813                            Session session = null;
4814    
4815                            try {
4816                                    session = openSession();
4817    
4818                                    StringBundler query = new StringBundler(2);
4819    
4820                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
4821    
4822                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4823    
4824                                    String sql = query.toString();
4825    
4826                                    Query q = session.createQuery(sql);
4827    
4828                                    QueryPos qPos = QueryPos.getInstance(q);
4829    
4830                                    qPos.add(companyId);
4831    
4832                                    count = (Long)q.uniqueResult();
4833                            }
4834                            catch (Exception e) {
4835                                    throw processException(e);
4836                            }
4837                            finally {
4838                                    if (count == null) {
4839                                            count = Long.valueOf(0);
4840                                    }
4841    
4842                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4843                                            finderArgs, count);
4844    
4845                                    closeSession(session);
4846                            }
4847                    }
4848    
4849                    return count.intValue();
4850            }
4851    
4852            /**
4853             * Counts all the d l file entries where groupId = &#63; and userId = &#63;.
4854             *
4855             * @param groupId the group id to search with
4856             * @param userId the user id to search with
4857             * @return the number of matching d l file entries
4858             * @throws SystemException if a system exception occurred
4859             */
4860            public int countByG_U(long groupId, long userId) throws SystemException {
4861                    Object[] finderArgs = new Object[] { groupId, userId };
4862    
4863                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
4864                                    finderArgs, this);
4865    
4866                    if (count == null) {
4867                            Session session = null;
4868    
4869                            try {
4870                                    session = openSession();
4871    
4872                                    StringBundler query = new StringBundler(3);
4873    
4874                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
4875    
4876                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4877    
4878                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4879    
4880                                    String sql = query.toString();
4881    
4882                                    Query q = session.createQuery(sql);
4883    
4884                                    QueryPos qPos = QueryPos.getInstance(q);
4885    
4886                                    qPos.add(groupId);
4887    
4888                                    qPos.add(userId);
4889    
4890                                    count = (Long)q.uniqueResult();
4891                            }
4892                            catch (Exception e) {
4893                                    throw processException(e);
4894                            }
4895                            finally {
4896                                    if (count == null) {
4897                                            count = Long.valueOf(0);
4898                                    }
4899    
4900                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
4901                                            count);
4902    
4903                                    closeSession(session);
4904                            }
4905                    }
4906    
4907                    return count.intValue();
4908            }
4909    
4910            /**
4911             * Filters by the user's permissions and counts all the d l file entries where groupId = &#63; and userId = &#63;.
4912             *
4913             * @param groupId the group id to search with
4914             * @param userId the user id to search with
4915             * @return the number of matching d l file entries that the user has permission to view
4916             * @throws SystemException if a system exception occurred
4917             */
4918            public int filterCountByG_U(long groupId, long userId)
4919                    throws SystemException {
4920                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4921                            return countByG_U(groupId, userId);
4922                    }
4923    
4924                    Session session = null;
4925    
4926                    try {
4927                            session = openSession();
4928    
4929                            StringBundler query = new StringBundler(3);
4930    
4931                            query.append(_FILTER_SQL_COUNT_DLFILEENTRY_WHERE);
4932    
4933                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4934    
4935                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4936    
4937                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4938                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
4939                                            _FILTER_COLUMN_USERID, groupId);
4940    
4941                            SQLQuery q = session.createSQLQuery(sql);
4942    
4943                            q.addScalar(COUNT_COLUMN_NAME,
4944                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4945    
4946                            QueryPos qPos = QueryPos.getInstance(q);
4947    
4948                            qPos.add(groupId);
4949    
4950                            qPos.add(userId);
4951    
4952                            Long count = (Long)q.uniqueResult();
4953    
4954                            return count.intValue();
4955                    }
4956                    catch (Exception e) {
4957                            throw processException(e);
4958                    }
4959                    finally {
4960                            closeSession(session);
4961                    }
4962            }
4963    
4964            /**
4965             * Counts all the d l file entries where groupId = &#63; and folderId = &#63;.
4966             *
4967             * @param groupId the group id to search with
4968             * @param folderId the folder id to search with
4969             * @return the number of matching d l file entries
4970             * @throws SystemException if a system exception occurred
4971             */
4972            public int countByG_F(long groupId, long folderId)
4973                    throws SystemException {
4974                    Object[] finderArgs = new Object[] { groupId, folderId };
4975    
4976                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
4977                                    finderArgs, this);
4978    
4979                    if (count == null) {
4980                            Session session = null;
4981    
4982                            try {
4983                                    session = openSession();
4984    
4985                                    StringBundler query = new StringBundler(3);
4986    
4987                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
4988    
4989                                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
4990    
4991                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
4992    
4993                                    String sql = query.toString();
4994    
4995                                    Query q = session.createQuery(sql);
4996    
4997                                    QueryPos qPos = QueryPos.getInstance(q);
4998    
4999                                    qPos.add(groupId);
5000    
5001                                    qPos.add(folderId);
5002    
5003                                    count = (Long)q.uniqueResult();
5004                            }
5005                            catch (Exception e) {
5006                                    throw processException(e);
5007                            }
5008                            finally {
5009                                    if (count == null) {
5010                                            count = Long.valueOf(0);
5011                                    }
5012    
5013                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
5014                                            count);
5015    
5016                                    closeSession(session);
5017                            }
5018                    }
5019    
5020                    return count.intValue();
5021            }
5022    
5023            /**
5024             * Counts all the d l file entries where groupId = &#63; and folderId = any &#63;.
5025             *
5026             * @param groupId the group id to search with
5027             * @param folderIds the folder ids to search with
5028             * @return the number of matching d l file entries
5029             * @throws SystemException if a system exception occurred
5030             */
5031            public int countByG_F(long groupId, long[] folderIds)
5032                    throws SystemException {
5033                    Object[] finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) };
5034    
5035                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F,
5036                                    finderArgs, this);
5037    
5038                    if (count == null) {
5039                            Session session = null;
5040    
5041                            try {
5042                                    session = openSession();
5043    
5044                                    StringBundler query = new StringBundler();
5045    
5046                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
5047    
5048                                    boolean conjunctionable = false;
5049    
5050                                    if (conjunctionable) {
5051                                            query.append(WHERE_AND);
5052                                    }
5053    
5054                                    query.append(_FINDER_COLUMN_G_F_GROUPID_5);
5055    
5056                                    conjunctionable = true;
5057    
5058                                    if ((folderIds == null) || (folderIds.length > 0)) {
5059                                            if (conjunctionable) {
5060                                                    query.append(WHERE_AND);
5061                                            }
5062    
5063                                            query.append(StringPool.OPEN_PARENTHESIS);
5064    
5065                                            for (int i = 0; i < folderIds.length; i++) {
5066                                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
5067    
5068                                                    if ((i + 1) < folderIds.length) {
5069                                                            query.append(WHERE_OR);
5070                                                    }
5071                                            }
5072    
5073                                            query.append(StringPool.CLOSE_PARENTHESIS);
5074    
5075                                            conjunctionable = true;
5076                                    }
5077    
5078                                    String sql = query.toString();
5079    
5080                                    Query q = session.createQuery(sql);
5081    
5082                                    QueryPos qPos = QueryPos.getInstance(q);
5083    
5084                                    qPos.add(groupId);
5085    
5086                                    if (folderIds != null) {
5087                                            qPos.add(folderIds);
5088                                    }
5089    
5090                                    count = (Long)q.uniqueResult();
5091                            }
5092                            catch (Exception e) {
5093                                    throw processException(e);
5094                            }
5095                            finally {
5096                                    if (count == null) {
5097                                            count = Long.valueOf(0);
5098                                    }
5099    
5100                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F, finderArgs,
5101                                            count);
5102    
5103                                    closeSession(session);
5104                            }
5105                    }
5106    
5107                    return count.intValue();
5108            }
5109    
5110            /**
5111             * Filters by the user's permissions and counts all the d l file entries where groupId = &#63; and folderId = &#63;.
5112             *
5113             * @param groupId the group id to search with
5114             * @param folderId the folder id to search with
5115             * @return the number of matching d l file entries that the user has permission to view
5116             * @throws SystemException if a system exception occurred
5117             */
5118            public int filterCountByG_F(long groupId, long folderId)
5119                    throws SystemException {
5120                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5121                            return countByG_F(groupId, folderId);
5122                    }
5123    
5124                    Session session = null;
5125    
5126                    try {
5127                            session = openSession();
5128    
5129                            StringBundler query = new StringBundler(3);
5130    
5131                            query.append(_FILTER_SQL_COUNT_DLFILEENTRY_WHERE);
5132    
5133                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
5134    
5135                            query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
5136    
5137                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5138                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
5139                                            _FILTER_COLUMN_USERID, groupId);
5140    
5141                            SQLQuery q = session.createSQLQuery(sql);
5142    
5143                            q.addScalar(COUNT_COLUMN_NAME,
5144                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5145    
5146                            QueryPos qPos = QueryPos.getInstance(q);
5147    
5148                            qPos.add(groupId);
5149    
5150                            qPos.add(folderId);
5151    
5152                            Long count = (Long)q.uniqueResult();
5153    
5154                            return count.intValue();
5155                    }
5156                    catch (Exception e) {
5157                            throw processException(e);
5158                    }
5159                    finally {
5160                            closeSession(session);
5161                    }
5162            }
5163    
5164            /**
5165             * Filters by the user's permissions and counts all the d l file entries where groupId = &#63; and folderId = any &#63;.
5166             *
5167             * @param groupId the group id to search with
5168             * @param folderIds the folder ids to search with
5169             * @return the number of matching d l file entries that the user has permission to view
5170             * @throws SystemException if a system exception occurred
5171             */
5172            public int filterCountByG_F(long groupId, long[] folderIds)
5173                    throws SystemException {
5174                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5175                            return countByG_F(groupId, folderIds);
5176                    }
5177    
5178                    Session session = null;
5179    
5180                    try {
5181                            session = openSession();
5182    
5183                            StringBundler query = new StringBundler();
5184    
5185                            query.append(_FILTER_SQL_COUNT_DLFILEENTRY_WHERE);
5186    
5187                            boolean conjunctionable = false;
5188    
5189                            if (conjunctionable) {
5190                                    query.append(WHERE_AND);
5191                            }
5192    
5193                            query.append(_FINDER_COLUMN_G_F_GROUPID_5);
5194    
5195                            conjunctionable = true;
5196    
5197                            if ((folderIds == null) || (folderIds.length > 0)) {
5198                                    if (conjunctionable) {
5199                                            query.append(WHERE_AND);
5200                                    }
5201    
5202                                    query.append(StringPool.OPEN_PARENTHESIS);
5203    
5204                                    for (int i = 0; i < folderIds.length; i++) {
5205                                            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
5206    
5207                                            if ((i + 1) < folderIds.length) {
5208                                                    query.append(WHERE_OR);
5209                                            }
5210                                    }
5211    
5212                                    query.append(StringPool.CLOSE_PARENTHESIS);
5213    
5214                                    conjunctionable = true;
5215                            }
5216    
5217                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5218                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
5219                                            _FILTER_COLUMN_USERID, groupId);
5220    
5221                            SQLQuery q = session.createSQLQuery(sql);
5222    
5223                            q.addScalar(COUNT_COLUMN_NAME,
5224                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5225    
5226                            QueryPos qPos = QueryPos.getInstance(q);
5227    
5228                            qPos.add(groupId);
5229    
5230                            if (folderIds != null) {
5231                                    qPos.add(folderIds);
5232                            }
5233    
5234                            Long count = (Long)q.uniqueResult();
5235    
5236                            return count.intValue();
5237                    }
5238                    catch (Exception e) {
5239                            throw processException(e);
5240                    }
5241                    finally {
5242                            closeSession(session);
5243                    }
5244            }
5245    
5246            /**
5247             * Counts all the d l file entries where groupId = &#63; and userId = &#63; and folderId = &#63;.
5248             *
5249             * @param groupId the group id to search with
5250             * @param userId the user id to search with
5251             * @param folderId the folder id to search with
5252             * @return the number of matching d l file entries
5253             * @throws SystemException if a system exception occurred
5254             */
5255            public int countByG_U_F(long groupId, long userId, long folderId)
5256                    throws SystemException {
5257                    Object[] finderArgs = new Object[] { groupId, userId, folderId };
5258    
5259                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_F,
5260                                    finderArgs, this);
5261    
5262                    if (count == null) {
5263                            Session session = null;
5264    
5265                            try {
5266                                    session = openSession();
5267    
5268                                    StringBundler query = new StringBundler(4);
5269    
5270                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
5271    
5272                                    query.append(_FINDER_COLUMN_G_U_F_GROUPID_2);
5273    
5274                                    query.append(_FINDER_COLUMN_G_U_F_USERID_2);
5275    
5276                                    query.append(_FINDER_COLUMN_G_U_F_FOLDERID_2);
5277    
5278                                    String sql = query.toString();
5279    
5280                                    Query q = session.createQuery(sql);
5281    
5282                                    QueryPos qPos = QueryPos.getInstance(q);
5283    
5284                                    qPos.add(groupId);
5285    
5286                                    qPos.add(userId);
5287    
5288                                    qPos.add(folderId);
5289    
5290                                    count = (Long)q.uniqueResult();
5291                            }
5292                            catch (Exception e) {
5293                                    throw processException(e);
5294                            }
5295                            finally {
5296                                    if (count == null) {
5297                                            count = Long.valueOf(0);
5298                                    }
5299    
5300                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_F,
5301                                            finderArgs, count);
5302    
5303                                    closeSession(session);
5304                            }
5305                    }
5306    
5307                    return count.intValue();
5308            }
5309    
5310            /**
5311             * Counts all the d l file entries where groupId = &#63; and userId = &#63; and folderId = any &#63;.
5312             *
5313             * @param groupId the group id to search with
5314             * @param userId the user id to search with
5315             * @param folderIds the folder ids to search with
5316             * @return the number of matching d l file entries
5317             * @throws SystemException if a system exception occurred
5318             */
5319            public int countByG_U_F(long groupId, long userId, long[] folderIds)
5320                    throws SystemException {
5321                    Object[] finderArgs = new Object[] {
5322                                    groupId, userId, StringUtil.merge(folderIds)
5323                            };
5324    
5325                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U_F,
5326                                    finderArgs, this);
5327    
5328                    if (count == null) {
5329                            Session session = null;
5330    
5331                            try {
5332                                    session = openSession();
5333    
5334                                    StringBundler query = new StringBundler();
5335    
5336                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
5337    
5338                                    boolean conjunctionable = false;
5339    
5340                                    if (conjunctionable) {
5341                                            query.append(WHERE_AND);
5342                                    }
5343    
5344                                    query.append(_FINDER_COLUMN_G_U_F_GROUPID_5);
5345    
5346                                    conjunctionable = true;
5347    
5348                                    if (conjunctionable) {
5349                                            query.append(WHERE_AND);
5350                                    }
5351    
5352                                    query.append(_FINDER_COLUMN_G_U_F_USERID_5);
5353    
5354                                    conjunctionable = true;
5355    
5356                                    if ((folderIds == null) || (folderIds.length > 0)) {
5357                                            if (conjunctionable) {
5358                                                    query.append(WHERE_AND);
5359                                            }
5360    
5361                                            query.append(StringPool.OPEN_PARENTHESIS);
5362    
5363                                            for (int i = 0; i < folderIds.length; i++) {
5364                                                    query.append(_FINDER_COLUMN_G_U_F_FOLDERID_5);
5365    
5366                                                    if ((i + 1) < folderIds.length) {
5367                                                            query.append(WHERE_OR);
5368                                                    }
5369                                            }
5370    
5371                                            query.append(StringPool.CLOSE_PARENTHESIS);
5372    
5373                                            conjunctionable = true;
5374                                    }
5375    
5376                                    String sql = query.toString();
5377    
5378                                    Query q = session.createQuery(sql);
5379    
5380                                    QueryPos qPos = QueryPos.getInstance(q);
5381    
5382                                    qPos.add(groupId);
5383    
5384                                    qPos.add(userId);
5385    
5386                                    if (folderIds != null) {
5387                                            qPos.add(folderIds);
5388                                    }
5389    
5390                                    count = (Long)q.uniqueResult();
5391                            }
5392                            catch (Exception e) {
5393                                    throw processException(e);
5394                            }
5395                            finally {
5396                                    if (count == null) {
5397                                            count = Long.valueOf(0);
5398                                    }
5399    
5400                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U_F,
5401                                            finderArgs, count);
5402    
5403                                    closeSession(session);
5404                            }
5405                    }
5406    
5407                    return count.intValue();
5408            }
5409    
5410            /**
5411             * Filters by the user's permissions and counts all the d l file entries where groupId = &#63; and userId = &#63; and folderId = &#63;.
5412             *
5413             * @param groupId the group id to search with
5414             * @param userId the user id to search with
5415             * @param folderId the folder id to search with
5416             * @return the number of matching d l file entries that the user has permission to view
5417             * @throws SystemException if a system exception occurred
5418             */
5419            public int filterCountByG_U_F(long groupId, long userId, long folderId)
5420                    throws SystemException {
5421                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5422                            return countByG_U_F(groupId, userId, folderId);
5423                    }
5424    
5425                    Session session = null;
5426    
5427                    try {
5428                            session = openSession();
5429    
5430                            StringBundler query = new StringBundler(4);
5431    
5432                            query.append(_FILTER_SQL_COUNT_DLFILEENTRY_WHERE);
5433    
5434                            query.append(_FINDER_COLUMN_G_U_F_GROUPID_2);
5435    
5436                            query.append(_FINDER_COLUMN_G_U_F_USERID_2);
5437    
5438                            query.append(_FINDER_COLUMN_G_U_F_FOLDERID_2);
5439    
5440                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5441                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
5442                                            _FILTER_COLUMN_USERID, groupId);
5443    
5444                            SQLQuery q = session.createSQLQuery(sql);
5445    
5446                            q.addScalar(COUNT_COLUMN_NAME,
5447                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5448    
5449                            QueryPos qPos = QueryPos.getInstance(q);
5450    
5451                            qPos.add(groupId);
5452    
5453                            qPos.add(userId);
5454    
5455                            qPos.add(folderId);
5456    
5457                            Long count = (Long)q.uniqueResult();
5458    
5459                            return count.intValue();
5460                    }
5461                    catch (Exception e) {
5462                            throw processException(e);
5463                    }
5464                    finally {
5465                            closeSession(session);
5466                    }
5467            }
5468    
5469            /**
5470             * Filters by the user's permissions and counts all the d l file entries where groupId = &#63; and userId = &#63; and folderId = any &#63;.
5471             *
5472             * @param groupId the group id to search with
5473             * @param userId the user id to search with
5474             * @param folderIds the folder ids to search with
5475             * @return the number of matching d l file entries that the user has permission to view
5476             * @throws SystemException if a system exception occurred
5477             */
5478            public int filterCountByG_U_F(long groupId, long userId, long[] folderIds)
5479                    throws SystemException {
5480                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5481                            return countByG_U_F(groupId, userId, folderIds);
5482                    }
5483    
5484                    Session session = null;
5485    
5486                    try {
5487                            session = openSession();
5488    
5489                            StringBundler query = new StringBundler();
5490    
5491                            query.append(_FILTER_SQL_COUNT_DLFILEENTRY_WHERE);
5492    
5493                            boolean conjunctionable = false;
5494    
5495                            if (conjunctionable) {
5496                                    query.append(WHERE_AND);
5497                            }
5498    
5499                            query.append(_FINDER_COLUMN_G_U_F_GROUPID_5);
5500    
5501                            conjunctionable = true;
5502    
5503                            if (conjunctionable) {
5504                                    query.append(WHERE_AND);
5505                            }
5506    
5507                            query.append(_FINDER_COLUMN_G_U_F_USERID_5);
5508    
5509                            conjunctionable = true;
5510    
5511                            if ((folderIds == null) || (folderIds.length > 0)) {
5512                                    if (conjunctionable) {
5513                                            query.append(WHERE_AND);
5514                                    }
5515    
5516                                    query.append(StringPool.OPEN_PARENTHESIS);
5517    
5518                                    for (int i = 0; i < folderIds.length; i++) {
5519                                            query.append(_FINDER_COLUMN_G_U_F_FOLDERID_5);
5520    
5521                                            if ((i + 1) < folderIds.length) {
5522                                                    query.append(WHERE_OR);
5523                                            }
5524                                    }
5525    
5526                                    query.append(StringPool.CLOSE_PARENTHESIS);
5527    
5528                                    conjunctionable = true;
5529                            }
5530    
5531                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5532                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
5533                                            _FILTER_COLUMN_USERID, groupId);
5534    
5535                            SQLQuery q = session.createSQLQuery(sql);
5536    
5537                            q.addScalar(COUNT_COLUMN_NAME,
5538                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5539    
5540                            QueryPos qPos = QueryPos.getInstance(q);
5541    
5542                            qPos.add(groupId);
5543    
5544                            qPos.add(userId);
5545    
5546                            if (folderIds != null) {
5547                                    qPos.add(folderIds);
5548                            }
5549    
5550                            Long count = (Long)q.uniqueResult();
5551    
5552                            return count.intValue();
5553                    }
5554                    catch (Exception e) {
5555                            throw processException(e);
5556                    }
5557                    finally {
5558                            closeSession(session);
5559                    }
5560            }
5561    
5562            /**
5563             * Counts all the d l file entries where groupId = &#63; and folderId = &#63; and name = &#63;.
5564             *
5565             * @param groupId the group id to search with
5566             * @param folderId the folder id to search with
5567             * @param name the name to search with
5568             * @return the number of matching d l file entries
5569             * @throws SystemException if a system exception occurred
5570             */
5571            public int countByG_F_N(long groupId, long folderId, String name)
5572                    throws SystemException {
5573                    Object[] finderArgs = new Object[] { groupId, folderId, name };
5574    
5575                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N,
5576                                    finderArgs, this);
5577    
5578                    if (count == null) {
5579                            Session session = null;
5580    
5581                            try {
5582                                    session = openSession();
5583    
5584                                    StringBundler query = new StringBundler(4);
5585    
5586                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
5587    
5588                                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
5589    
5590                                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
5591    
5592                                    if (name == null) {
5593                                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
5594                                    }
5595                                    else {
5596                                            if (name.equals(StringPool.BLANK)) {
5597                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
5598                                            }
5599                                            else {
5600                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
5601                                            }
5602                                    }
5603    
5604                                    String sql = query.toString();
5605    
5606                                    Query q = session.createQuery(sql);
5607    
5608                                    QueryPos qPos = QueryPos.getInstance(q);
5609    
5610                                    qPos.add(groupId);
5611    
5612                                    qPos.add(folderId);
5613    
5614                                    if (name != null) {
5615                                            qPos.add(name);
5616                                    }
5617    
5618                                    count = (Long)q.uniqueResult();
5619                            }
5620                            catch (Exception e) {
5621                                    throw processException(e);
5622                            }
5623                            finally {
5624                                    if (count == null) {
5625                                            count = Long.valueOf(0);
5626                                    }
5627    
5628                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N,
5629                                            finderArgs, count);
5630    
5631                                    closeSession(session);
5632                            }
5633                    }
5634    
5635                    return count.intValue();
5636            }
5637    
5638            /**
5639             * Filters by the user's permissions and counts all the d l file entries where groupId = &#63; and folderId = &#63; and name = &#63;.
5640             *
5641             * @param groupId the group id to search with
5642             * @param folderId the folder id to search with
5643             * @param name the name to search with
5644             * @return the number of matching d l file entries that the user has permission to view
5645             * @throws SystemException if a system exception occurred
5646             */
5647            public int filterCountByG_F_N(long groupId, long folderId, String name)
5648                    throws SystemException {
5649                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5650                            return countByG_F_N(groupId, folderId, name);
5651                    }
5652    
5653                    Session session = null;
5654    
5655                    try {
5656                            session = openSession();
5657    
5658                            StringBundler query = new StringBundler(4);
5659    
5660                            query.append(_FILTER_SQL_COUNT_DLFILEENTRY_WHERE);
5661    
5662                            query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
5663    
5664                            query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
5665    
5666                            if (name == null) {
5667                                    query.append(_FINDER_COLUMN_G_F_N_NAME_1);
5668                            }
5669                            else {
5670                                    if (name.equals(StringPool.BLANK)) {
5671                                            query.append(_FINDER_COLUMN_G_F_N_NAME_3);
5672                                    }
5673                                    else {
5674                                            query.append(_FINDER_COLUMN_G_F_N_NAME_2);
5675                                    }
5676                            }
5677    
5678                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5679                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
5680                                            _FILTER_COLUMN_USERID, groupId);
5681    
5682                            SQLQuery q = session.createSQLQuery(sql);
5683    
5684                            q.addScalar(COUNT_COLUMN_NAME,
5685                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5686    
5687                            QueryPos qPos = QueryPos.getInstance(q);
5688    
5689                            qPos.add(groupId);
5690    
5691                            qPos.add(folderId);
5692    
5693                            if (name != null) {
5694                                    qPos.add(name);
5695                            }
5696    
5697                            Long count = (Long)q.uniqueResult();
5698    
5699                            return count.intValue();
5700                    }
5701                    catch (Exception e) {
5702                            throw processException(e);
5703                    }
5704                    finally {
5705                            closeSession(session);
5706                    }
5707            }
5708    
5709            /**
5710             * Counts all the d l file entries where groupId = &#63; and folderId = &#63; and title = &#63;.
5711             *
5712             * @param groupId the group id to search with
5713             * @param folderId the folder id to search with
5714             * @param title the title to search with
5715             * @return the number of matching d l file entries
5716             * @throws SystemException if a system exception occurred
5717             */
5718            public int countByG_F_T(long groupId, long folderId, String title)
5719                    throws SystemException {
5720                    Object[] finderArgs = new Object[] { groupId, folderId, title };
5721    
5722                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_T,
5723                                    finderArgs, this);
5724    
5725                    if (count == null) {
5726                            Session session = null;
5727    
5728                            try {
5729                                    session = openSession();
5730    
5731                                    StringBundler query = new StringBundler(4);
5732    
5733                                    query.append(_SQL_COUNT_DLFILEENTRY_WHERE);
5734    
5735                                    query.append(_FINDER_COLUMN_G_F_T_GROUPID_2);
5736    
5737                                    query.append(_FINDER_COLUMN_G_F_T_FOLDERID_2);
5738    
5739                                    if (title == null) {
5740                                            query.append(_FINDER_COLUMN_G_F_T_TITLE_1);
5741                                    }
5742                                    else {
5743                                            if (title.equals(StringPool.BLANK)) {
5744                                                    query.append(_FINDER_COLUMN_G_F_T_TITLE_3);
5745                                            }
5746                                            else {
5747                                                    query.append(_FINDER_COLUMN_G_F_T_TITLE_2);
5748                                            }
5749                                    }
5750    
5751                                    String sql = query.toString();
5752    
5753                                    Query q = session.createQuery(sql);
5754    
5755                                    QueryPos qPos = QueryPos.getInstance(q);
5756    
5757                                    qPos.add(groupId);
5758    
5759                                    qPos.add(folderId);
5760    
5761                                    if (title != null) {
5762                                            qPos.add(title);
5763                                    }
5764    
5765                                    count = (Long)q.uniqueResult();
5766                            }
5767                            catch (Exception e) {
5768                                    throw processException(e);
5769                            }
5770                            finally {
5771                                    if (count == null) {
5772                                            count = Long.valueOf(0);
5773                                    }
5774    
5775                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_T,
5776                                            finderArgs, count);
5777    
5778                                    closeSession(session);
5779                            }
5780                    }
5781    
5782                    return count.intValue();
5783            }
5784    
5785            /**
5786             * Filters by the user's permissions and counts all the d l file entries where groupId = &#63; and folderId = &#63; and title = &#63;.
5787             *
5788             * @param groupId the group id to search with
5789             * @param folderId the folder id to search with
5790             * @param title the title to search with
5791             * @return the number of matching d l file entries that the user has permission to view
5792             * @throws SystemException if a system exception occurred
5793             */
5794            public int filterCountByG_F_T(long groupId, long folderId, String title)
5795                    throws SystemException {
5796                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5797                            return countByG_F_T(groupId, folderId, title);
5798                    }
5799    
5800                    Session session = null;
5801    
5802                    try {
5803                            session = openSession();
5804    
5805                            StringBundler query = new StringBundler(4);
5806    
5807                            query.append(_FILTER_SQL_COUNT_DLFILEENTRY_WHERE);
5808    
5809                            query.append(_FINDER_COLUMN_G_F_T_GROUPID_2);
5810    
5811                            query.append(_FINDER_COLUMN_G_F_T_FOLDERID_2);
5812    
5813                            if (title == null) {
5814                                    query.append(_FINDER_COLUMN_G_F_T_TITLE_1);
5815                            }
5816                            else {
5817                                    if (title.equals(StringPool.BLANK)) {
5818                                            query.append(_FINDER_COLUMN_G_F_T_TITLE_3);
5819                                    }
5820                                    else {
5821                                            query.append(_FINDER_COLUMN_G_F_T_TITLE_2);
5822                                    }
5823                            }
5824    
5825                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5826                                            DLFileEntry.class.getName(), _FILTER_COLUMN_PK,
5827                                            _FILTER_COLUMN_USERID, groupId);
5828    
5829                            SQLQuery q = session.createSQLQuery(sql);
5830    
5831                            q.addScalar(COUNT_COLUMN_NAME,
5832                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5833    
5834                            QueryPos qPos = QueryPos.getInstance(q);
5835    
5836                            qPos.add(groupId);
5837    
5838                            qPos.add(folderId);
5839    
5840                            if (title != null) {
5841                                    qPos.add(title);
5842                            }
5843    
5844                            Long count = (Long)q.uniqueResult();
5845    
5846                            return count.intValue();
5847                    }
5848                    catch (Exception e) {
5849                            throw processException(e);
5850                    }
5851                    finally {
5852                            closeSession(session);
5853                    }
5854            }
5855    
5856            /**
5857             * Counts all the d l file entries.
5858             *
5859             * @return the number of d l file entries
5860             * @throws SystemException if a system exception occurred
5861             */
5862            public int countAll() throws SystemException {
5863                    Object[] finderArgs = new Object[0];
5864    
5865                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5866                                    finderArgs, this);
5867    
5868                    if (count == null) {
5869                            Session session = null;
5870    
5871                            try {
5872                                    session = openSession();
5873    
5874                                    Query q = session.createQuery(_SQL_COUNT_DLFILEENTRY);
5875    
5876                                    count = (Long)q.uniqueResult();
5877                            }
5878                            catch (Exception e) {
5879                                    throw processException(e);
5880                            }
5881                            finally {
5882                                    if (count == null) {
5883                                            count = Long.valueOf(0);
5884                                    }
5885    
5886                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
5887                                            count);
5888    
5889                                    closeSession(session);
5890                            }
5891                    }
5892    
5893                    return count.intValue();
5894            }
5895    
5896            /**
5897             * Initializes the d l file entry persistence.
5898             */
5899            public void afterPropertiesSet() {
5900                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5901                                            com.liferay.portal.util.PropsUtil.get(
5902                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileEntry")));
5903    
5904                    if (listenerClassNames.length > 0) {
5905                            try {
5906                                    List<ModelListener<DLFileEntry>> listenersList = new ArrayList<ModelListener<DLFileEntry>>();
5907    
5908                                    for (String listenerClassName : listenerClassNames) {
5909                                            listenersList.add((ModelListener<DLFileEntry>)InstanceFactory.newInstance(
5910                                                            listenerClassName));
5911                                    }
5912    
5913                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5914                            }
5915                            catch (Exception e) {
5916                                    _log.error(e);
5917                            }
5918                    }
5919            }
5920    
5921            public void destroy() {
5922                    EntityCacheUtil.removeCache(DLFileEntryImpl.class.getName());
5923                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5924                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
5925            }
5926    
5927            @BeanReference(type = DLFileEntryPersistence.class)
5928            protected DLFileEntryPersistence dlFileEntryPersistence;
5929            @BeanReference(type = DLFileRankPersistence.class)
5930            protected DLFileRankPersistence dlFileRankPersistence;
5931            @BeanReference(type = DLFileShortcutPersistence.class)
5932            protected DLFileShortcutPersistence dlFileShortcutPersistence;
5933            @BeanReference(type = DLFileVersionPersistence.class)
5934            protected DLFileVersionPersistence dlFileVersionPersistence;
5935            @BeanReference(type = DLFolderPersistence.class)
5936            protected DLFolderPersistence dlFolderPersistence;
5937            @BeanReference(type = LockPersistence.class)
5938            protected LockPersistence lockPersistence;
5939            @BeanReference(type = ResourcePersistence.class)
5940            protected ResourcePersistence resourcePersistence;
5941            @BeanReference(type = UserPersistence.class)
5942            protected UserPersistence userPersistence;
5943            @BeanReference(type = WebDAVPropsPersistence.class)
5944            protected WebDAVPropsPersistence webDAVPropsPersistence;
5945            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
5946            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
5947            @BeanReference(type = AssetCategoryPersistence.class)
5948            protected AssetCategoryPersistence assetCategoryPersistence;
5949            @BeanReference(type = AssetEntryPersistence.class)
5950            protected AssetEntryPersistence assetEntryPersistence;
5951            @BeanReference(type = AssetTagPersistence.class)
5952            protected AssetTagPersistence assetTagPersistence;
5953            @BeanReference(type = ExpandoValuePersistence.class)
5954            protected ExpandoValuePersistence expandoValuePersistence;
5955            @BeanReference(type = MBDiscussionPersistence.class)
5956            protected MBDiscussionPersistence mbDiscussionPersistence;
5957            @BeanReference(type = MBMessagePersistence.class)
5958            protected MBMessagePersistence mbMessagePersistence;
5959            @BeanReference(type = RatingsEntryPersistence.class)
5960            protected RatingsEntryPersistence ratingsEntryPersistence;
5961            @BeanReference(type = RatingsStatsPersistence.class)
5962            protected RatingsStatsPersistence ratingsStatsPersistence;
5963            @BeanReference(type = SocialActivityPersistence.class)
5964            protected SocialActivityPersistence socialActivityPersistence;
5965            private static final String _SQL_SELECT_DLFILEENTRY = "SELECT dlFileEntry FROM DLFileEntry dlFileEntry";
5966            private static final String _SQL_SELECT_DLFILEENTRY_WHERE = "SELECT dlFileEntry FROM DLFileEntry dlFileEntry WHERE ";
5967            private static final String _SQL_COUNT_DLFILEENTRY = "SELECT COUNT(dlFileEntry) FROM DLFileEntry dlFileEntry";
5968            private static final String _SQL_COUNT_DLFILEENTRY_WHERE = "SELECT COUNT(dlFileEntry) FROM DLFileEntry dlFileEntry WHERE ";
5969            private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFileEntry.uuid IS NULL";
5970            private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFileEntry.uuid = ?";
5971            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFileEntry.uuid IS NULL OR dlFileEntry.uuid = ?)";
5972            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "dlFileEntry.uuid IS NULL AND ";
5973            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "dlFileEntry.uuid = ? AND ";
5974            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(dlFileEntry.uuid IS NULL OR dlFileEntry.uuid = ?) AND ";
5975            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "dlFileEntry.groupId = ?";
5976            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "dlFileEntry.groupId = ?";
5977            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "dlFileEntry.companyId = ?";
5978            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "dlFileEntry.groupId = ? AND ";
5979            private static final String _FINDER_COLUMN_G_U_USERID_2 = "dlFileEntry.userId = ?";
5980            private static final String _FINDER_COLUMN_G_F_GROUPID_2 = "dlFileEntry.groupId = ? AND ";
5981            private static final String _FINDER_COLUMN_G_F_GROUPID_5 = "(" +
5982                    _removeConjunction(_FINDER_COLUMN_G_F_GROUPID_2) + ")";
5983            private static final String _FINDER_COLUMN_G_F_FOLDERID_2 = "dlFileEntry.folderId = ?";
5984            private static final String _FINDER_COLUMN_G_F_FOLDERID_5 = "(" +
5985                    _removeConjunction(_FINDER_COLUMN_G_F_FOLDERID_2) + ")";
5986            private static final String _FINDER_COLUMN_G_U_F_GROUPID_2 = "dlFileEntry.groupId = ? AND ";
5987            private static final String _FINDER_COLUMN_G_U_F_GROUPID_5 = "(" +
5988                    _removeConjunction(_FINDER_COLUMN_G_U_F_GROUPID_2) + ")";
5989            private static final String _FINDER_COLUMN_G_U_F_USERID_2 = "dlFileEntry.userId = ? AND ";
5990            private static final String _FINDER_COLUMN_G_U_F_USERID_5 = "(" +
5991                    _removeConjunction(_FINDER_COLUMN_G_U_F_USERID_2) + ")";
5992            private static final String _FINDER_COLUMN_G_U_F_FOLDERID_2 = "dlFileEntry.folderId = ?";
5993            private static final String _FINDER_COLUMN_G_U_F_FOLDERID_5 = "(" +
5994                    _removeConjunction(_FINDER_COLUMN_G_U_F_FOLDERID_2) + ")";
5995            private static final String _FINDER_COLUMN_G_F_N_GROUPID_2 = "dlFileEntry.groupId = ? AND ";
5996            private static final String _FINDER_COLUMN_G_F_N_FOLDERID_2 = "dlFileEntry.folderId = ? AND ";
5997            private static final String _FINDER_COLUMN_G_F_N_NAME_1 = "dlFileEntry.name IS NULL";
5998            private static final String _FINDER_COLUMN_G_F_N_NAME_2 = "dlFileEntry.name = ?";
5999            private static final String _FINDER_COLUMN_G_F_N_NAME_3 = "(dlFileEntry.name IS NULL OR dlFileEntry.name = ?)";
6000            private static final String _FINDER_COLUMN_G_F_T_GROUPID_2 = "dlFileEntry.groupId = ? AND ";
6001            private static final String _FINDER_COLUMN_G_F_T_FOLDERID_2 = "dlFileEntry.folderId = ? AND ";
6002            private static final String _FINDER_COLUMN_G_F_T_TITLE_1 = "dlFileEntry.title IS NULL";
6003            private static final String _FINDER_COLUMN_G_F_T_TITLE_2 = "dlFileEntry.title = ?";
6004            private static final String _FINDER_COLUMN_G_F_T_TITLE_3 = "(dlFileEntry.title IS NULL OR dlFileEntry.title = ?)";
6005    
6006            private static String _removeConjunction(String sql) {
6007                    int pos = sql.indexOf(" AND ");
6008    
6009                    if (pos != -1) {
6010                            sql = sql.substring(0, pos);
6011                    }
6012    
6013                    return sql;
6014            }
6015    
6016            private static final String _FILTER_SQL_SELECT_DLFILEENTRY_WHERE = "SELECT DISTINCT {dlFileEntry.*} FROM DLFileEntry dlFileEntry WHERE ";
6017            private static final String _FILTER_SQL_SELECT_DLFILEENTRY_NO_INLINE_DISTINCT_WHERE =
6018                    "SELECT {dlFileEntry.*} FROM (SELECT DISTINCT fileEntryId FROM DLFileEntry) dlFileEntry2 INNER JOIN DLFileEntry dlFileEntry ON (dlFileEntry2.fileEntryId = dlFileEntry.fileEntryId) WHERE ";
6019            private static final String _FILTER_SQL_COUNT_DLFILEENTRY_WHERE = "SELECT COUNT(DISTINCT dlFileEntry.fileEntryId) AS COUNT_VALUE FROM DLFileEntry dlFileEntry WHERE ";
6020            private static final String _FILTER_COLUMN_PK = "dlFileEntry.fileEntryId";
6021            private static final String _FILTER_COLUMN_USERID = "dlFileEntry.userId";
6022            private static final String _FILTER_ENTITY_ALIAS = "dlFileEntry";
6023            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileEntry.";
6024            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileEntry exists with the primary key ";
6025            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileEntry exists with the key {";
6026            private static Log _log = LogFactoryUtil.getLog(DLFileEntryPersistenceImpl.class);
6027    }