001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.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.getOriginalCompanyId()),
297                                    new Long(dlFileRankModelImpl.getOriginalUserId()),
298                                    new Long(dlFileRankModelImpl.getOriginalFolderId()),
299                                    
300                            dlFileRankModelImpl.getOriginalName()
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                            Session session = null;
537    
538                            try {
539                                    session = openSession();
540    
541                                    StringBundler query = null;
542    
543                                    if (orderByComparator != null) {
544                                            query = new StringBundler(3 +
545                                                            (orderByComparator.getOrderByFields().length * 3));
546                                    }
547                                    else {
548                                            query = new StringBundler(3);
549                                    }
550    
551                                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
552    
553                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
554    
555                                    if (orderByComparator != null) {
556                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
557                                                    orderByComparator);
558                                    }
559    
560                                    else {
561                                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
562                                    }
563    
564                                    String sql = query.toString();
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                                            list = new ArrayList<DLFileRank>();
581                                    }
582    
583                                    cacheResult(list);
584    
585                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
586                                            finderArgs, list);
587    
588                                    closeSession(session);
589                            }
590                    }
591    
592                    return list;
593            }
594    
595            /**
596             * Finds the first d l file rank in the ordered set where userId = &#63;.
597             *
598             * <p>
599             * 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.
600             * </p>
601             *
602             * @param userId the user id to search with
603             * @param orderByComparator the comparator to order the set by
604             * @return the first matching d l file rank
605             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
606             * @throws SystemException if a system exception occurred
607             */
608            public DLFileRank findByUserId_First(long userId,
609                    OrderByComparator orderByComparator)
610                    throws NoSuchFileRankException, SystemException {
611                    List<DLFileRank> list = findByUserId(userId, 0, 1, orderByComparator);
612    
613                    if (list.isEmpty()) {
614                            StringBundler msg = new StringBundler(4);
615    
616                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
617    
618                            msg.append("userId=");
619                            msg.append(userId);
620    
621                            msg.append(StringPool.CLOSE_CURLY_BRACE);
622    
623                            throw new NoSuchFileRankException(msg.toString());
624                    }
625                    else {
626                            return list.get(0);
627                    }
628            }
629    
630            /**
631             * Finds the last d l file rank in the ordered set where userId = &#63;.
632             *
633             * <p>
634             * 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.
635             * </p>
636             *
637             * @param userId the user id to search with
638             * @param orderByComparator the comparator to order the set by
639             * @return the last matching d l file rank
640             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
641             * @throws SystemException if a system exception occurred
642             */
643            public DLFileRank findByUserId_Last(long userId,
644                    OrderByComparator orderByComparator)
645                    throws NoSuchFileRankException, SystemException {
646                    int count = countByUserId(userId);
647    
648                    List<DLFileRank> list = findByUserId(userId, count - 1, count,
649                                    orderByComparator);
650    
651                    if (list.isEmpty()) {
652                            StringBundler msg = new StringBundler(4);
653    
654                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
655    
656                            msg.append("userId=");
657                            msg.append(userId);
658    
659                            msg.append(StringPool.CLOSE_CURLY_BRACE);
660    
661                            throw new NoSuchFileRankException(msg.toString());
662                    }
663                    else {
664                            return list.get(0);
665                    }
666            }
667    
668            /**
669             * Finds the d l file ranks before and after the current d l file rank in the ordered set where userId = &#63;.
670             *
671             * <p>
672             * 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.
673             * </p>
674             *
675             * @param fileRankId the primary key of the current d l file rank
676             * @param userId the user id to search with
677             * @param orderByComparator the comparator to order the set by
678             * @return the previous, current, and next d l file rank
679             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a d l file rank with the primary key could not be found
680             * @throws SystemException if a system exception occurred
681             */
682            public DLFileRank[] findByUserId_PrevAndNext(long fileRankId, long userId,
683                    OrderByComparator orderByComparator)
684                    throws NoSuchFileRankException, SystemException {
685                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
686    
687                    Session session = null;
688    
689                    try {
690                            session = openSession();
691    
692                            DLFileRank[] array = new DLFileRankImpl[3];
693    
694                            array[0] = getByUserId_PrevAndNext(session, dlFileRank, userId,
695                                            orderByComparator, true);
696    
697                            array[1] = dlFileRank;
698    
699                            array[2] = getByUserId_PrevAndNext(session, dlFileRank, userId,
700                                            orderByComparator, false);
701    
702                            return array;
703                    }
704                    catch (Exception e) {
705                            throw processException(e);
706                    }
707                    finally {
708                            closeSession(session);
709                    }
710            }
711    
712            protected DLFileRank getByUserId_PrevAndNext(Session session,
713                    DLFileRank dlFileRank, long userId,
714                    OrderByComparator orderByComparator, boolean previous) {
715                    StringBundler query = null;
716    
717                    if (orderByComparator != null) {
718                            query = new StringBundler(6 +
719                                            (orderByComparator.getOrderByFields().length * 6));
720                    }
721                    else {
722                            query = new StringBundler(3);
723                    }
724    
725                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
726    
727                    query.append(_FINDER_COLUMN_USERID_USERID_2);
728    
729                    if (orderByComparator != null) {
730                            String[] orderByFields = orderByComparator.getOrderByFields();
731    
732                            if (orderByFields.length > 0) {
733                                    query.append(WHERE_AND);
734                            }
735    
736                            for (int i = 0; i < orderByFields.length; i++) {
737                                    query.append(_ORDER_BY_ENTITY_ALIAS);
738                                    query.append(orderByFields[i]);
739    
740                                    if ((i + 1) < orderByFields.length) {
741                                            if (orderByComparator.isAscending() ^ previous) {
742                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
743                                            }
744                                            else {
745                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
746                                            }
747                                    }
748                                    else {
749                                            if (orderByComparator.isAscending() ^ previous) {
750                                                    query.append(WHERE_GREATER_THAN);
751                                            }
752                                            else {
753                                                    query.append(WHERE_LESSER_THAN);
754                                            }
755                                    }
756                            }
757    
758                            query.append(ORDER_BY_CLAUSE);
759    
760                            for (int i = 0; i < orderByFields.length; i++) {
761                                    query.append(_ORDER_BY_ENTITY_ALIAS);
762                                    query.append(orderByFields[i]);
763    
764                                    if ((i + 1) < orderByFields.length) {
765                                            if (orderByComparator.isAscending() ^ previous) {
766                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
767                                            }
768                                            else {
769                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
770                                            }
771                                    }
772                                    else {
773                                            if (orderByComparator.isAscending() ^ previous) {
774                                                    query.append(ORDER_BY_ASC);
775                                            }
776                                            else {
777                                                    query.append(ORDER_BY_DESC);
778                                            }
779                                    }
780                            }
781                    }
782    
783                    else {
784                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
785                    }
786    
787                    String sql = query.toString();
788    
789                    Query q = session.createQuery(sql);
790    
791                    q.setFirstResult(0);
792                    q.setMaxResults(2);
793    
794                    QueryPos qPos = QueryPos.getInstance(q);
795    
796                    qPos.add(userId);
797    
798                    if (orderByComparator != null) {
799                            Object[] values = orderByComparator.getOrderByValues(dlFileRank);
800    
801                            for (Object value : values) {
802                                    qPos.add(value);
803                            }
804                    }
805    
806                    List<DLFileRank> list = q.list();
807    
808                    if (list.size() == 2) {
809                            return list.get(1);
810                    }
811                    else {
812                            return null;
813                    }
814            }
815    
816            /**
817             * Finds all the d l file ranks where groupId = &#63; and userId = &#63;.
818             *
819             * @param groupId the group id to search with
820             * @param userId the user id to search with
821             * @return the matching d l file ranks
822             * @throws SystemException if a system exception occurred
823             */
824            public List<DLFileRank> findByG_U(long groupId, long userId)
825                    throws SystemException {
826                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
827                            null);
828            }
829    
830            /**
831             * Finds a range of all the d l file ranks where groupId = &#63; and userId = &#63;.
832             *
833             * <p>
834             * 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.
835             * </p>
836             *
837             * @param groupId the group id to search with
838             * @param userId the user id to search with
839             * @param start the lower bound of the range of d l file ranks to return
840             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
841             * @return the range of matching d l file ranks
842             * @throws SystemException if a system exception occurred
843             */
844            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
845                    int end) throws SystemException {
846                    return findByG_U(groupId, userId, start, end, null);
847            }
848    
849            /**
850             * Finds an ordered range of all the d l file ranks where groupId = &#63; and userId = &#63;.
851             *
852             * <p>
853             * 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.
854             * </p>
855             *
856             * @param groupId the group id to search with
857             * @param userId the user id to search with
858             * @param start the lower bound of the range of d l file ranks to return
859             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
860             * @param orderByComparator the comparator to order the results by
861             * @return the ordered range of matching d l file ranks
862             * @throws SystemException if a system exception occurred
863             */
864            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
865                    int end, OrderByComparator orderByComparator) throws SystemException {
866                    Object[] finderArgs = new Object[] {
867                                    groupId, userId,
868                                    
869                                    String.valueOf(start), String.valueOf(end),
870                                    String.valueOf(orderByComparator)
871                            };
872    
873                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_U,
874                                    finderArgs, this);
875    
876                    if (list == null) {
877                            Session session = null;
878    
879                            try {
880                                    session = openSession();
881    
882                                    StringBundler query = null;
883    
884                                    if (orderByComparator != null) {
885                                            query = new StringBundler(4 +
886                                                            (orderByComparator.getOrderByFields().length * 3));
887                                    }
888                                    else {
889                                            query = new StringBundler(4);
890                                    }
891    
892                                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
893    
894                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
895    
896                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
897    
898                                    if (orderByComparator != null) {
899                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
900                                                    orderByComparator);
901                                    }
902    
903                                    else {
904                                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
905                                    }
906    
907                                    String sql = query.toString();
908    
909                                    Query q = session.createQuery(sql);
910    
911                                    QueryPos qPos = QueryPos.getInstance(q);
912    
913                                    qPos.add(groupId);
914    
915                                    qPos.add(userId);
916    
917                                    list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
918                                                    end);
919                            }
920                            catch (Exception e) {
921                                    throw processException(e);
922                            }
923                            finally {
924                                    if (list == null) {
925                                            list = new ArrayList<DLFileRank>();
926                                    }
927    
928                                    cacheResult(list);
929    
930                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_U, finderArgs,
931                                            list);
932    
933                                    closeSession(session);
934                            }
935                    }
936    
937                    return list;
938            }
939    
940            /**
941             * Finds the first d l file rank in the ordered set where groupId = &#63; and userId = &#63;.
942             *
943             * <p>
944             * 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.
945             * </p>
946             *
947             * @param groupId the group id to search with
948             * @param userId the user id to search with
949             * @param orderByComparator the comparator to order the set by
950             * @return the first matching d l file rank
951             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
952             * @throws SystemException if a system exception occurred
953             */
954            public DLFileRank findByG_U_First(long groupId, long userId,
955                    OrderByComparator orderByComparator)
956                    throws NoSuchFileRankException, SystemException {
957                    List<DLFileRank> list = findByG_U(groupId, userId, 0, 1,
958                                    orderByComparator);
959    
960                    if (list.isEmpty()) {
961                            StringBundler msg = new StringBundler(6);
962    
963                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
964    
965                            msg.append("groupId=");
966                            msg.append(groupId);
967    
968                            msg.append(", userId=");
969                            msg.append(userId);
970    
971                            msg.append(StringPool.CLOSE_CURLY_BRACE);
972    
973                            throw new NoSuchFileRankException(msg.toString());
974                    }
975                    else {
976                            return list.get(0);
977                    }
978            }
979    
980            /**
981             * Finds the last d l file rank in the ordered set where groupId = &#63; and userId = &#63;.
982             *
983             * <p>
984             * 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.
985             * </p>
986             *
987             * @param groupId the group id to search with
988             * @param userId the user id to search with
989             * @param orderByComparator the comparator to order the set by
990             * @return the last matching d l file rank
991             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
992             * @throws SystemException if a system exception occurred
993             */
994            public DLFileRank findByG_U_Last(long groupId, long userId,
995                    OrderByComparator orderByComparator)
996                    throws NoSuchFileRankException, SystemException {
997                    int count = countByG_U(groupId, userId);
998    
999                    List<DLFileRank> list = findByG_U(groupId, userId, count - 1, count,
1000                                    orderByComparator);
1001    
1002                    if (list.isEmpty()) {
1003                            StringBundler msg = new StringBundler(6);
1004    
1005                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1006    
1007                            msg.append("groupId=");
1008                            msg.append(groupId);
1009    
1010                            msg.append(", userId=");
1011                            msg.append(userId);
1012    
1013                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1014    
1015                            throw new NoSuchFileRankException(msg.toString());
1016                    }
1017                    else {
1018                            return list.get(0);
1019                    }
1020            }
1021    
1022            /**
1023             * 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;.
1024             *
1025             * <p>
1026             * 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.
1027             * </p>
1028             *
1029             * @param fileRankId the primary key of the current d l file rank
1030             * @param groupId the group id to search with
1031             * @param userId the user id to search with
1032             * @param orderByComparator the comparator to order the set by
1033             * @return the previous, current, and next d l file rank
1034             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a d l file rank with the primary key could not be found
1035             * @throws SystemException if a system exception occurred
1036             */
1037            public DLFileRank[] findByG_U_PrevAndNext(long fileRankId, long groupId,
1038                    long userId, OrderByComparator orderByComparator)
1039                    throws NoSuchFileRankException, SystemException {
1040                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1041    
1042                    Session session = null;
1043    
1044                    try {
1045                            session = openSession();
1046    
1047                            DLFileRank[] array = new DLFileRankImpl[3];
1048    
1049                            array[0] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1050                                            userId, orderByComparator, true);
1051    
1052                            array[1] = dlFileRank;
1053    
1054                            array[2] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1055                                            userId, orderByComparator, false);
1056    
1057                            return array;
1058                    }
1059                    catch (Exception e) {
1060                            throw processException(e);
1061                    }
1062                    finally {
1063                            closeSession(session);
1064                    }
1065            }
1066    
1067            protected DLFileRank getByG_U_PrevAndNext(Session session,
1068                    DLFileRank dlFileRank, long groupId, long userId,
1069                    OrderByComparator orderByComparator, boolean previous) {
1070                    StringBundler query = null;
1071    
1072                    if (orderByComparator != null) {
1073                            query = new StringBundler(6 +
1074                                            (orderByComparator.getOrderByFields().length * 6));
1075                    }
1076                    else {
1077                            query = new StringBundler(3);
1078                    }
1079    
1080                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1081    
1082                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1083    
1084                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1085    
1086                    if (orderByComparator != null) {
1087                            String[] orderByFields = orderByComparator.getOrderByFields();
1088    
1089                            if (orderByFields.length > 0) {
1090                                    query.append(WHERE_AND);
1091                            }
1092    
1093                            for (int i = 0; i < orderByFields.length; i++) {
1094                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1095                                    query.append(orderByFields[i]);
1096    
1097                                    if ((i + 1) < orderByFields.length) {
1098                                            if (orderByComparator.isAscending() ^ previous) {
1099                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1100                                            }
1101                                            else {
1102                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1103                                            }
1104                                    }
1105                                    else {
1106                                            if (orderByComparator.isAscending() ^ previous) {
1107                                                    query.append(WHERE_GREATER_THAN);
1108                                            }
1109                                            else {
1110                                                    query.append(WHERE_LESSER_THAN);
1111                                            }
1112                                    }
1113                            }
1114    
1115                            query.append(ORDER_BY_CLAUSE);
1116    
1117                            for (int i = 0; i < orderByFields.length; i++) {
1118                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1119                                    query.append(orderByFields[i]);
1120    
1121                                    if ((i + 1) < orderByFields.length) {
1122                                            if (orderByComparator.isAscending() ^ previous) {
1123                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1124                                            }
1125                                            else {
1126                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1127                                            }
1128                                    }
1129                                    else {
1130                                            if (orderByComparator.isAscending() ^ previous) {
1131                                                    query.append(ORDER_BY_ASC);
1132                                            }
1133                                            else {
1134                                                    query.append(ORDER_BY_DESC);
1135                                            }
1136                                    }
1137                            }
1138                    }
1139    
1140                    else {
1141                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1142                    }
1143    
1144                    String sql = query.toString();
1145    
1146                    Query q = session.createQuery(sql);
1147    
1148                    q.setFirstResult(0);
1149                    q.setMaxResults(2);
1150    
1151                    QueryPos qPos = QueryPos.getInstance(q);
1152    
1153                    qPos.add(groupId);
1154    
1155                    qPos.add(userId);
1156    
1157                    if (orderByComparator != null) {
1158                            Object[] values = orderByComparator.getOrderByValues(dlFileRank);
1159    
1160                            for (Object value : values) {
1161                                    qPos.add(value);
1162                            }
1163                    }
1164    
1165                    List<DLFileRank> list = q.list();
1166    
1167                    if (list.size() == 2) {
1168                            return list.get(1);
1169                    }
1170                    else {
1171                            return null;
1172                    }
1173            }
1174    
1175            /**
1176             * Finds all the d l file ranks where folderId = &#63; and name = &#63;.
1177             *
1178             * @param folderId the folder id to search with
1179             * @param name the name to search with
1180             * @return the matching d l file ranks
1181             * @throws SystemException if a system exception occurred
1182             */
1183            public List<DLFileRank> findByF_N(long folderId, String name)
1184                    throws SystemException {
1185                    return findByF_N(folderId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1186                            null);
1187            }
1188    
1189            /**
1190             * Finds a range of all the d l file ranks where folderId = &#63; and name = &#63;.
1191             *
1192             * <p>
1193             * 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.
1194             * </p>
1195             *
1196             * @param folderId the folder id to search with
1197             * @param name the name to search with
1198             * @param start the lower bound of the range of d l file ranks to return
1199             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
1200             * @return the range of matching d l file ranks
1201             * @throws SystemException if a system exception occurred
1202             */
1203            public List<DLFileRank> findByF_N(long folderId, String name, int start,
1204                    int end) throws SystemException {
1205                    return findByF_N(folderId, name, start, end, null);
1206            }
1207    
1208            /**
1209             * Finds an ordered range of all the d l file ranks where folderId = &#63; and name = &#63;.
1210             *
1211             * <p>
1212             * 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.
1213             * </p>
1214             *
1215             * @param folderId the folder id to search with
1216             * @param name the name to search with
1217             * @param start the lower bound of the range of d l file ranks to return
1218             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
1219             * @param orderByComparator the comparator to order the results by
1220             * @return the ordered range of matching d l file ranks
1221             * @throws SystemException if a system exception occurred
1222             */
1223            public List<DLFileRank> findByF_N(long folderId, String name, int start,
1224                    int end, OrderByComparator orderByComparator) throws SystemException {
1225                    Object[] finderArgs = new Object[] {
1226                                    folderId, name,
1227                                    
1228                                    String.valueOf(start), String.valueOf(end),
1229                                    String.valueOf(orderByComparator)
1230                            };
1231    
1232                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_F_N,
1233                                    finderArgs, this);
1234    
1235                    if (list == null) {
1236                            Session session = null;
1237    
1238                            try {
1239                                    session = openSession();
1240    
1241                                    StringBundler query = null;
1242    
1243                                    if (orderByComparator != null) {
1244                                            query = new StringBundler(4 +
1245                                                            (orderByComparator.getOrderByFields().length * 3));
1246                                    }
1247                                    else {
1248                                            query = new StringBundler(4);
1249                                    }
1250    
1251                                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1252    
1253                                    query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
1254    
1255                                    if (name == null) {
1256                                            query.append(_FINDER_COLUMN_F_N_NAME_1);
1257                                    }
1258                                    else {
1259                                            if (name.equals(StringPool.BLANK)) {
1260                                                    query.append(_FINDER_COLUMN_F_N_NAME_3);
1261                                            }
1262                                            else {
1263                                                    query.append(_FINDER_COLUMN_F_N_NAME_2);
1264                                            }
1265                                    }
1266    
1267                                    if (orderByComparator != null) {
1268                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1269                                                    orderByComparator);
1270                                    }
1271    
1272                                    else {
1273                                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1274                                    }
1275    
1276                                    String sql = query.toString();
1277    
1278                                    Query q = session.createQuery(sql);
1279    
1280                                    QueryPos qPos = QueryPos.getInstance(q);
1281    
1282                                    qPos.add(folderId);
1283    
1284                                    if (name != null) {
1285                                            qPos.add(name);
1286                                    }
1287    
1288                                    list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
1289                                                    end);
1290                            }
1291                            catch (Exception e) {
1292                                    throw processException(e);
1293                            }
1294                            finally {
1295                                    if (list == null) {
1296                                            list = new ArrayList<DLFileRank>();
1297                                    }
1298    
1299                                    cacheResult(list);
1300    
1301                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_F_N, finderArgs,
1302                                            list);
1303    
1304                                    closeSession(session);
1305                            }
1306                    }
1307    
1308                    return list;
1309            }
1310    
1311            /**
1312             * Finds the first d l file rank in the ordered set where folderId = &#63; and name = &#63;.
1313             *
1314             * <p>
1315             * 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.
1316             * </p>
1317             *
1318             * @param folderId the folder id to search with
1319             * @param name the name to search with
1320             * @param orderByComparator the comparator to order the set by
1321             * @return the first matching d l file rank
1322             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
1323             * @throws SystemException if a system exception occurred
1324             */
1325            public DLFileRank findByF_N_First(long folderId, String name,
1326                    OrderByComparator orderByComparator)
1327                    throws NoSuchFileRankException, SystemException {
1328                    List<DLFileRank> list = findByF_N(folderId, name, 0, 1,
1329                                    orderByComparator);
1330    
1331                    if (list.isEmpty()) {
1332                            StringBundler msg = new StringBundler(6);
1333    
1334                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1335    
1336                            msg.append("folderId=");
1337                            msg.append(folderId);
1338    
1339                            msg.append(", name=");
1340                            msg.append(name);
1341    
1342                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1343    
1344                            throw new NoSuchFileRankException(msg.toString());
1345                    }
1346                    else {
1347                            return list.get(0);
1348                    }
1349            }
1350    
1351            /**
1352             * Finds the last d l file rank in the ordered set where folderId = &#63; and name = &#63;.
1353             *
1354             * <p>
1355             * 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.
1356             * </p>
1357             *
1358             * @param folderId the folder id to search with
1359             * @param name the name to search with
1360             * @param orderByComparator the comparator to order the set by
1361             * @return the last matching d l file rank
1362             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
1363             * @throws SystemException if a system exception occurred
1364             */
1365            public DLFileRank findByF_N_Last(long folderId, String name,
1366                    OrderByComparator orderByComparator)
1367                    throws NoSuchFileRankException, SystemException {
1368                    int count = countByF_N(folderId, name);
1369    
1370                    List<DLFileRank> list = findByF_N(folderId, name, count - 1, count,
1371                                    orderByComparator);
1372    
1373                    if (list.isEmpty()) {
1374                            StringBundler msg = new StringBundler(6);
1375    
1376                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1377    
1378                            msg.append("folderId=");
1379                            msg.append(folderId);
1380    
1381                            msg.append(", name=");
1382                            msg.append(name);
1383    
1384                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1385    
1386                            throw new NoSuchFileRankException(msg.toString());
1387                    }
1388                    else {
1389                            return list.get(0);
1390                    }
1391            }
1392    
1393            /**
1394             * 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;.
1395             *
1396             * <p>
1397             * 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.
1398             * </p>
1399             *
1400             * @param fileRankId the primary key of the current d l file rank
1401             * @param folderId the folder id to search with
1402             * @param name the name to search with
1403             * @param orderByComparator the comparator to order the set by
1404             * @return the previous, current, and next d l file rank
1405             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a d l file rank with the primary key could not be found
1406             * @throws SystemException if a system exception occurred
1407             */
1408            public DLFileRank[] findByF_N_PrevAndNext(long fileRankId, long folderId,
1409                    String name, OrderByComparator orderByComparator)
1410                    throws NoSuchFileRankException, SystemException {
1411                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1412    
1413                    Session session = null;
1414    
1415                    try {
1416                            session = openSession();
1417    
1418                            DLFileRank[] array = new DLFileRankImpl[3];
1419    
1420                            array[0] = getByF_N_PrevAndNext(session, dlFileRank, folderId,
1421                                            name, orderByComparator, true);
1422    
1423                            array[1] = dlFileRank;
1424    
1425                            array[2] = getByF_N_PrevAndNext(session, dlFileRank, folderId,
1426                                            name, orderByComparator, false);
1427    
1428                            return array;
1429                    }
1430                    catch (Exception e) {
1431                            throw processException(e);
1432                    }
1433                    finally {
1434                            closeSession(session);
1435                    }
1436            }
1437    
1438            protected DLFileRank getByF_N_PrevAndNext(Session session,
1439                    DLFileRank dlFileRank, long folderId, String name,
1440                    OrderByComparator orderByComparator, boolean previous) {
1441                    StringBundler query = null;
1442    
1443                    if (orderByComparator != null) {
1444                            query = new StringBundler(6 +
1445                                            (orderByComparator.getOrderByFields().length * 6));
1446                    }
1447                    else {
1448                            query = new StringBundler(3);
1449                    }
1450    
1451                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1452    
1453                    query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
1454    
1455                    if (name == null) {
1456                            query.append(_FINDER_COLUMN_F_N_NAME_1);
1457                    }
1458                    else {
1459                            if (name.equals(StringPool.BLANK)) {
1460                                    query.append(_FINDER_COLUMN_F_N_NAME_3);
1461                            }
1462                            else {
1463                                    query.append(_FINDER_COLUMN_F_N_NAME_2);
1464                            }
1465                    }
1466    
1467                    if (orderByComparator != null) {
1468                            String[] orderByFields = orderByComparator.getOrderByFields();
1469    
1470                            if (orderByFields.length > 0) {
1471                                    query.append(WHERE_AND);
1472                            }
1473    
1474                            for (int i = 0; i < orderByFields.length; i++) {
1475                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1476                                    query.append(orderByFields[i]);
1477    
1478                                    if ((i + 1) < orderByFields.length) {
1479                                            if (orderByComparator.isAscending() ^ previous) {
1480                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1481                                            }
1482                                            else {
1483                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1484                                            }
1485                                    }
1486                                    else {
1487                                            if (orderByComparator.isAscending() ^ previous) {
1488                                                    query.append(WHERE_GREATER_THAN);
1489                                            }
1490                                            else {
1491                                                    query.append(WHERE_LESSER_THAN);
1492                                            }
1493                                    }
1494                            }
1495    
1496                            query.append(ORDER_BY_CLAUSE);
1497    
1498                            for (int i = 0; i < orderByFields.length; i++) {
1499                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1500                                    query.append(orderByFields[i]);
1501    
1502                                    if ((i + 1) < orderByFields.length) {
1503                                            if (orderByComparator.isAscending() ^ previous) {
1504                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1505                                            }
1506                                            else {
1507                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1508                                            }
1509                                    }
1510                                    else {
1511                                            if (orderByComparator.isAscending() ^ previous) {
1512                                                    query.append(ORDER_BY_ASC);
1513                                            }
1514                                            else {
1515                                                    query.append(ORDER_BY_DESC);
1516                                            }
1517                                    }
1518                            }
1519                    }
1520    
1521                    else {
1522                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1523                    }
1524    
1525                    String sql = query.toString();
1526    
1527                    Query q = session.createQuery(sql);
1528    
1529                    q.setFirstResult(0);
1530                    q.setMaxResults(2);
1531    
1532                    QueryPos qPos = QueryPos.getInstance(q);
1533    
1534                    qPos.add(folderId);
1535    
1536                    if (name != null) {
1537                            qPos.add(name);
1538                    }
1539    
1540                    if (orderByComparator != null) {
1541                            Object[] values = orderByComparator.getOrderByValues(dlFileRank);
1542    
1543                            for (Object value : values) {
1544                                    qPos.add(value);
1545                            }
1546                    }
1547    
1548                    List<DLFileRank> list = q.list();
1549    
1550                    if (list.size() == 2) {
1551                            return list.get(1);
1552                    }
1553                    else {
1554                            return null;
1555                    }
1556            }
1557    
1558            /**
1559             * 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.
1560             *
1561             * @param companyId the company id to search with
1562             * @param userId the user id to search with
1563             * @param folderId the folder id to search with
1564             * @param name the name to search with
1565             * @return the matching d l file rank
1566             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching d l file rank could not be found
1567             * @throws SystemException if a system exception occurred
1568             */
1569            public DLFileRank findByC_U_F_N(long companyId, long userId, long folderId,
1570                    String name) throws NoSuchFileRankException, SystemException {
1571                    DLFileRank dlFileRank = fetchByC_U_F_N(companyId, userId, folderId, name);
1572    
1573                    if (dlFileRank == null) {
1574                            StringBundler msg = new StringBundler(10);
1575    
1576                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1577    
1578                            msg.append("companyId=");
1579                            msg.append(companyId);
1580    
1581                            msg.append(", userId=");
1582                            msg.append(userId);
1583    
1584                            msg.append(", folderId=");
1585                            msg.append(folderId);
1586    
1587                            msg.append(", name=");
1588                            msg.append(name);
1589    
1590                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1591    
1592                            if (_log.isWarnEnabled()) {
1593                                    _log.warn(msg.toString());
1594                            }
1595    
1596                            throw new NoSuchFileRankException(msg.toString());
1597                    }
1598    
1599                    return dlFileRank;
1600            }
1601    
1602            /**
1603             * 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.
1604             *
1605             * @param companyId the company id to search with
1606             * @param userId the user id to search with
1607             * @param folderId the folder id to search with
1608             * @param name the name to search with
1609             * @return the matching d l file rank, or <code>null</code> if a matching d l file rank could not be found
1610             * @throws SystemException if a system exception occurred
1611             */
1612            public DLFileRank fetchByC_U_F_N(long companyId, long userId,
1613                    long folderId, String name) throws SystemException {
1614                    return fetchByC_U_F_N(companyId, userId, folderId, name, true);
1615            }
1616    
1617            /**
1618             * 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.
1619             *
1620             * @param companyId the company id to search with
1621             * @param userId the user id to search with
1622             * @param folderId the folder id to search with
1623             * @param name the name to search with
1624             * @return the matching d l file rank, or <code>null</code> if a matching d l file rank could not be found
1625             * @throws SystemException if a system exception occurred
1626             */
1627            public DLFileRank fetchByC_U_F_N(long companyId, long userId,
1628                    long folderId, String name, boolean retrieveFromCache)
1629                    throws SystemException {
1630                    Object[] finderArgs = new Object[] { companyId, userId, folderId, name };
1631    
1632                    Object result = null;
1633    
1634                    if (retrieveFromCache) {
1635                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1636                                            finderArgs, this);
1637                    }
1638    
1639                    if (result == null) {
1640                            Session session = null;
1641    
1642                            try {
1643                                    session = openSession();
1644    
1645                                    StringBundler query = new StringBundler(6);
1646    
1647                                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1648    
1649                                    query.append(_FINDER_COLUMN_C_U_F_N_COMPANYID_2);
1650    
1651                                    query.append(_FINDER_COLUMN_C_U_F_N_USERID_2);
1652    
1653                                    query.append(_FINDER_COLUMN_C_U_F_N_FOLDERID_2);
1654    
1655                                    if (name == null) {
1656                                            query.append(_FINDER_COLUMN_C_U_F_N_NAME_1);
1657                                    }
1658                                    else {
1659                                            if (name.equals(StringPool.BLANK)) {
1660                                                    query.append(_FINDER_COLUMN_C_U_F_N_NAME_3);
1661                                            }
1662                                            else {
1663                                                    query.append(_FINDER_COLUMN_C_U_F_N_NAME_2);
1664                                            }
1665                                    }
1666    
1667                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1668    
1669                                    String sql = query.toString();
1670    
1671                                    Query q = session.createQuery(sql);
1672    
1673                                    QueryPos qPos = QueryPos.getInstance(q);
1674    
1675                                    qPos.add(companyId);
1676    
1677                                    qPos.add(userId);
1678    
1679                                    qPos.add(folderId);
1680    
1681                                    if (name != null) {
1682                                            qPos.add(name);
1683                                    }
1684    
1685                                    List<DLFileRank> list = q.list();
1686    
1687                                    result = list;
1688    
1689                                    DLFileRank dlFileRank = null;
1690    
1691                                    if (list.isEmpty()) {
1692                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1693                                                    finderArgs, list);
1694                                    }
1695                                    else {
1696                                            dlFileRank = list.get(0);
1697    
1698                                            cacheResult(dlFileRank);
1699    
1700                                            if ((dlFileRank.getCompanyId() != companyId) ||
1701                                                            (dlFileRank.getUserId() != userId) ||
1702                                                            (dlFileRank.getFolderId() != folderId) ||
1703                                                            (dlFileRank.getName() == null) ||
1704                                                            !dlFileRank.getName().equals(name)) {
1705                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1706                                                            finderArgs, dlFileRank);
1707                                            }
1708                                    }
1709    
1710                                    return dlFileRank;
1711                            }
1712                            catch (Exception e) {
1713                                    throw processException(e);
1714                            }
1715                            finally {
1716                                    if (result == null) {
1717                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F_N,
1718                                                    finderArgs, new ArrayList<DLFileRank>());
1719                                    }
1720    
1721                                    closeSession(session);
1722                            }
1723                    }
1724                    else {
1725                            if (result instanceof List<?>) {
1726                                    return null;
1727                            }
1728                            else {
1729                                    return (DLFileRank)result;
1730                            }
1731                    }
1732            }
1733    
1734            /**
1735             * Finds all the d l file ranks.
1736             *
1737             * @return the d l file ranks
1738             * @throws SystemException if a system exception occurred
1739             */
1740            public List<DLFileRank> findAll() throws SystemException {
1741                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1742            }
1743    
1744            /**
1745             * Finds a range of all the d l file ranks.
1746             *
1747             * <p>
1748             * 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.
1749             * </p>
1750             *
1751             * @param start the lower bound of the range of d l file ranks to return
1752             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
1753             * @return the range of d l file ranks
1754             * @throws SystemException if a system exception occurred
1755             */
1756            public List<DLFileRank> findAll(int start, int end)
1757                    throws SystemException {
1758                    return findAll(start, end, null);
1759            }
1760    
1761            /**
1762             * Finds an ordered range of all the d l file ranks.
1763             *
1764             * <p>
1765             * 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.
1766             * </p>
1767             *
1768             * @param start the lower bound of the range of d l file ranks to return
1769             * @param end the upper bound of the range of d l file ranks to return (not inclusive)
1770             * @param orderByComparator the comparator to order the results by
1771             * @return the ordered range of d l file ranks
1772             * @throws SystemException if a system exception occurred
1773             */
1774            public List<DLFileRank> findAll(int start, int end,
1775                    OrderByComparator orderByComparator) throws SystemException {
1776                    Object[] finderArgs = new Object[] {
1777                                    String.valueOf(start), String.valueOf(end),
1778                                    String.valueOf(orderByComparator)
1779                            };
1780    
1781                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1782                                    finderArgs, this);
1783    
1784                    if (list == null) {
1785                            Session session = null;
1786    
1787                            try {
1788                                    session = openSession();
1789    
1790                                    StringBundler query = null;
1791                                    String sql = null;
1792    
1793                                    if (orderByComparator != null) {
1794                                            query = new StringBundler(2 +
1795                                                            (orderByComparator.getOrderByFields().length * 3));
1796    
1797                                            query.append(_SQL_SELECT_DLFILERANK);
1798    
1799                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1800                                                    orderByComparator);
1801    
1802                                            sql = query.toString();
1803                                    }
1804                                    else {
1805                                            sql = _SQL_SELECT_DLFILERANK.concat(DLFileRankModelImpl.ORDER_BY_JPQL);
1806                                    }
1807    
1808                                    Query q = session.createQuery(sql);
1809    
1810                                    if (orderByComparator == null) {
1811                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1812                                                            start, end, false);
1813    
1814                                            Collections.sort(list);
1815                                    }
1816                                    else {
1817                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1818                                                            start, end);
1819                                    }
1820                            }
1821                            catch (Exception e) {
1822                                    throw processException(e);
1823                            }
1824                            finally {
1825                                    if (list == null) {
1826                                            list = new ArrayList<DLFileRank>();
1827                                    }
1828    
1829                                    cacheResult(list);
1830    
1831                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1832    
1833                                    closeSession(session);
1834                            }
1835                    }
1836    
1837                    return list;
1838            }
1839    
1840            /**
1841             * Removes all the d l file ranks where userId = &#63; from the database.
1842             *
1843             * @param userId the user id to search with
1844             * @throws SystemException if a system exception occurred
1845             */
1846            public void removeByUserId(long userId) throws SystemException {
1847                    for (DLFileRank dlFileRank : findByUserId(userId)) {
1848                            remove(dlFileRank);
1849                    }
1850            }
1851    
1852            /**
1853             * Removes all the d l file ranks where groupId = &#63; and userId = &#63; from the database.
1854             *
1855             * @param groupId the group id to search with
1856             * @param userId the user id to search with
1857             * @throws SystemException if a system exception occurred
1858             */
1859            public void removeByG_U(long groupId, long userId)
1860                    throws SystemException {
1861                    for (DLFileRank dlFileRank : findByG_U(groupId, userId)) {
1862                            remove(dlFileRank);
1863                    }
1864            }
1865    
1866            /**
1867             * Removes all the d l file ranks where folderId = &#63; and name = &#63; from the database.
1868             *
1869             * @param folderId the folder id to search with
1870             * @param name the name to search with
1871             * @throws SystemException if a system exception occurred
1872             */
1873            public void removeByF_N(long folderId, String name)
1874                    throws SystemException {
1875                    for (DLFileRank dlFileRank : findByF_N(folderId, name)) {
1876                            remove(dlFileRank);
1877                    }
1878            }
1879    
1880            /**
1881             * Removes the d l file rank where companyId = &#63; and userId = &#63; and folderId = &#63; and name = &#63; from the database.
1882             *
1883             * @param companyId the company id to search with
1884             * @param userId the user id to search with
1885             * @param folderId the folder id to search with
1886             * @param name the name to search with
1887             * @throws SystemException if a system exception occurred
1888             */
1889            public void removeByC_U_F_N(long companyId, long userId, long folderId,
1890                    String name) throws NoSuchFileRankException, SystemException {
1891                    DLFileRank dlFileRank = findByC_U_F_N(companyId, userId, folderId, name);
1892    
1893                    remove(dlFileRank);
1894            }
1895    
1896            /**
1897             * Removes all the d l file ranks from the database.
1898             *
1899             * @throws SystemException if a system exception occurred
1900             */
1901            public void removeAll() throws SystemException {
1902                    for (DLFileRank dlFileRank : findAll()) {
1903                            remove(dlFileRank);
1904                    }
1905            }
1906    
1907            /**
1908             * Counts all the d l file ranks where userId = &#63;.
1909             *
1910             * @param userId the user id to search with
1911             * @return the number of matching d l file ranks
1912             * @throws SystemException if a system exception occurred
1913             */
1914            public int countByUserId(long userId) throws SystemException {
1915                    Object[] finderArgs = new Object[] { userId };
1916    
1917                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1918                                    finderArgs, this);
1919    
1920                    if (count == null) {
1921                            Session session = null;
1922    
1923                            try {
1924                                    session = openSession();
1925    
1926                                    StringBundler query = new StringBundler(2);
1927    
1928                                    query.append(_SQL_COUNT_DLFILERANK_WHERE);
1929    
1930                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1931    
1932                                    String sql = query.toString();
1933    
1934                                    Query q = session.createQuery(sql);
1935    
1936                                    QueryPos qPos = QueryPos.getInstance(q);
1937    
1938                                    qPos.add(userId);
1939    
1940                                    count = (Long)q.uniqueResult();
1941                            }
1942                            catch (Exception e) {
1943                                    throw processException(e);
1944                            }
1945                            finally {
1946                                    if (count == null) {
1947                                            count = Long.valueOf(0);
1948                                    }
1949    
1950                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1951                                            finderArgs, count);
1952    
1953                                    closeSession(session);
1954                            }
1955                    }
1956    
1957                    return count.intValue();
1958            }
1959    
1960            /**
1961             * Counts all the d l file ranks where groupId = &#63; and userId = &#63;.
1962             *
1963             * @param groupId the group id to search with
1964             * @param userId the user id to search with
1965             * @return the number of matching d l file ranks
1966             * @throws SystemException if a system exception occurred
1967             */
1968            public int countByG_U(long groupId, long userId) throws SystemException {
1969                    Object[] finderArgs = new Object[] { groupId, userId };
1970    
1971                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1972                                    finderArgs, this);
1973    
1974                    if (count == null) {
1975                            Session session = null;
1976    
1977                            try {
1978                                    session = openSession();
1979    
1980                                    StringBundler query = new StringBundler(3);
1981    
1982                                    query.append(_SQL_COUNT_DLFILERANK_WHERE);
1983    
1984                                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1985    
1986                                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1987    
1988                                    String sql = query.toString();
1989    
1990                                    Query q = session.createQuery(sql);
1991    
1992                                    QueryPos qPos = QueryPos.getInstance(q);
1993    
1994                                    qPos.add(groupId);
1995    
1996                                    qPos.add(userId);
1997    
1998                                    count = (Long)q.uniqueResult();
1999                            }
2000                            catch (Exception e) {
2001                                    throw processException(e);
2002                            }
2003                            finally {
2004                                    if (count == null) {
2005                                            count = Long.valueOf(0);
2006                                    }
2007    
2008                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2009                                            count);
2010    
2011                                    closeSession(session);
2012                            }
2013                    }
2014    
2015                    return count.intValue();
2016            }
2017    
2018            /**
2019             * Counts all the d l file ranks where folderId = &#63; and name = &#63;.
2020             *
2021             * @param folderId the folder id to search with
2022             * @param name the name to search with
2023             * @return the number of matching d l file ranks
2024             * @throws SystemException if a system exception occurred
2025             */
2026            public int countByF_N(long folderId, String name) throws SystemException {
2027                    Object[] finderArgs = new Object[] { folderId, name };
2028    
2029                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_F_N,
2030                                    finderArgs, this);
2031    
2032                    if (count == null) {
2033                            Session session = null;
2034    
2035                            try {
2036                                    session = openSession();
2037    
2038                                    StringBundler query = new StringBundler(3);
2039    
2040                                    query.append(_SQL_COUNT_DLFILERANK_WHERE);
2041    
2042                                    query.append(_FINDER_COLUMN_F_N_FOLDERID_2);
2043    
2044                                    if (name == null) {
2045                                            query.append(_FINDER_COLUMN_F_N_NAME_1);
2046                                    }
2047                                    else {
2048                                            if (name.equals(StringPool.BLANK)) {
2049                                                    query.append(_FINDER_COLUMN_F_N_NAME_3);
2050                                            }
2051                                            else {
2052                                                    query.append(_FINDER_COLUMN_F_N_NAME_2);
2053                                            }
2054                                    }
2055    
2056                                    String sql = query.toString();
2057    
2058                                    Query q = session.createQuery(sql);
2059    
2060                                    QueryPos qPos = QueryPos.getInstance(q);
2061    
2062                                    qPos.add(folderId);
2063    
2064                                    if (name != null) {
2065                                            qPos.add(name);
2066                                    }
2067    
2068                                    count = (Long)q.uniqueResult();
2069                            }
2070                            catch (Exception e) {
2071                                    throw processException(e);
2072                            }
2073                            finally {
2074                                    if (count == null) {
2075                                            count = Long.valueOf(0);
2076                                    }
2077    
2078                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_N, finderArgs,
2079                                            count);
2080    
2081                                    closeSession(session);
2082                            }
2083                    }
2084    
2085                    return count.intValue();
2086            }
2087    
2088            /**
2089             * Counts all the d l file ranks where companyId = &#63; and userId = &#63; and folderId = &#63; and name = &#63;.
2090             *
2091             * @param companyId the company id to search with
2092             * @param userId the user id to search with
2093             * @param folderId the folder id to search with
2094             * @param name the name to search with
2095             * @return the number of matching d l file ranks
2096             * @throws SystemException if a system exception occurred
2097             */
2098            public int countByC_U_F_N(long companyId, long userId, long folderId,
2099                    String name) throws SystemException {
2100                    Object[] finderArgs = new Object[] { companyId, userId, folderId, name };
2101    
2102                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_U_F_N,
2103                                    finderArgs, this);
2104    
2105                    if (count == null) {
2106                            Session session = null;
2107    
2108                            try {
2109                                    session = openSession();
2110    
2111                                    StringBundler query = new StringBundler(5);
2112    
2113                                    query.append(_SQL_COUNT_DLFILERANK_WHERE);
2114    
2115                                    query.append(_FINDER_COLUMN_C_U_F_N_COMPANYID_2);
2116    
2117                                    query.append(_FINDER_COLUMN_C_U_F_N_USERID_2);
2118    
2119                                    query.append(_FINDER_COLUMN_C_U_F_N_FOLDERID_2);
2120    
2121                                    if (name == null) {
2122                                            query.append(_FINDER_COLUMN_C_U_F_N_NAME_1);
2123                                    }
2124                                    else {
2125                                            if (name.equals(StringPool.BLANK)) {
2126                                                    query.append(_FINDER_COLUMN_C_U_F_N_NAME_3);
2127                                            }
2128                                            else {
2129                                                    query.append(_FINDER_COLUMN_C_U_F_N_NAME_2);
2130                                            }
2131                                    }
2132    
2133                                    String sql = query.toString();
2134    
2135                                    Query q = session.createQuery(sql);
2136    
2137                                    QueryPos qPos = QueryPos.getInstance(q);
2138    
2139                                    qPos.add(companyId);
2140    
2141                                    qPos.add(userId);
2142    
2143                                    qPos.add(folderId);
2144    
2145                                    if (name != null) {
2146                                            qPos.add(name);
2147                                    }
2148    
2149                                    count = (Long)q.uniqueResult();
2150                            }
2151                            catch (Exception e) {
2152                                    throw processException(e);
2153                            }
2154                            finally {
2155                                    if (count == null) {
2156                                            count = Long.valueOf(0);
2157                                    }
2158    
2159                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F_N,
2160                                            finderArgs, count);
2161    
2162                                    closeSession(session);
2163                            }
2164                    }
2165    
2166                    return count.intValue();
2167            }
2168    
2169            /**
2170             * Counts all the d l file ranks.
2171             *
2172             * @return the number of d l file ranks
2173             * @throws SystemException if a system exception occurred
2174             */
2175            public int countAll() throws SystemException {
2176                    Object[] finderArgs = new Object[0];
2177    
2178                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2179                                    finderArgs, this);
2180    
2181                    if (count == null) {
2182                            Session session = null;
2183    
2184                            try {
2185                                    session = openSession();
2186    
2187                                    Query q = session.createQuery(_SQL_COUNT_DLFILERANK);
2188    
2189                                    count = (Long)q.uniqueResult();
2190                            }
2191                            catch (Exception e) {
2192                                    throw processException(e);
2193                            }
2194                            finally {
2195                                    if (count == null) {
2196                                            count = Long.valueOf(0);
2197                                    }
2198    
2199                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2200                                            count);
2201    
2202                                    closeSession(session);
2203                            }
2204                    }
2205    
2206                    return count.intValue();
2207            }
2208    
2209            /**
2210             * Initializes the d l file rank persistence.
2211             */
2212            public void afterPropertiesSet() {
2213                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2214                                            com.liferay.portal.util.PropsUtil.get(
2215                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileRank")));
2216    
2217                    if (listenerClassNames.length > 0) {
2218                            try {
2219                                    List<ModelListener<DLFileRank>> listenersList = new ArrayList<ModelListener<DLFileRank>>();
2220    
2221                                    for (String listenerClassName : listenerClassNames) {
2222                                            listenersList.add((ModelListener<DLFileRank>)InstanceFactory.newInstance(
2223                                                            listenerClassName));
2224                                    }
2225    
2226                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2227                            }
2228                            catch (Exception e) {
2229                                    _log.error(e);
2230                            }
2231                    }
2232            }
2233    
2234            public void destroy() {
2235                    EntityCacheUtil.removeCache(DLFileRankImpl.class.getName());
2236                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2237                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2238            }
2239    
2240            @BeanReference(type = DLFileEntryPersistence.class)
2241            protected DLFileEntryPersistence dlFileEntryPersistence;
2242            @BeanReference(type = DLFileRankPersistence.class)
2243            protected DLFileRankPersistence dlFileRankPersistence;
2244            @BeanReference(type = DLFileShortcutPersistence.class)
2245            protected DLFileShortcutPersistence dlFileShortcutPersistence;
2246            @BeanReference(type = DLFileVersionPersistence.class)
2247            protected DLFileVersionPersistence dlFileVersionPersistence;
2248            @BeanReference(type = DLFolderPersistence.class)
2249            protected DLFolderPersistence dlFolderPersistence;
2250            @BeanReference(type = LayoutPersistence.class)
2251            protected LayoutPersistence layoutPersistence;
2252            @BeanReference(type = ResourcePersistence.class)
2253            protected ResourcePersistence resourcePersistence;
2254            @BeanReference(type = UserPersistence.class)
2255            protected UserPersistence userPersistence;
2256            private static final String _SQL_SELECT_DLFILERANK = "SELECT dlFileRank FROM DLFileRank dlFileRank";
2257            private static final String _SQL_SELECT_DLFILERANK_WHERE = "SELECT dlFileRank FROM DLFileRank dlFileRank WHERE ";
2258            private static final String _SQL_COUNT_DLFILERANK = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank";
2259            private static final String _SQL_COUNT_DLFILERANK_WHERE = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank WHERE ";
2260            private static final String _FINDER_COLUMN_USERID_USERID_2 = "dlFileRank.userId = ?";
2261            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "dlFileRank.groupId = ? AND ";
2262            private static final String _FINDER_COLUMN_G_U_USERID_2 = "dlFileRank.userId = ?";
2263            private static final String _FINDER_COLUMN_F_N_FOLDERID_2 = "dlFileRank.folderId = ? AND ";
2264            private static final String _FINDER_COLUMN_F_N_NAME_1 = "dlFileRank.name IS NULL";
2265            private static final String _FINDER_COLUMN_F_N_NAME_2 = "dlFileRank.name = ?";
2266            private static final String _FINDER_COLUMN_F_N_NAME_3 = "(dlFileRank.name IS NULL OR dlFileRank.name = ?)";
2267            private static final String _FINDER_COLUMN_C_U_F_N_COMPANYID_2 = "dlFileRank.companyId = ? AND ";
2268            private static final String _FINDER_COLUMN_C_U_F_N_USERID_2 = "dlFileRank.userId = ? AND ";
2269            private static final String _FINDER_COLUMN_C_U_F_N_FOLDERID_2 = "dlFileRank.folderId = ? AND ";
2270            private static final String _FINDER_COLUMN_C_U_F_N_NAME_1 = "dlFileRank.name IS NULL";
2271            private static final String _FINDER_COLUMN_C_U_F_N_NAME_2 = "dlFileRank.name = ?";
2272            private static final String _FINDER_COLUMN_C_U_F_N_NAME_3 = "(dlFileRank.name IS NULL OR dlFileRank.name = ?)";
2273            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileRank.";
2274            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileRank exists with the primary key ";
2275            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileRank exists with the key {";
2276            private static Log _log = LogFactoryUtil.getLog(DLFileRankPersistenceImpl.class);
2277    }