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.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
039    import com.liferay.portal.service.persistence.LayoutPersistence;
040    import com.liferay.portal.service.persistence.ResourcePersistence;
041    import com.liferay.portal.service.persistence.UserPersistence;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.documentlibrary.NoSuchFileRankException;
045    import com.liferay.portlet.documentlibrary.model.DLFileRank;
046    import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
047    import com.liferay.portlet.documentlibrary.model.impl.DLFileRankModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the d l file rank service.
057     *
058     * <p>
059     * Never modify or reference this class directly. Always use {@link DLFileRankUtil} to access the d l file rank persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
060     * </p>
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see DLFileRankPersistence
068     * @see DLFileRankUtil
069     * @generated
070     */
071    public class DLFileRankPersistenceImpl extends BasePersistenceImpl<DLFileRank>
072            implements DLFileRankPersistence {
073            public static final String FINDER_CLASS_NAME_ENTITY = DLFileRankImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075                    ".List";
076            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
077                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
078                            "findByUserId",
079                            new String[] {
080                                    Long.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
086                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
087                            "countByUserId", new String[] { Long.class.getName() });
088            public static final FinderPath FINDER_PATH_FIND_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
089                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090                            "findByG_U",
091                            new String[] {
092                                    Long.class.getName(), Long.class.getName(),
093                                    
094                            "java.lang.Integer", "java.lang.Integer",
095                                    "com.liferay.portal.kernel.util.OrderByComparator"
096                            });
097            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
098                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099                            "countByG_U",
100                            new String[] { Long.class.getName(), Long.class.getName() });
101            public static final FinderPath FINDER_PATH_FIND_BY_F_N = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
102                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103                            "findByF_N",
104                            new String[] {
105                                    Long.class.getName(), String.class.getName(),
106                                    
107                            "java.lang.Integer", "java.lang.Integer",
108                                    "com.liferay.portal.kernel.util.OrderByComparator"
109                            });
110            public static final FinderPath FINDER_PATH_COUNT_BY_F_N = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
111                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
112                            "countByF_N",
113                            new String[] { Long.class.getName(), String.class.getName() });
114            public static final FinderPath FINDER_PATH_FETCH_BY_C_U_F_N = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
115                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
116                            "fetchByC_U_F_N",
117                            new String[] {
118                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
119                                    String.class.getName()
120                            });
121            public static final FinderPath FINDER_PATH_COUNT_BY_C_U_F_N = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
122                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
123                            "countByC_U_F_N",
124                            new String[] {
125                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
126                                    String.class.getName()
127                            });
128            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
129                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130                            "findAll", new String[0]);
131            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
132                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133                            "countAll", new String[0]);
134    
135            /**
136             * Caches the d l file rank in the entity cache if it is enabled.
137             *
138             * @param dlFileRank the d l file rank to cache
139             */
140            public void cacheResult(DLFileRank dlFileRank) {
141                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
142                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
143    
144                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
145                            new Object[] {
146                                    new Long(dlFileRank.getCompanyId()),
147                                    new Long(dlFileRank.getUserId()),
148                                    new Long(dlFileRank.getFolderId()),
149                                    
150                            dlFileRank.getName()
151                            }, dlFileRank);
152            }
153    
154            /**
155             * Caches the d l file ranks in the entity cache if it is enabled.
156             *
157             * @param dlFileRanks the d l file ranks to cache
158             */
159            public void cacheResult(List<DLFileRank> dlFileRanks) {
160                    for (DLFileRank dlFileRank : dlFileRanks) {
161                            if (EntityCacheUtil.getResult(
162                                                    DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
163                                                    DLFileRankImpl.class, dlFileRank.getPrimaryKey(), this) == null) {
164                                    cacheResult(dlFileRank);
165                            }
166                    }
167            }
168    
169            /**
170             * Clears the cache for all d l file ranks.
171             *
172             * <p>
173             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
174             * </p>
175             */
176            public void clearCache() {
177                    CacheRegistryUtil.clear(DLFileRankImpl.class.getName());
178                    EntityCacheUtil.clearCache(DLFileRankImpl.class.getName());
179                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
180                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
181            }
182    
183            /**
184             * Clears the cache for the d l file rank.
185             *
186             * <p>
187             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
188             * </p>
189             */
190            public void clearCache(DLFileRank dlFileRank) {
191                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
192                            DLFileRankImpl.class, dlFileRank.getPrimaryKey());
193    
194                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F_N,
195                            new Object[] {
196                                    new Long(dlFileRank.getCompanyId()),
197                                    new Long(dlFileRank.getUserId()),
198                                    new Long(dlFileRank.getFolderId()),
199                                    
200                            dlFileRank.getName()
201                            });
202            }
203    
204            /**
205             * Creates a new d l file rank with the primary key. Does not add the d l file rank to the database.
206             *
207             * @param fileRankId the primary key for the new d l file rank
208             * @return the new d l file rank
209             */
210            public DLFileRank create(long fileRankId) {
211                    DLFileRank dlFileRank = new DLFileRankImpl();
212    
213                    dlFileRank.setNew(true);
214                    dlFileRank.setPrimaryKey(fileRankId);
215    
216                    return dlFileRank;
217            }
218    
219            /**
220             * Removes the d l file rank with the primary key from the database. Also notifies the appropriate model listeners.
221             *
222             * @param primaryKey the primary key of the d l file rank to remove
223             * @return the d l file rank that was removed
224             * @throws com.liferay.portal.NoSuchModelException if a d l file rank with the primary key could not be found
225             * @throws SystemException if a system exception occurred
226             */
227            public DLFileRank remove(Serializable primaryKey)
228                    throws NoSuchModelException, SystemException {
229                    return remove(((Long)primaryKey).longValue());
230            }
231    
232            /**
233             * Removes the d l file rank with the primary key from the database. Also notifies the appropriate model listeners.
234             *
235             * @param fileRankId the primary key of the d l file rank to remove
236             * @return the d l file rank that was removed
237             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a d l file rank with the primary key could not be found
238             * @throws SystemException if a system exception occurred
239             */
240            public DLFileRank remove(long fileRankId)
241                    throws NoSuchFileRankException, SystemException {
242                    Session session = null;
243    
244                    try {
245                            session = openSession();
246    
247                            DLFileRank dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
248                                            new Long(fileRankId));
249    
250                            if (dlFileRank == null) {
251                                    if (_log.isWarnEnabled()) {
252                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileRankId);
253                                    }
254    
255                                    throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
256                                            fileRankId);
257                            }
258    
259                            return remove(dlFileRank);
260                    }
261                    catch (NoSuchFileRankException nsee) {
262                            throw nsee;
263                    }
264                    catch (Exception e) {
265                            throw processException(e);
266                    }
267                    finally {
268                            closeSession(session);
269                    }
270            }
271    
272            protected DLFileRank removeImpl(DLFileRank dlFileRank)
273                    throws SystemException {
274                    dlFileRank = toUnwrappedModel(dlFileRank);
275    
276                    Session session = null;
277    
278                    try {
279                            session = openSession();
280    
281                            BatchSessionUtil.delete(session, dlFileRank);
282                    }
283                    catch (Exception e) {
284                            throw processException(e);
285                    }
286                    finally {
287                            closeSession(session);
288                    }
289    
290                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
291    
292                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
293    
294                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F_N,
295                            new Object[] {
296                                    new Long(dlFileRankModelImpl.getCompanyId()),
297                                    new Long(dlFileRankModelImpl.getUserId()),
298                                    new Long(dlFileRankModelImpl.getFolderId()),
299                                    
300                            dlFileRankModelImpl.getName()
301                            });
302    
303                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
304                            DLFileRankImpl.class, dlFileRank.getPrimaryKey());
305    
306                    return dlFileRank;
307            }
308    
309            public DLFileRank updateImpl(
310                    com.liferay.portlet.documentlibrary.model.DLFileRank dlFileRank,
311                    boolean merge) throws SystemException {
312                    dlFileRank = toUnwrappedModel(dlFileRank);
313    
314                    boolean isNew = dlFileRank.isNew();
315    
316                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
317    
318                    Session session = null;
319    
320                    try {
321                            session = openSession();
322    
323                            BatchSessionUtil.update(session, dlFileRank, merge);
324    
325                            dlFileRank.setNew(false);
326                    }
327                    catch (Exception e) {
328                            throw processException(e);
329                    }
330                    finally {
331                            closeSession(session);
332                    }
333    
334                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
335    
336                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
337                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
338    
339                    if (!isNew &&
340                                    ((dlFileRank.getCompanyId() != dlFileRankModelImpl.getOriginalCompanyId()) ||
341                                    (dlFileRank.getUserId() != dlFileRankModelImpl.getOriginalUserId()) ||
342                                    (dlFileRank.getFolderId() != dlFileRankModelImpl.getOriginalFolderId()) ||
343                                    !Validator.equals(dlFileRank.getName(),
344                                            dlFileRankModelImpl.getOriginalName()))) {
345                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F_N,
346                                    new Object[] {
347                                            new Long(dlFileRankModelImpl.getOriginalCompanyId()),
348                                            new Long(dlFileRankModelImpl.getOriginalUserId()),
349                                            new Long(dlFileRankModelImpl.getOriginalFolderId()),
350                                            
351                                    dlFileRankModelImpl.getOriginalName()
352                                    });
353                    }
354    
355                    if (isNew ||
356                                    ((dlFileRank.getCompanyId() != dlFileRankModelImpl.getOriginalCompanyId()) ||
357                                    (dlFileRank.getUserId() != dlFileRankModelImpl.getOriginalUserId()) ||
358                                    (dlFileRank.getFolderId() != dlFileRankModelImpl.getOriginalFolderId()) ||
359                                    !Validator.equals(dlFileRank.getName(),
360                                            dlFileRankModelImpl.getOriginalName()))) {
361                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
362                                    new Object[] {
363                                            new Long(dlFileRank.getCompanyId()),
364                                            new Long(dlFileRank.getUserId()),
365                                            new Long(dlFileRank.getFolderId()),
366                                            
367                                    dlFileRank.getName()
368                                    }, dlFileRank);
369                    }
370    
371                    return dlFileRank;
372            }
373    
374            protected DLFileRank toUnwrappedModel(DLFileRank dlFileRank) {
375                    if (dlFileRank instanceof DLFileRankImpl) {
376                            return dlFileRank;
377                    }
378    
379                    DLFileRankImpl dlFileRankImpl = new DLFileRankImpl();
380    
381                    dlFileRankImpl.setNew(dlFileRank.isNew());
382                    dlFileRankImpl.setPrimaryKey(dlFileRank.getPrimaryKey());
383    
384                    dlFileRankImpl.setFileRankId(dlFileRank.getFileRankId());
385                    dlFileRankImpl.setGroupId(dlFileRank.getGroupId());
386                    dlFileRankImpl.setCompanyId(dlFileRank.getCompanyId());
387                    dlFileRankImpl.setUserId(dlFileRank.getUserId());
388                    dlFileRankImpl.setCreateDate(dlFileRank.getCreateDate());
389                    dlFileRankImpl.setFolderId(dlFileRank.getFolderId());
390                    dlFileRankImpl.setName(dlFileRank.getName());
391    
392                    return dlFileRankImpl;
393            }
394    
395            /**
396             * Finds the d l file rank with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
397             *
398             * @param primaryKey the primary key of the d l file rank to find
399             * @return the d l file rank
400             * @throws com.liferay.portal.NoSuchModelException if a d l file rank with the primary key could not be found
401             * @throws SystemException if a system exception occurred
402             */
403            public DLFileRank findByPrimaryKey(Serializable primaryKey)
404                    throws NoSuchModelException, SystemException {
405                    return findByPrimaryKey(((Long)primaryKey).longValue());
406            }
407    
408            /**
409             * Finds the d l file rank with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFileRankException} if it could not be found.
410             *
411             * @param fileRankId the primary key of the d l file rank to find
412             * @return the d l file rank
413             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a d l file rank with the primary key could not be found
414             * @throws SystemException if a system exception occurred
415             */
416            public DLFileRank findByPrimaryKey(long fileRankId)
417                    throws NoSuchFileRankException, SystemException {
418                    DLFileRank dlFileRank = fetchByPrimaryKey(fileRankId);
419    
420                    if (dlFileRank == null) {
421                            if (_log.isWarnEnabled()) {
422                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileRankId);
423                            }
424    
425                            throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
426                                    fileRankId);
427                    }
428    
429                    return dlFileRank;
430            }
431    
432            /**
433             * Finds the d l file rank with the primary key or returns <code>null</code> if it could not be found.
434             *
435             * @param primaryKey the primary key of the d l file rank to find
436             * @return the d l file rank, or <code>null</code> if a d l file rank with the primary key could not be found
437             * @throws SystemException if a system exception occurred
438             */
439            public DLFileRank fetchByPrimaryKey(Serializable primaryKey)
440                    throws SystemException {
441                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
442            }
443    
444            /**
445             * Finds the d l file rank with the primary key or returns <code>null</code> if it could not be found.
446             *
447             * @param fileRankId the primary key of the d l file rank to find
448             * @return the d l file rank, or <code>null</code> if a d l file rank with the primary key could not be found
449             * @throws SystemException if a system exception occurred
450             */
451            public DLFileRank fetchByPrimaryKey(long fileRankId)
452                    throws SystemException {
453                    DLFileRank dlFileRank = (DLFileRank)EntityCacheUtil.getResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
454                                    DLFileRankImpl.class, fileRankId, this);
455    
456                    if (dlFileRank == null) {
457                            Session session = null;
458    
459                            try {
460                                    session = openSession();
461    
462                                    dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
463                                                    new Long(fileRankId));
464                            }
465                            catch (Exception e) {
466                                    throw processException(e);
467                            }
468                            finally {
469                                    if (dlFileRank != null) {
470                                            cacheResult(dlFileRank);
471                                    }
472    
473                                    closeSession(session);
474                            }
475                    }
476    
477                    return dlFileRank;
478            }
479    
480            /**
481             * Finds all the d l file ranks where userId = &#63;.
482             *
483             * @param userId the user id to search with
484             * @return the matching d l file ranks
485             * @throws SystemException if a system exception occurred
486             */
487            public List<DLFileRank> findByUserId(long userId) throws SystemException {
488                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
489            }
490    
491            /**
492             * Finds a range of all the d l file ranks where userId = &#63;.
493             *
494             * <p>
495             * 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.
496             * </p>
497             *
498             * @param userId the user id to search with
499             * @param start the lower bound of the range of d l file ranks to return
500             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
501             * @return the range of matching d l file ranks
502             * @throws SystemException if a system exception occurred
503             */
504            public List<DLFileRank> findByUserId(long userId, int start, int end)
505                    throws SystemException {
506                    return findByUserId(userId, start, end, null);
507            }
508    
509            /**
510             * Finds an ordered range of all the d l file ranks where userId = &#63;.
511             *
512             * <p>
513             * 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.
514             * </p>
515             *
516             * @param userId the user id to search with
517             * @param start the lower bound of the range of d l file ranks to return
518             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
519             * @param orderByComparator the comparator to order the results by
520             * @return the ordered range of matching d l file ranks
521             * @throws SystemException if a system exception occurred
522             */
523            public List<DLFileRank> findByUserId(long userId, int start, int end,
524                    OrderByComparator orderByComparator) throws SystemException {
525                    Object[] finderArgs = new Object[] {
526                                    userId,
527                                    
528                                    String.valueOf(start), String.valueOf(end),
529                                    String.valueOf(orderByComparator)
530                            };
531    
532                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
533                                    finderArgs, this);
534    
535                    if (list == null) {
536                            StringBundler query = null;
537    
538                            if (orderByComparator != null) {
539                                    query = new StringBundler(3 +
540                                                    (orderByComparator.getOrderByFields().length * 3));
541                            }
542                            else {
543                                    query = new StringBundler(3);
544                            }
545    
546                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
547    
548                            query.append(_FINDER_COLUMN_USERID_USERID_2);
549    
550                            if (orderByComparator != null) {
551                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
552                                            orderByComparator);
553                            }
554    
555                            else {
556                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
557                            }
558    
559                            String sql = query.toString();
560    
561                            Session session = null;
562    
563                            try {
564                                    session = openSession();
565    
566                                    Query q = session.createQuery(sql);
567    
568                                    QueryPos qPos = QueryPos.getInstance(q);
569    
570                                    qPos.add(userId);
571    
572                                    list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
573                                                    end);
574                            }
575                            catch (Exception e) {
576                                    throw processException(e);
577                            }
578                            finally {
579                                    if (list == null) {
580                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
581                                                    finderArgs);
582                                    }
583                                    else {
584                                            cacheResult(list);
585    
586                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
587                                                    finderArgs, list);
588                                    }
589    
590                                    closeSession(session);
591                            }
592                    }
593    
594                    return list;
595            }
596    
597            /**
598             * Finds the first d l file rank in the ordered set where userId = &#63;.
599             *
600             * <p>
601             * 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.
602             * </p>
603             *
604             * @param userId the user id to search with
605             * @param orderByComparator the comparator to order the set by
606             * @return the first matching d l file rank
607             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
608             * @throws SystemException if a system exception occurred
609             */
610            public DLFileRank findByUserId_First(long userId,
611                    OrderByComparator orderByComparator)
612                    throws NoSuchFileRankException, SystemException {
613                    List<DLFileRank> list = findByUserId(userId, 0, 1, orderByComparator);
614    
615                    if (list.isEmpty()) {
616                            StringBundler msg = new StringBundler(4);
617    
618                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
619    
620                            msg.append("userId=");
621                            msg.append(userId);
622    
623                            msg.append(StringPool.CLOSE_CURLY_BRACE);
624    
625                            throw new NoSuchFileRankException(msg.toString());
626                    }
627                    else {
628                            return list.get(0);
629                    }
630            }
631    
632            /**
633             * Finds the last d l file rank in the ordered set where userId = &#63;.
634             *
635             * <p>
636             * 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.
637             * </p>
638             *
639             * @param userId the user id to search with
640             * @param orderByComparator the comparator to order the set by
641             * @return the last matching d l file rank
642             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
643             * @throws SystemException if a system exception occurred
644             */
645            public DLFileRank findByUserId_Last(long userId,
646                    OrderByComparator orderByComparator)
647                    throws NoSuchFileRankException, SystemException {
648                    int count = countByUserId(userId);
649    
650                    List<DLFileRank> list = findByUserId(userId, count - 1, count,
651                                    orderByComparator);
652    
653                    if (list.isEmpty()) {
654                            StringBundler msg = new StringBundler(4);
655    
656                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
657    
658                            msg.append("userId=");
659                            msg.append(userId);
660    
661                            msg.append(StringPool.CLOSE_CURLY_BRACE);
662    
663                            throw new NoSuchFileRankException(msg.toString());
664                    }
665                    else {
666                            return list.get(0);
667                    }
668            }
669    
670            /**
671             * Finds the d l file ranks before and after the current d l file rank in the ordered set where userId = &#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 fileRankId the primary key of the current d l file rank
678             * @param userId the user id to search with
679             * @param orderByComparator the comparator to order the set by
680             * @return the previous, current, and next d l file rank
681             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a d l file rank with the primary key could not be found
682             * @throws SystemException if a system exception occurred
683             */
684            public DLFileRank[] findByUserId_PrevAndNext(long fileRankId, long userId,
685                    OrderByComparator orderByComparator)
686                    throws NoSuchFileRankException, SystemException {
687                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
688    
689                    Session session = null;
690    
691                    try {
692                            session = openSession();
693    
694                            DLFileRank[] array = new DLFileRankImpl[3];
695    
696                            array[0] = getByUserId_PrevAndNext(session, dlFileRank, userId,
697                                            orderByComparator, true);
698    
699                            array[1] = dlFileRank;
700    
701                            array[2] = getByUserId_PrevAndNext(session, dlFileRank, userId,
702                                            orderByComparator, false);
703    
704                            return array;
705                    }
706                    catch (Exception e) {
707                            throw processException(e);
708                    }
709                    finally {
710                            closeSession(session);
711                    }
712            }
713    
714            protected DLFileRank getByUserId_PrevAndNext(Session session,
715                    DLFileRank dlFileRank, long userId,
716                    OrderByComparator orderByComparator, boolean previous) {
717                    StringBundler query = null;
718    
719                    if (orderByComparator != null) {
720                            query = new StringBundler(6 +
721                                            (orderByComparator.getOrderByFields().length * 6));
722                    }
723                    else {
724                            query = new StringBundler(3);
725                    }
726    
727                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
728    
729                    query.append(_FINDER_COLUMN_USERID_USERID_2);
730    
731                    if (orderByComparator != null) {
732                            String[] orderByFields = orderByComparator.getOrderByFields();
733    
734                            if (orderByFields.length > 0) {
735                                    query.append(WHERE_AND);
736                            }
737    
738                            for (int i = 0; i < orderByFields.length; i++) {
739                                    query.append(_ORDER_BY_ENTITY_ALIAS);
740                                    query.append(orderByFields[i]);
741    
742                                    if ((i + 1) < orderByFields.length) {
743                                            if (orderByComparator.isAscending() ^ previous) {
744                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
745                                            }
746                                            else {
747                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
748                                            }
749                                    }
750                                    else {
751                                            if (orderByComparator.isAscending() ^ previous) {
752                                                    query.append(WHERE_GREATER_THAN);
753                                            }
754                                            else {
755                                                    query.append(WHERE_LESSER_THAN);
756                                            }
757                                    }
758                            }
759    
760                            query.append(ORDER_BY_CLAUSE);
761    
762                            for (int i = 0; i < orderByFields.length; i++) {
763                                    query.append(_ORDER_BY_ENTITY_ALIAS);
764                                    query.append(orderByFields[i]);
765    
766                                    if ((i + 1) < orderByFields.length) {
767                                            if (orderByComparator.isAscending() ^ previous) {
768                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
769                                            }
770                                            else {
771                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
772                                            }
773                                    }
774                                    else {
775                                            if (orderByComparator.isAscending() ^ previous) {
776                                                    query.append(ORDER_BY_ASC);
777                                            }
778                                            else {
779                                                    query.append(ORDER_BY_DESC);
780                                            }
781                                    }
782                            }
783                    }
784    
785                    else {
786                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
787                    }
788    
789                    String sql = query.toString();
790    
791                    Query q = session.createQuery(sql);
792    
793                    q.setFirstResult(0);
794                    q.setMaxResults(2);
795    
796                    QueryPos qPos = QueryPos.getInstance(q);
797    
798                    qPos.add(userId);
799    
800                    if (orderByComparator != null) {
801                            Object[] values = orderByComparator.getOrderByValues(dlFileRank);
802    
803                            for (Object value : values) {
804                                    qPos.add(value);
805                            }
806                    }
807    
808                    List<DLFileRank> list = q.list();
809    
810                    if (list.size() == 2) {
811                            return list.get(1);
812                    }
813                    else {
814                            return null;
815                    }
816            }
817    
818            /**
819             * Finds all the d l file ranks where groupId = &#63; and userId = &#63;.
820             *
821             * @param groupId the group id to search with
822             * @param userId the user id to search with
823             * @return the matching d l file ranks
824             * @throws SystemException if a system exception occurred
825             */
826            public List<DLFileRank> findByG_U(long groupId, long userId)
827                    throws SystemException {
828                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
829                            null);
830            }
831    
832            /**
833             * Finds a range of all the d l file ranks where groupId = &#63; and userId = &#63;.
834             *
835             * <p>
836             * 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.
837             * </p>
838             *
839             * @param groupId the group id to search with
840             * @param userId the user id to search with
841             * @param start the lower bound of the range of d l file ranks to return
842             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
843             * @return the range of matching d l file ranks
844             * @throws SystemException if a system exception occurred
845             */
846            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
847                    int end) throws SystemException {
848                    return findByG_U(groupId, userId, start, end, null);
849            }
850    
851            /**
852             * Finds an ordered range of all the d l file ranks where groupId = &#63; and userId = &#63;.
853             *
854             * <p>
855             * 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.
856             * </p>
857             *
858             * @param groupId the group id to search with
859             * @param userId the user id to search with
860             * @param start the lower bound of the range of d l file ranks to return
861             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
862             * @param orderByComparator the comparator to order the results by
863             * @return the ordered range of matching d l file ranks
864             * @throws SystemException if a system exception occurred
865             */
866            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
867                    int end, OrderByComparator orderByComparator) throws SystemException {
868                    Object[] finderArgs = new Object[] {
869                                    groupId, userId,
870                                    
871                                    String.valueOf(start), String.valueOf(end),
872                                    String.valueOf(orderByComparator)
873                            };
874    
875                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
876                                    finderArgs, this);
877    
878                    if (list == null) {
879                            StringBundler query = null;
880    
881                            if (orderByComparator != null) {
882                                    query = new StringBundler(4 +
883                                                    (orderByComparator.getOrderByFields().length * 3));
884                            }
885                            else {
886                                    query = new StringBundler(4);
887                            }
888    
889                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
890    
891                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
892    
893                            query.append(_FINDER_COLUMN_G_U_USERID_2);
894    
895                            if (orderByComparator != null) {
896                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
897                                            orderByComparator);
898                            }
899    
900                            else {
901                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
902                            }
903    
904                            String sql = query.toString();
905    
906                            Session session = null;
907    
908                            try {
909                                    session = openSession();
910    
911                                    Query q = session.createQuery(sql);
912    
913                                    QueryPos qPos = QueryPos.getInstance(q);
914    
915                                    qPos.add(groupId);
916    
917                                    qPos.add(userId);
918    
919                                    list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
920                                                    end);
921                            }
922                            catch (Exception e) {
923                                    throw processException(e);
924                            }
925                            finally {
926                                    if (list == null) {
927                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_U,
928                                                    finderArgs);
929                                    }
930                                    else {
931                                            cacheResult(list);
932    
933                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U,
934                                                    finderArgs, list);
935                                    }
936    
937                                    closeSession(session);
938                            }
939                    }
940    
941                    return list;
942            }
943    
944            /**
945             * Finds the first d l file rank in the ordered set where groupId = &#63; and userId = &#63;.
946             *
947             * <p>
948             * 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.
949             * </p>
950             *
951             * @param groupId the group id to search with
952             * @param userId the user id to search with
953             * @param orderByComparator the comparator to order the set by
954             * @return the first matching d l file rank
955             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
956             * @throws SystemException if a system exception occurred
957             */
958            public DLFileRank findByG_U_First(long groupId, long userId,
959                    OrderByComparator orderByComparator)
960                    throws NoSuchFileRankException, SystemException {
961                    List<DLFileRank> list = findByG_U(groupId, userId, 0, 1,
962                                    orderByComparator);
963    
964                    if (list.isEmpty()) {
965                            StringBundler msg = new StringBundler(6);
966    
967                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
968    
969                            msg.append("groupId=");
970                            msg.append(groupId);
971    
972                            msg.append(", userId=");
973                            msg.append(userId);
974    
975                            msg.append(StringPool.CLOSE_CURLY_BRACE);
976    
977                            throw new NoSuchFileRankException(msg.toString());
978                    }
979                    else {
980                            return list.get(0);
981                    }
982            }
983    
984            /**
985             * Finds the last d l file rank in the ordered set where groupId = &#63; and userId = &#63;.
986             *
987             * <p>
988             * 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.
989             * </p>
990             *
991             * @param groupId the group id to search with
992             * @param userId the user id to search with
993             * @param orderByComparator the comparator to order the set by
994             * @return the last matching d l file rank
995             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
996             * @throws SystemException if a system exception occurred
997             */
998            public DLFileRank findByG_U_Last(long groupId, long userId,
999                    OrderByComparator orderByComparator)
1000                    throws NoSuchFileRankException, SystemException {
1001                    int count = countByG_U(groupId, userId);
1002    
1003                    List<DLFileRank> list = findByG_U(groupId, userId, count - 1, count,
1004                                    orderByComparator);
1005    
1006                    if (list.isEmpty()) {
1007                            StringBundler msg = new StringBundler(6);
1008    
1009                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1010    
1011                            msg.append("groupId=");
1012                            msg.append(groupId);
1013    
1014                            msg.append(", userId=");
1015                            msg.append(userId);
1016    
1017                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1018    
1019                            throw new NoSuchFileRankException(msg.toString());
1020                    }
1021                    else {
1022                            return list.get(0);
1023                    }
1024            }
1025    
1026            /**
1027             * Finds the d l file ranks before and after the current d l file rank in the ordered set where groupId = &#63; and userId = &#63;.
1028             *
1029             * <p>
1030             * 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.
1031             * </p>
1032             *
1033             * @param fileRankId the primary key of the current d l file rank
1034             * @param groupId the group id to search with
1035             * @param userId the user id to search with
1036             * @param orderByComparator the comparator to order the set by
1037             * @return the previous, current, and next d l file rank
1038             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a d l file rank with the primary key could not be found
1039             * @throws SystemException if a system exception occurred
1040             */
1041            public DLFileRank[] findByG_U_PrevAndNext(long fileRankId, long groupId,
1042                    long userId, OrderByComparator orderByComparator)
1043                    throws NoSuchFileRankException, SystemException {
1044                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1045    
1046                    Session session = null;
1047    
1048                    try {
1049                            session = openSession();
1050    
1051                            DLFileRank[] array = new DLFileRankImpl[3];
1052    
1053                            array[0] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1054                                            userId, orderByComparator, true);
1055    
1056                            array[1] = dlFileRank;
1057    
1058                            array[2] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1059                                            userId, orderByComparator, false);
1060    
1061                            return array;
1062                    }
1063                    catch (Exception e) {
1064                            throw processException(e);
1065                    }
1066                    finally {
1067                            closeSession(session);
1068                    }
1069            }
1070    
1071            protected DLFileRank getByG_U_PrevAndNext(Session session,
1072                    DLFileRank dlFileRank, long groupId, long userId,
1073                    OrderByComparator orderByComparator, boolean previous) {
1074                    StringBundler query = null;
1075    
1076                    if (orderByComparator != null) {
1077                            query = new StringBundler(6 +
1078                                            (orderByComparator.getOrderByFields().length * 6));
1079                    }
1080                    else {
1081                            query = new StringBundler(3);
1082                    }
1083    
1084                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1085    
1086                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1087    
1088                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1089    
1090                    if (orderByComparator != null) {
1091                            String[] orderByFields = orderByComparator.getOrderByFields();
1092    
1093                            if (orderByFields.length > 0) {
1094                                    query.append(WHERE_AND);
1095                            }
1096    
1097                            for (int i = 0; i < orderByFields.length; i++) {
1098                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1099                                    query.append(orderByFields[i]);
1100    
1101                                    if ((i + 1) < orderByFields.length) {
1102                                            if (orderByComparator.isAscending() ^ previous) {
1103                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1104                                            }
1105                                            else {
1106                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1107                                            }
1108                                    }
1109                                    else {
1110                                            if (orderByComparator.isAscending() ^ previous) {
1111                                                    query.append(WHERE_GREATER_THAN);
1112                                            }
1113                                            else {
1114                                                    query.append(WHERE_LESSER_THAN);
1115                                            }
1116                                    }
1117                            }
1118    
1119                            query.append(ORDER_BY_CLAUSE);
1120    
1121                            for (int i = 0; i < orderByFields.length; i++) {
1122                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1123                                    query.append(orderByFields[i]);
1124    
1125                                    if ((i + 1) < orderByFields.length) {
1126                                            if (orderByComparator.isAscending() ^ previous) {
1127                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1128                                            }
1129                                            else {
1130                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1131                                            }
1132                                    }
1133                                    else {
1134                                            if (orderByComparator.isAscending() ^ previous) {
1135                                                    query.append(ORDER_BY_ASC);
1136                                            }
1137                                            else {
1138                                                    query.append(ORDER_BY_DESC);
1139                                            }
1140                                    }
1141                            }
1142                    }
1143    
1144                    else {
1145                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1146                    }
1147    
1148                    String sql = query.toString();
1149    
1150                    Query q = session.createQuery(sql);
1151    
1152                    q.setFirstResult(0);
1153                    q.setMaxResults(2);
1154    
1155                    QueryPos qPos = QueryPos.getInstance(q);
1156    
1157                    qPos.add(groupId);
1158    
1159                    qPos.add(userId);
1160    
1161                    if (orderByComparator != null) {
1162                            Object[] values = orderByComparator.getOrderByValues(dlFileRank);
1163    
1164                            for (Object value : values) {
1165                                    qPos.add(value);
1166                            }
1167                    }
1168    
1169                    List<DLFileRank> list = q.list();
1170    
1171                    if (list.size() == 2) {
1172                            return list.get(1);
1173                    }
1174                    else {
1175                            return null;
1176                    }
1177            }
1178    
1179            /**
1180             * Finds all the d l file ranks where folderId = &#63; and name = &#63;.
1181             *
1182             * @param folderId the folder id to search with
1183             * @param name the name to search with
1184             * @return the matching d l file ranks
1185             * @throws SystemException if a system exception occurred
1186             */
1187            public List<DLFileRank> findByF_N(long folderId, String name)
1188                    throws SystemException {
1189                    return findByF_N(folderId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1190                            null);
1191            }
1192    
1193            /**
1194             * Finds a range of all the d l file ranks where folderId = &#63; and name = &#63;.
1195             *
1196             * <p>
1197             * 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.
1198             * </p>
1199             *
1200             * @param folderId the folder id to search with
1201             * @param name the name to search with
1202             * @param start the lower bound of the range of d l file ranks to return
1203             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
1204             * @return the range of matching d l file ranks
1205             * @throws SystemException if a system exception occurred
1206             */
1207            public List<DLFileRank> findByF_N(long folderId, String name, int start,
1208                    int end) throws SystemException {
1209                    return findByF_N(folderId, name, start, end, null);
1210            }
1211    
1212            /**
1213             * Finds an ordered range of all the d l file ranks where folderId = &#63; and name = &#63;.
1214             *
1215             * <p>
1216             * 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.
1217             * </p>
1218             *
1219             * @param folderId the folder id to search with
1220             * @param name the name to search with
1221             * @param start the lower bound of the range of d l file ranks to return
1222             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
1223             * @param orderByComparator the comparator to order the results by
1224             * @return the ordered range of matching d l file ranks
1225             * @throws SystemException if a system exception occurred
1226             */
1227            public List<DLFileRank> findByF_N(long folderId, String name, int start,
1228                    int end, OrderByComparator orderByComparator) throws SystemException {
1229                    Object[] finderArgs = new Object[] {
1230                                    folderId, name,
1231                                    
1232                                    String.valueOf(start), String.valueOf(end),
1233                                    String.valueOf(orderByComparator)
1234                            };
1235    
1236                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_F_N,
1237                                    finderArgs, this);
1238    
1239                    if (list == null) {
1240                            StringBundler query = null;
1241    
1242                            if (orderByComparator != null) {
1243                                    query = new StringBundler(4 +
1244                                                    (orderByComparator.getOrderByFields().length * 3));
1245                            }
1246                            else {
1247                                    query = new StringBundler(4);
1248                            }
1249    
1250                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
1251    
1252                            query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
1253    
1254                            if (name == null) {
1255                                    query.append(_FINDER_COLUMN_F_N_NAME_1);
1256                            }
1257                            else {
1258                                    if (name.equals(StringPool.BLANK)) {
1259                                            query.append(_FINDER_COLUMN_F_N_NAME_3);
1260                                    }
1261                                    else {
1262                                            query.append(_FINDER_COLUMN_F_N_NAME_2);
1263                                    }
1264                            }
1265    
1266                            if (orderByComparator != null) {
1267                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1268                                            orderByComparator);
1269                            }
1270    
1271                            else {
1272                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1273                            }
1274    
1275                            String sql = query.toString();
1276    
1277                            Session session = null;
1278    
1279                            try {
1280                                    session = openSession();
1281    
1282                                    Query q = session.createQuery(sql);
1283    
1284                                    QueryPos qPos = QueryPos.getInstance(q);
1285    
1286                                    qPos.add(folderId);
1287    
1288                                    if (name != null) {
1289                                            qPos.add(name);
1290                                    }
1291    
1292                                    list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
1293                                                    end);
1294                            }
1295                            catch (Exception e) {
1296                                    throw processException(e);
1297                            }
1298                            finally {
1299                                    if (list == null) {
1300                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_F_N,
1301                                                    finderArgs);
1302                                    }
1303                                    else {
1304                                            cacheResult(list);
1305    
1306                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_F_N,
1307                                                    finderArgs, list);
1308                                    }
1309    
1310                                    closeSession(session);
1311                            }
1312                    }
1313    
1314                    return list;
1315            }
1316    
1317            /**
1318             * Finds the first d l file rank in the ordered set where folderId = &#63; and name = &#63;.
1319             *
1320             * <p>
1321             * 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.
1322             * </p>
1323             *
1324             * @param folderId the folder id to search with
1325             * @param name the name to search with
1326             * @param orderByComparator the comparator to order the set by
1327             * @return the first matching d l file rank
1328             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
1329             * @throws SystemException if a system exception occurred
1330             */
1331            public DLFileRank findByF_N_First(long folderId, String name,
1332                    OrderByComparator orderByComparator)
1333                    throws NoSuchFileRankException, SystemException {
1334                    List<DLFileRank> list = findByF_N(folderId, name, 0, 1,
1335                                    orderByComparator);
1336    
1337                    if (list.isEmpty()) {
1338                            StringBundler msg = new StringBundler(6);
1339    
1340                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1341    
1342                            msg.append("folderId=");
1343                            msg.append(folderId);
1344    
1345                            msg.append(", name=");
1346                            msg.append(name);
1347    
1348                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1349    
1350                            throw new NoSuchFileRankException(msg.toString());
1351                    }
1352                    else {
1353                            return list.get(0);
1354                    }
1355            }
1356    
1357            /**
1358             * Finds the last d l file rank in the ordered set where folderId = &#63; and name = &#63;.
1359             *
1360             * <p>
1361             * 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.
1362             * </p>
1363             *
1364             * @param folderId the folder id to search with
1365             * @param name the name to search with
1366             * @param orderByComparator the comparator to order the set by
1367             * @return the last matching d l file rank
1368             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
1369             * @throws SystemException if a system exception occurred
1370             */
1371            public DLFileRank findByF_N_Last(long folderId, String name,
1372                    OrderByComparator orderByComparator)
1373                    throws NoSuchFileRankException, SystemException {
1374                    int count = countByF_N(folderId, name);
1375    
1376                    List<DLFileRank> list = findByF_N(folderId, name, count - 1, count,
1377                                    orderByComparator);
1378    
1379                    if (list.isEmpty()) {
1380                            StringBundler msg = new StringBundler(6);
1381    
1382                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1383    
1384                            msg.append("folderId=");
1385                            msg.append(folderId);
1386    
1387                            msg.append(", name=");
1388                            msg.append(name);
1389    
1390                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1391    
1392                            throw new NoSuchFileRankException(msg.toString());
1393                    }
1394                    else {
1395                            return list.get(0);
1396                    }
1397            }
1398    
1399            /**
1400             * Finds the d l file ranks before and after the current d l file rank in the ordered set where folderId = &#63; and name = &#63;.
1401             *
1402             * <p>
1403             * 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.
1404             * </p>
1405             *
1406             * @param fileRankId the primary key of the current d l file rank
1407             * @param folderId the folder id to search with
1408             * @param name the name to search with
1409             * @param orderByComparator the comparator to order the set by
1410             * @return the previous, current, and next d l file rank
1411             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a d l file rank with the primary key could not be found
1412             * @throws SystemException if a system exception occurred
1413             */
1414            public DLFileRank[] findByF_N_PrevAndNext(long fileRankId, long folderId,
1415                    String name, OrderByComparator orderByComparator)
1416                    throws NoSuchFileRankException, SystemException {
1417                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1418    
1419                    Session session = null;
1420    
1421                    try {
1422                            session = openSession();
1423    
1424                            DLFileRank[] array = new DLFileRankImpl[3];
1425    
1426                            array[0] = getByF_N_PrevAndNext(session, dlFileRank, folderId,
1427                                            name, orderByComparator, true);
1428    
1429                            array[1] = dlFileRank;
1430    
1431                            array[2] = getByF_N_PrevAndNext(session, dlFileRank, folderId,
1432                                            name, orderByComparator, false);
1433    
1434                            return array;
1435                    }
1436                    catch (Exception e) {
1437                            throw processException(e);
1438                    }
1439                    finally {
1440                            closeSession(session);
1441                    }
1442            }
1443    
1444            protected DLFileRank getByF_N_PrevAndNext(Session session,
1445                    DLFileRank dlFileRank, long folderId, String name,
1446                    OrderByComparator orderByComparator, boolean previous) {
1447                    StringBundler query = null;
1448    
1449                    if (orderByComparator != null) {
1450                            query = new StringBundler(6 +
1451                                            (orderByComparator.getOrderByFields().length * 6));
1452                    }
1453                    else {
1454                            query = new StringBundler(3);
1455                    }
1456    
1457                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1458    
1459                    query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
1460    
1461                    if (name == null) {
1462                            query.append(_FINDER_COLUMN_F_N_NAME_1);
1463                    }
1464                    else {
1465                            if (name.equals(StringPool.BLANK)) {
1466                                    query.append(_FINDER_COLUMN_F_N_NAME_3);
1467                            }
1468                            else {
1469                                    query.append(_FINDER_COLUMN_F_N_NAME_2);
1470                            }
1471                    }
1472    
1473                    if (orderByComparator != null) {
1474                            String[] orderByFields = orderByComparator.getOrderByFields();
1475    
1476                            if (orderByFields.length > 0) {
1477                                    query.append(WHERE_AND);
1478                            }
1479    
1480                            for (int i = 0; i < orderByFields.length; i++) {
1481                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1482                                    query.append(orderByFields[i]);
1483    
1484                                    if ((i + 1) < orderByFields.length) {
1485                                            if (orderByComparator.isAscending() ^ previous) {
1486                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1487                                            }
1488                                            else {
1489                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1490                                            }
1491                                    }
1492                                    else {
1493                                            if (orderByComparator.isAscending() ^ previous) {
1494                                                    query.append(WHERE_GREATER_THAN);
1495                                            }
1496                                            else {
1497                                                    query.append(WHERE_LESSER_THAN);
1498                                            }
1499                                    }
1500                            }
1501    
1502                            query.append(ORDER_BY_CLAUSE);
1503    
1504                            for (int i = 0; i < orderByFields.length; i++) {
1505                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1506                                    query.append(orderByFields[i]);
1507    
1508                                    if ((i + 1) < orderByFields.length) {
1509                                            if (orderByComparator.isAscending() ^ previous) {
1510                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1511                                            }
1512                                            else {
1513                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1514                                            }
1515                                    }
1516                                    else {
1517                                            if (orderByComparator.isAscending() ^ previous) {
1518                                                    query.append(ORDER_BY_ASC);
1519                                            }
1520                                            else {
1521                                                    query.append(ORDER_BY_DESC);
1522                                            }
1523                                    }
1524                            }
1525                    }
1526    
1527                    else {
1528                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1529                    }
1530    
1531                    String sql = query.toString();
1532    
1533                    Query q = session.createQuery(sql);
1534    
1535                    q.setFirstResult(0);
1536                    q.setMaxResults(2);
1537    
1538                    QueryPos qPos = QueryPos.getInstance(q);
1539    
1540                    qPos.add(folderId);
1541    
1542                    if (name != null) {
1543                            qPos.add(name);
1544                    }
1545    
1546                    if (orderByComparator != null) {
1547                            Object[] values = orderByComparator.getOrderByValues(dlFileRank);
1548    
1549                            for (Object value : values) {
1550                                    qPos.add(value);
1551                            }
1552                    }
1553    
1554                    List<DLFileRank> list = q.list();
1555    
1556                    if (list.size() == 2) {
1557                            return list.get(1);
1558                    }
1559                    else {
1560                            return null;
1561                    }
1562            }
1563    
1564            /**
1565             * Finds the d l file rank where companyId = &#63; and userId = &#63; and folderId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFileRankException} if it could not be found.
1566             *
1567             * @param companyId the company id to search with
1568             * @param userId the user id to search with
1569             * @param folderId the folder id to search with
1570             * @param name the name to search with
1571             * @return the matching d l file rank
1572             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
1573             * @throws SystemException if a system exception occurred
1574             */
1575            public DLFileRank findByC_U_F_N(long companyId, long userId, long folderId,
1576                    String name) throws NoSuchFileRankException, SystemException {
1577                    DLFileRank dlFileRank = fetchByC_U_F_N(companyId, userId, folderId, name);
1578    
1579                    if (dlFileRank == null) {
1580                            StringBundler msg = new StringBundler(10);
1581    
1582                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1583    
1584                            msg.append("companyId=");
1585                            msg.append(companyId);
1586    
1587                            msg.append(", userId=");
1588                            msg.append(userId);
1589    
1590                            msg.append(", folderId=");
1591                            msg.append(folderId);
1592    
1593                            msg.append(", name=");
1594                            msg.append(name);
1595    
1596                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1597    
1598                            if (_log.isWarnEnabled()) {
1599                                    _log.warn(msg.toString());
1600                            }
1601    
1602                            throw new NoSuchFileRankException(msg.toString());
1603                    }
1604    
1605                    return dlFileRank;
1606            }
1607    
1608            /**
1609             * Finds the d l file rank where companyId = &#63; and userId = &#63; and folderId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1610             *
1611             * @param companyId the company id to search with
1612             * @param userId the user id to search with
1613             * @param folderId the folder id to search with
1614             * @param name the name to search with
1615             * @return the matching d l file rank, or <code>null</code> if a matching d l file rank could not be found
1616             * @throws SystemException if a system exception occurred
1617             */
1618            public DLFileRank fetchByC_U_F_N(long companyId, long userId,
1619                    long folderId, String name) throws SystemException {
1620                    return fetchByC_U_F_N(companyId, userId, folderId, name, true);
1621            }
1622    
1623            /**
1624             * Finds the d l file rank where companyId = &#63; and userId = &#63; and folderId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1625             *
1626             * @param companyId the company id to search with
1627             * @param userId the user id to search with
1628             * @param folderId the folder id to search with
1629             * @param name the name to search with
1630             * @return the matching d l file rank, or <code>null</code> if a matching d l file rank could not be found
1631             * @throws SystemException if a system exception occurred
1632             */
1633            public DLFileRank fetchByC_U_F_N(long companyId, long userId,
1634                    long folderId, String name, boolean retrieveFromCache)
1635                    throws SystemException {
1636                    Object[] finderArgs = new Object[] { companyId, userId, folderId, name };
1637    
1638                    Object result = null;
1639    
1640                    if (retrieveFromCache) {
1641                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1642                                            finderArgs, this);
1643                    }
1644    
1645                    if (result == null) {
1646                            StringBundler query = new StringBundler(6);
1647    
1648                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
1649    
1650                            query.append(_FINDER_COLUMN_C_U_F_N_COMPANYID_2);
1651    
1652                            query.append(_FINDER_COLUMN_C_U_F_N_USERID_2);
1653    
1654                            query.append(_FINDER_COLUMN_C_U_F_N_FOLDERID_2);
1655    
1656                            if (name == null) {
1657                                    query.append(_FINDER_COLUMN_C_U_F_N_NAME_1);
1658                            }
1659                            else {
1660                                    if (name.equals(StringPool.BLANK)) {
1661                                            query.append(_FINDER_COLUMN_C_U_F_N_NAME_3);
1662                                    }
1663                                    else {
1664                                            query.append(_FINDER_COLUMN_C_U_F_N_NAME_2);
1665                                    }
1666                            }
1667    
1668                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1669    
1670                            String sql = query.toString();
1671    
1672                            Session session = null;
1673    
1674                            try {
1675                                    session = openSession();
1676    
1677                                    Query q = session.createQuery(sql);
1678    
1679                                    QueryPos qPos = QueryPos.getInstance(q);
1680    
1681                                    qPos.add(companyId);
1682    
1683                                    qPos.add(userId);
1684    
1685                                    qPos.add(folderId);
1686    
1687                                    if (name != null) {
1688                                            qPos.add(name);
1689                                    }
1690    
1691                                    List<DLFileRank> list = q.list();
1692    
1693                                    result = list;
1694    
1695                                    DLFileRank dlFileRank = null;
1696    
1697                                    if (list.isEmpty()) {
1698                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1699                                                    finderArgs, list);
1700                                    }
1701                                    else {
1702                                            dlFileRank = list.get(0);
1703    
1704                                            cacheResult(dlFileRank);
1705    
1706                                            if ((dlFileRank.getCompanyId() != companyId) ||
1707                                                            (dlFileRank.getUserId() != userId) ||
1708                                                            (dlFileRank.getFolderId() != folderId) ||
1709                                                            (dlFileRank.getName() == null) ||
1710                                                            !dlFileRank.getName().equals(name)) {
1711                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1712                                                            finderArgs, dlFileRank);
1713                                            }
1714                                    }
1715    
1716                                    return dlFileRank;
1717                            }
1718                            catch (Exception e) {
1719                                    throw processException(e);
1720                            }
1721                            finally {
1722                                    if (result == null) {
1723                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1724                                                    finderArgs);
1725                                    }
1726    
1727                                    closeSession(session);
1728                            }
1729                    }
1730                    else {
1731                            if (result instanceof List<?>) {
1732                                    return null;
1733                            }
1734                            else {
1735                                    return (DLFileRank)result;
1736                            }
1737                    }
1738            }
1739    
1740            /**
1741             * Finds all the d l file ranks.
1742             *
1743             * @return the d l file ranks
1744             * @throws SystemException if a system exception occurred
1745             */
1746            public List<DLFileRank> findAll() throws SystemException {
1747                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1748            }
1749    
1750            /**
1751             * Finds a range of all the d l file ranks.
1752             *
1753             * <p>
1754             * 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.
1755             * </p>
1756             *
1757             * @param start the lower bound of the range of d l file ranks to return
1758             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
1759             * @return the range of d l file ranks
1760             * @throws SystemException if a system exception occurred
1761             */
1762            public List<DLFileRank> findAll(int start, int end)
1763                    throws SystemException {
1764                    return findAll(start, end, null);
1765            }
1766    
1767            /**
1768             * Finds an ordered range of all the d l file ranks.
1769             *
1770             * <p>
1771             * 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.
1772             * </p>
1773             *
1774             * @param start the lower bound of the range of d l file ranks to return
1775             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
1776             * @param orderByComparator the comparator to order the results by
1777             * @return the ordered range of d l file ranks
1778             * @throws SystemException if a system exception occurred
1779             */
1780            public List<DLFileRank> findAll(int start, int end,
1781                    OrderByComparator orderByComparator) throws SystemException {
1782                    Object[] finderArgs = new Object[] {
1783                                    String.valueOf(start), String.valueOf(end),
1784                                    String.valueOf(orderByComparator)
1785                            };
1786    
1787                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1788                                    finderArgs, this);
1789    
1790                    if (list == null) {
1791                            StringBundler query = null;
1792                            String sql = null;
1793    
1794                            if (orderByComparator != null) {
1795                                    query = new StringBundler(2 +
1796                                                    (orderByComparator.getOrderByFields().length * 3));
1797    
1798                                    query.append(_SQL_SELECT_DLFILERANK);
1799    
1800                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1801                                            orderByComparator);
1802    
1803                                    sql = query.toString();
1804                            }
1805                            else {
1806                                    sql = _SQL_SELECT_DLFILERANK.concat(DLFileRankModelImpl.ORDER_BY_JPQL);
1807                            }
1808    
1809                            Session session = null;
1810    
1811                            try {
1812                                    session = openSession();
1813    
1814                                    Query q = session.createQuery(sql);
1815    
1816                                    if (orderByComparator == null) {
1817                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1818                                                            start, end, false);
1819    
1820                                            Collections.sort(list);
1821                                    }
1822                                    else {
1823                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1824                                                            start, end);
1825                                    }
1826                            }
1827                            catch (Exception e) {
1828                                    throw processException(e);
1829                            }
1830                            finally {
1831                                    if (list == null) {
1832                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1833                                                    finderArgs);
1834                                    }
1835                                    else {
1836                                            cacheResult(list);
1837    
1838                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1839                                                    list);
1840                                    }
1841    
1842                                    closeSession(session);
1843                            }
1844                    }
1845    
1846                    return list;
1847            }
1848    
1849            /**
1850             * Removes all the d l file ranks where userId = &#63; from the database.
1851             *
1852             * @param userId the user id to search with
1853             * @throws SystemException if a system exception occurred
1854             */
1855            public void removeByUserId(long userId) throws SystemException {
1856                    for (DLFileRank dlFileRank : findByUserId(userId)) {
1857                            remove(dlFileRank);
1858                    }
1859            }
1860    
1861            /**
1862             * Removes all the d l file ranks where groupId = &#63; and userId = &#63; from the database.
1863             *
1864             * @param groupId the group id to search with
1865             * @param userId the user id to search with
1866             * @throws SystemException if a system exception occurred
1867             */
1868            public void removeByG_U(long groupId, long userId)
1869                    throws SystemException {
1870                    for (DLFileRank dlFileRank : findByG_U(groupId, userId)) {
1871                            remove(dlFileRank);
1872                    }
1873            }
1874    
1875            /**
1876             * Removes all the d l file ranks where folderId = &#63; and name = &#63; from the database.
1877             *
1878             * @param folderId the folder id to search with
1879             * @param name the name to search with
1880             * @throws SystemException if a system exception occurred
1881             */
1882            public void removeByF_N(long folderId, String name)
1883                    throws SystemException {
1884                    for (DLFileRank dlFileRank : findByF_N(folderId, name)) {
1885                            remove(dlFileRank);
1886                    }
1887            }
1888    
1889            /**
1890             * Removes the d l file rank where companyId = &#63; and userId = &#63; and folderId = &#63; and name = &#63; from the database.
1891             *
1892             * @param companyId the company id to search with
1893             * @param userId the user id to search with
1894             * @param folderId the folder id to search with
1895             * @param name the name to search with
1896             * @throws SystemException if a system exception occurred
1897             */
1898            public void removeByC_U_F_N(long companyId, long userId, long folderId,
1899                    String name) throws NoSuchFileRankException, SystemException {
1900                    DLFileRank dlFileRank = findByC_U_F_N(companyId, userId, folderId, name);
1901    
1902                    remove(dlFileRank);
1903            }
1904    
1905            /**
1906             * Removes all the d l file ranks from the database.
1907             *
1908             * @throws SystemException if a system exception occurred
1909             */
1910            public void removeAll() throws SystemException {
1911                    for (DLFileRank dlFileRank : findAll()) {
1912                            remove(dlFileRank);
1913                    }
1914            }
1915    
1916            /**
1917             * Counts all the d l file ranks where userId = &#63;.
1918             *
1919             * @param userId the user id to search with
1920             * @return the number of matching d l file ranks
1921             * @throws SystemException if a system exception occurred
1922             */
1923            public int countByUserId(long userId) throws SystemException {
1924                    Object[] finderArgs = new Object[] { userId };
1925    
1926                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1927                                    finderArgs, this);
1928    
1929                    if (count == null) {
1930                            StringBundler query = new StringBundler(2);
1931    
1932                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
1933    
1934                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1935    
1936                            String sql = query.toString();
1937    
1938                            Session session = null;
1939    
1940                            try {
1941                                    session = openSession();
1942    
1943                                    Query q = session.createQuery(sql);
1944    
1945                                    QueryPos qPos = QueryPos.getInstance(q);
1946    
1947                                    qPos.add(userId);
1948    
1949                                    count = (Long)q.uniqueResult();
1950                            }
1951                            catch (Exception e) {
1952                                    throw processException(e);
1953                            }
1954                            finally {
1955                                    if (count == null) {
1956                                            count = Long.valueOf(0);
1957                                    }
1958    
1959                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1960                                            finderArgs, count);
1961    
1962                                    closeSession(session);
1963                            }
1964                    }
1965    
1966                    return count.intValue();
1967            }
1968    
1969            /**
1970             * Counts all the d l file ranks where groupId = &#63; and userId = &#63;.
1971             *
1972             * @param groupId the group id to search with
1973             * @param userId the user id to search with
1974             * @return the number of matching d l file ranks
1975             * @throws SystemException if a system exception occurred
1976             */
1977            public int countByG_U(long groupId, long userId) throws SystemException {
1978                    Object[] finderArgs = new Object[] { groupId, userId };
1979    
1980                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1981                                    finderArgs, this);
1982    
1983                    if (count == null) {
1984                            StringBundler query = new StringBundler(3);
1985    
1986                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
1987    
1988                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1989    
1990                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1991    
1992                            String sql = query.toString();
1993    
1994                            Session session = null;
1995    
1996                            try {
1997                                    session = openSession();
1998    
1999                                    Query q = session.createQuery(sql);
2000    
2001                                    QueryPos qPos = QueryPos.getInstance(q);
2002    
2003                                    qPos.add(groupId);
2004    
2005                                    qPos.add(userId);
2006    
2007                                    count = (Long)q.uniqueResult();
2008                            }
2009                            catch (Exception e) {
2010                                    throw processException(e);
2011                            }
2012                            finally {
2013                                    if (count == null) {
2014                                            count = Long.valueOf(0);
2015                                    }
2016    
2017                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2018                                            count);
2019    
2020                                    closeSession(session);
2021                            }
2022                    }
2023    
2024                    return count.intValue();
2025            }
2026    
2027            /**
2028             * Counts all the d l file ranks where folderId = &#63; and name = &#63;.
2029             *
2030             * @param folderId the folder id to search with
2031             * @param name the name to search with
2032             * @return the number of matching d l file ranks
2033             * @throws SystemException if a system exception occurred
2034             */
2035            public int countByF_N(long folderId, String name) throws SystemException {
2036                    Object[] finderArgs = new Object[] { folderId, name };
2037    
2038                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_N,
2039                                    finderArgs, this);
2040    
2041                    if (count == null) {
2042                            StringBundler query = new StringBundler(3);
2043    
2044                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2045    
2046                            query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
2047    
2048                            if (name == null) {
2049                                    query.append(_FINDER_COLUMN_F_N_NAME_1);
2050                            }
2051                            else {
2052                                    if (name.equals(StringPool.BLANK)) {
2053                                            query.append(_FINDER_COLUMN_F_N_NAME_3);
2054                                    }
2055                                    else {
2056                                            query.append(_FINDER_COLUMN_F_N_NAME_2);
2057                                    }
2058                            }
2059    
2060                            String sql = query.toString();
2061    
2062                            Session session = null;
2063    
2064                            try {
2065                                    session = openSession();
2066    
2067                                    Query q = session.createQuery(sql);
2068    
2069                                    QueryPos qPos = QueryPos.getInstance(q);
2070    
2071                                    qPos.add(folderId);
2072    
2073                                    if (name != null) {
2074                                            qPos.add(name);
2075                                    }
2076    
2077                                    count = (Long)q.uniqueResult();
2078                            }
2079                            catch (Exception e) {
2080                                    throw processException(e);
2081                            }
2082                            finally {
2083                                    if (count == null) {
2084                                            count = Long.valueOf(0);
2085                                    }
2086    
2087                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_N, finderArgs,
2088                                            count);
2089    
2090                                    closeSession(session);
2091                            }
2092                    }
2093    
2094                    return count.intValue();
2095            }
2096    
2097            /**
2098             * Counts all the d l file ranks where companyId = &#63; and userId = &#63; and folderId = &#63; and name = &#63;.
2099             *
2100             * @param companyId the company id to search with
2101             * @param userId the user id to search with
2102             * @param folderId the folder id to search with
2103             * @param name the name to search with
2104             * @return the number of matching d l file ranks
2105             * @throws SystemException if a system exception occurred
2106             */
2107            public int countByC_U_F_N(long companyId, long userId, long folderId,
2108                    String name) throws SystemException {
2109                    Object[] finderArgs = new Object[] { companyId, userId, folderId, name };
2110    
2111                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_U_F_N,
2112                                    finderArgs, this);
2113    
2114                    if (count == null) {
2115                            StringBundler query = new StringBundler(5);
2116    
2117                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2118    
2119                            query.append(_FINDER_COLUMN_C_U_F_N_COMPANYID_2);
2120    
2121                            query.append(_FINDER_COLUMN_C_U_F_N_USERID_2);
2122    
2123                            query.append(_FINDER_COLUMN_C_U_F_N_FOLDERID_2);
2124    
2125                            if (name == null) {
2126                                    query.append(_FINDER_COLUMN_C_U_F_N_NAME_1);
2127                            }
2128                            else {
2129                                    if (name.equals(StringPool.BLANK)) {
2130                                            query.append(_FINDER_COLUMN_C_U_F_N_NAME_3);
2131                                    }
2132                                    else {
2133                                            query.append(_FINDER_COLUMN_C_U_F_N_NAME_2);
2134                                    }
2135                            }
2136    
2137                            String sql = query.toString();
2138    
2139                            Session session = null;
2140    
2141                            try {
2142                                    session = openSession();
2143    
2144                                    Query q = session.createQuery(sql);
2145    
2146                                    QueryPos qPos = QueryPos.getInstance(q);
2147    
2148                                    qPos.add(companyId);
2149    
2150                                    qPos.add(userId);
2151    
2152                                    qPos.add(folderId);
2153    
2154                                    if (name != null) {
2155                                            qPos.add(name);
2156                                    }
2157    
2158                                    count = (Long)q.uniqueResult();
2159                            }
2160                            catch (Exception e) {
2161                                    throw processException(e);
2162                            }
2163                            finally {
2164                                    if (count == null) {
2165                                            count = Long.valueOf(0);
2166                                    }
2167    
2168                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F_N,
2169                                            finderArgs, count);
2170    
2171                                    closeSession(session);
2172                            }
2173                    }
2174    
2175                    return count.intValue();
2176            }
2177    
2178            /**
2179             * Counts all the d l file ranks.
2180             *
2181             * @return the number of d l file ranks
2182             * @throws SystemException if a system exception occurred
2183             */
2184            public int countAll() throws SystemException {
2185                    Object[] finderArgs = new Object[0];
2186    
2187                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2188                                    finderArgs, this);
2189    
2190                    if (count == null) {
2191                            Session session = null;
2192    
2193                            try {
2194                                    session = openSession();
2195    
2196                                    Query q = session.createQuery(_SQL_COUNT_DLFILERANK);
2197    
2198                                    count = (Long)q.uniqueResult();
2199                            }
2200                            catch (Exception e) {
2201                                    throw processException(e);
2202                            }
2203                            finally {
2204                                    if (count == null) {
2205                                            count = Long.valueOf(0);
2206                                    }
2207    
2208                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2209                                            count);
2210    
2211                                    closeSession(session);
2212                            }
2213                    }
2214    
2215                    return count.intValue();
2216            }
2217    
2218            /**
2219             * Initializes the d l file rank persistence.
2220             */
2221            public void afterPropertiesSet() {
2222                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2223                                            com.liferay.portal.util.PropsUtil.get(
2224                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileRank")));
2225    
2226                    if (listenerClassNames.length > 0) {
2227                            try {
2228                                    List<ModelListener<DLFileRank>> listenersList = new ArrayList<ModelListener<DLFileRank>>();
2229    
2230                                    for (String listenerClassName : listenerClassNames) {
2231                                            listenersList.add((ModelListener<DLFileRank>)InstanceFactory.newInstance(
2232                                                            listenerClassName));
2233                                    }
2234    
2235                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2236                            }
2237                            catch (Exception e) {
2238                                    _log.error(e);
2239                            }
2240                    }
2241            }
2242    
2243            public void destroy() {
2244                    EntityCacheUtil.removeCache(DLFileRankImpl.class.getName());
2245                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2246                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2247            }
2248    
2249            @BeanReference(type = DLFileEntryPersistence.class)
2250            protected DLFileEntryPersistence dlFileEntryPersistence;
2251            @BeanReference(type = DLFileRankPersistence.class)
2252            protected DLFileRankPersistence dlFileRankPersistence;
2253            @BeanReference(type = DLFileShortcutPersistence.class)
2254            protected DLFileShortcutPersistence dlFileShortcutPersistence;
2255            @BeanReference(type = DLFileVersionPersistence.class)
2256            protected DLFileVersionPersistence dlFileVersionPersistence;
2257            @BeanReference(type = DLFolderPersistence.class)
2258            protected DLFolderPersistence dlFolderPersistence;
2259            @BeanReference(type = LayoutPersistence.class)
2260            protected LayoutPersistence layoutPersistence;
2261            @BeanReference(type = ResourcePersistence.class)
2262            protected ResourcePersistence resourcePersistence;
2263            @BeanReference(type = UserPersistence.class)
2264            protected UserPersistence userPersistence;
2265            private static final String _SQL_SELECT_DLFILERANK = "SELECT dlFileRank FROM DLFileRank dlFileRank";
2266            private static final String _SQL_SELECT_DLFILERANK_WHERE = "SELECT dlFileRank FROM DLFileRank dlFileRank WHERE ";
2267            private static final String _SQL_COUNT_DLFILERANK = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank";
2268            private static final String _SQL_COUNT_DLFILERANK_WHERE = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank WHERE ";
2269            private static final String _FINDER_COLUMN_USERID_USERID_2 = "dlFileRank.userId = ?";
2270            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "dlFileRank.groupId = ? AND ";
2271            private static final String _FINDER_COLUMN_G_U_USERID_2 = "dlFileRank.userId = ?";
2272            private static final String _FINDER_COLUMN_F_N_FOLDERID_2 = "dlFileRank.folderId = ? AND ";
2273            private static final String _FINDER_COLUMN_F_N_NAME_1 = "dlFileRank.name IS NULL";
2274            private static final String _FINDER_COLUMN_F_N_NAME_2 = "dlFileRank.name = ?";
2275            private static final String _FINDER_COLUMN_F_N_NAME_3 = "(dlFileRank.name IS NULL OR dlFileRank.name = ?)";
2276            private static final String _FINDER_COLUMN_C_U_F_N_COMPANYID_2 = "dlFileRank.companyId = ? AND ";
2277            private static final String _FINDER_COLUMN_C_U_F_N_USERID_2 = "dlFileRank.userId = ? AND ";
2278            private static final String _FINDER_COLUMN_C_U_F_N_FOLDERID_2 = "dlFileRank.folderId = ? AND ";
2279            private static final String _FINDER_COLUMN_C_U_F_N_NAME_1 = "dlFileRank.name IS NULL";
2280            private static final String _FINDER_COLUMN_C_U_F_N_NAME_2 = "dlFileRank.name = ?";
2281            private static final String _FINDER_COLUMN_C_U_F_N_NAME_3 = "(dlFileRank.name IS NULL OR dlFileRank.name = ?)";
2282            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileRank.";
2283            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileRank exists with the primary key ";
2284            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileRank exists with the key {";
2285            private static Log _log = LogFactoryUtil.getLog(DLFileRankPersistenceImpl.class);
2286    }