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