001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.OrderByComparator;
029    import com.liferay.portal.kernel.util.SetUtil;
030    import com.liferay.portal.kernel.util.StringBundler;
031    import com.liferay.portal.kernel.util.StringPool;
032    import com.liferay.portal.kernel.util.StringUtil;
033    import com.liferay.portal.model.CacheModel;
034    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
035    
036    import com.liferay.portlet.documentlibrary.NoSuchFileRankException;
037    import com.liferay.portlet.documentlibrary.model.DLFileRank;
038    import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
039    import com.liferay.portlet.documentlibrary.model.impl.DLFileRankModelImpl;
040    import com.liferay.portlet.documentlibrary.service.persistence.DLFileRankPersistence;
041    
042    import java.io.Serializable;
043    
044    import java.util.Collections;
045    import java.util.HashMap;
046    import java.util.HashSet;
047    import java.util.Iterator;
048    import java.util.List;
049    import java.util.Map;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the document library file rank service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see DLFileRankPersistence
061     * @see com.liferay.portlet.documentlibrary.service.persistence.DLFileRankUtil
062     * @generated
063     */
064    @ProviderType
065    public class DLFileRankPersistenceImpl extends BasePersistenceImpl<DLFileRank>
066            implements DLFileRankPersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * Never modify or reference this class directly. Always use {@link DLFileRankUtil} to access the document library file rank persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = DLFileRankImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
078                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
081                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
084                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
087                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
089                            new String[] {
090                                    Long.class.getName(),
091                                    
092                            Integer.class.getName(), Integer.class.getName(),
093                                    OrderByComparator.class.getName()
094                            });
095            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
096                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
097                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
099                            new String[] { Long.class.getName() },
100                            DLFileRankModelImpl.USERID_COLUMN_BITMASK |
101                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
103                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
105                            new String[] { Long.class.getName() });
106    
107            /**
108             * Returns all the document library file ranks where userId = &#63;.
109             *
110             * @param userId the user ID
111             * @return the matching document library file ranks
112             */
113            @Override
114            public List<DLFileRank> findByUserId(long userId) {
115                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116            }
117    
118            /**
119             * Returns a range of all the document library file ranks where userId = &#63;.
120             *
121             * <p>
122             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
123             * </p>
124             *
125             * @param userId the user ID
126             * @param start the lower bound of the range of document library file ranks
127             * @param end the upper bound of the range of document library file ranks (not inclusive)
128             * @return the range of matching document library file ranks
129             */
130            @Override
131            public List<DLFileRank> findByUserId(long userId, int start, int end) {
132                    return findByUserId(userId, start, end, null);
133            }
134    
135            /**
136             * Returns an ordered range of all the document library file ranks where userId = &#63;.
137             *
138             * <p>
139             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
140             * </p>
141             *
142             * @param userId the user ID
143             * @param start the lower bound of the range of document library file ranks
144             * @param end the upper bound of the range of document library file ranks (not inclusive)
145             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
146             * @return the ordered range of matching document library file ranks
147             */
148            @Override
149            public List<DLFileRank> findByUserId(long userId, int start, int end,
150                    OrderByComparator<DLFileRank> orderByComparator) {
151                    boolean pagination = true;
152                    FinderPath finderPath = null;
153                    Object[] finderArgs = null;
154    
155                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156                                    (orderByComparator == null)) {
157                            pagination = false;
158                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
159                            finderArgs = new Object[] { userId };
160                    }
161                    else {
162                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
163                            finderArgs = new Object[] { userId, start, end, orderByComparator };
164                    }
165    
166                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
167                                    finderArgs, this);
168    
169                    if ((list != null) && !list.isEmpty()) {
170                            for (DLFileRank dlFileRank : list) {
171                                    if ((userId != dlFileRank.getUserId())) {
172                                            list = null;
173    
174                                            break;
175                                    }
176                            }
177                    }
178    
179                    if (list == null) {
180                            StringBundler query = null;
181    
182                            if (orderByComparator != null) {
183                                    query = new StringBundler(3 +
184                                                    (orderByComparator.getOrderByFields().length * 3));
185                            }
186                            else {
187                                    query = new StringBundler(3);
188                            }
189    
190                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
191    
192                            query.append(_FINDER_COLUMN_USERID_USERID_2);
193    
194                            if (orderByComparator != null) {
195                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
196                                            orderByComparator);
197                            }
198                            else
199                             if (pagination) {
200                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
201                            }
202    
203                            String sql = query.toString();
204    
205                            Session session = null;
206    
207                            try {
208                                    session = openSession();
209    
210                                    Query q = session.createQuery(sql);
211    
212                                    QueryPos qPos = QueryPos.getInstance(q);
213    
214                                    qPos.add(userId);
215    
216                                    if (!pagination) {
217                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
218                                                            start, end, false);
219    
220                                            Collections.sort(list);
221    
222                                            list = Collections.unmodifiableList(list);
223                                    }
224                                    else {
225                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
226                                                            start, end);
227                                    }
228    
229                                    cacheResult(list);
230    
231                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
232                            }
233                            catch (Exception e) {
234                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
235    
236                                    throw processException(e);
237                            }
238                            finally {
239                                    closeSession(session);
240                            }
241                    }
242    
243                    return list;
244            }
245    
246            /**
247             * Returns the first document library file rank in the ordered set where userId = &#63;.
248             *
249             * @param userId the user ID
250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
251             * @return the first matching document library file rank
252             * @throws NoSuchFileRankException if a matching document library file rank could not be found
253             */
254            @Override
255            public DLFileRank findByUserId_First(long userId,
256                    OrderByComparator<DLFileRank> orderByComparator)
257                    throws NoSuchFileRankException {
258                    DLFileRank dlFileRank = fetchByUserId_First(userId, orderByComparator);
259    
260                    if (dlFileRank != null) {
261                            return dlFileRank;
262                    }
263    
264                    StringBundler msg = new StringBundler(4);
265    
266                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
267    
268                    msg.append("userId=");
269                    msg.append(userId);
270    
271                    msg.append(StringPool.CLOSE_CURLY_BRACE);
272    
273                    throw new NoSuchFileRankException(msg.toString());
274            }
275    
276            /**
277             * Returns the first document library file rank in the ordered set where userId = &#63;.
278             *
279             * @param userId the user ID
280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
281             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
282             */
283            @Override
284            public DLFileRank fetchByUserId_First(long userId,
285                    OrderByComparator<DLFileRank> orderByComparator) {
286                    List<DLFileRank> list = findByUserId(userId, 0, 1, orderByComparator);
287    
288                    if (!list.isEmpty()) {
289                            return list.get(0);
290                    }
291    
292                    return null;
293            }
294    
295            /**
296             * Returns the last document library file rank in the ordered set where userId = &#63;.
297             *
298             * @param userId the user ID
299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
300             * @return the last matching document library file rank
301             * @throws NoSuchFileRankException if a matching document library file rank could not be found
302             */
303            @Override
304            public DLFileRank findByUserId_Last(long userId,
305                    OrderByComparator<DLFileRank> orderByComparator)
306                    throws NoSuchFileRankException {
307                    DLFileRank dlFileRank = fetchByUserId_Last(userId, orderByComparator);
308    
309                    if (dlFileRank != null) {
310                            return dlFileRank;
311                    }
312    
313                    StringBundler msg = new StringBundler(4);
314    
315                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
316    
317                    msg.append("userId=");
318                    msg.append(userId);
319    
320                    msg.append(StringPool.CLOSE_CURLY_BRACE);
321    
322                    throw new NoSuchFileRankException(msg.toString());
323            }
324    
325            /**
326             * Returns the last document library file rank in the ordered set where userId = &#63;.
327             *
328             * @param userId the user ID
329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
330             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
331             */
332            @Override
333            public DLFileRank fetchByUserId_Last(long userId,
334                    OrderByComparator<DLFileRank> orderByComparator) {
335                    int count = countByUserId(userId);
336    
337                    if (count == 0) {
338                            return null;
339                    }
340    
341                    List<DLFileRank> list = findByUserId(userId, count - 1, count,
342                                    orderByComparator);
343    
344                    if (!list.isEmpty()) {
345                            return list.get(0);
346                    }
347    
348                    return null;
349            }
350    
351            /**
352             * Returns the document library file ranks before and after the current document library file rank in the ordered set where userId = &#63;.
353             *
354             * @param fileRankId the primary key of the current document library file rank
355             * @param userId the user ID
356             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
357             * @return the previous, current, and next document library file rank
358             * @throws NoSuchFileRankException if a document library file rank with the primary key could not be found
359             */
360            @Override
361            public DLFileRank[] findByUserId_PrevAndNext(long fileRankId, long userId,
362                    OrderByComparator<DLFileRank> orderByComparator)
363                    throws NoSuchFileRankException {
364                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
365    
366                    Session session = null;
367    
368                    try {
369                            session = openSession();
370    
371                            DLFileRank[] array = new DLFileRankImpl[3];
372    
373                            array[0] = getByUserId_PrevAndNext(session, dlFileRank, userId,
374                                            orderByComparator, true);
375    
376                            array[1] = dlFileRank;
377    
378                            array[2] = getByUserId_PrevAndNext(session, dlFileRank, userId,
379                                            orderByComparator, false);
380    
381                            return array;
382                    }
383                    catch (Exception e) {
384                            throw processException(e);
385                    }
386                    finally {
387                            closeSession(session);
388                    }
389            }
390    
391            protected DLFileRank getByUserId_PrevAndNext(Session session,
392                    DLFileRank dlFileRank, long userId,
393                    OrderByComparator<DLFileRank> orderByComparator, boolean previous) {
394                    StringBundler query = null;
395    
396                    if (orderByComparator != null) {
397                            query = new StringBundler(6 +
398                                            (orderByComparator.getOrderByFields().length * 6));
399                    }
400                    else {
401                            query = new StringBundler(3);
402                    }
403    
404                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
405    
406                    query.append(_FINDER_COLUMN_USERID_USERID_2);
407    
408                    if (orderByComparator != null) {
409                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
410    
411                            if (orderByConditionFields.length > 0) {
412                                    query.append(WHERE_AND);
413                            }
414    
415                            for (int i = 0; i < orderByConditionFields.length; i++) {
416                                    query.append(_ORDER_BY_ENTITY_ALIAS);
417                                    query.append(orderByConditionFields[i]);
418    
419                                    if ((i + 1) < orderByConditionFields.length) {
420                                            if (orderByComparator.isAscending() ^ previous) {
421                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
422                                            }
423                                            else {
424                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
425                                            }
426                                    }
427                                    else {
428                                            if (orderByComparator.isAscending() ^ previous) {
429                                                    query.append(WHERE_GREATER_THAN);
430                                            }
431                                            else {
432                                                    query.append(WHERE_LESSER_THAN);
433                                            }
434                                    }
435                            }
436    
437                            query.append(ORDER_BY_CLAUSE);
438    
439                            String[] orderByFields = orderByComparator.getOrderByFields();
440    
441                            for (int i = 0; i < orderByFields.length; i++) {
442                                    query.append(_ORDER_BY_ENTITY_ALIAS);
443                                    query.append(orderByFields[i]);
444    
445                                    if ((i + 1) < orderByFields.length) {
446                                            if (orderByComparator.isAscending() ^ previous) {
447                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
448                                            }
449                                            else {
450                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
451                                            }
452                                    }
453                                    else {
454                                            if (orderByComparator.isAscending() ^ previous) {
455                                                    query.append(ORDER_BY_ASC);
456                                            }
457                                            else {
458                                                    query.append(ORDER_BY_DESC);
459                                            }
460                                    }
461                            }
462                    }
463                    else {
464                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
465                    }
466    
467                    String sql = query.toString();
468    
469                    Query q = session.createQuery(sql);
470    
471                    q.setFirstResult(0);
472                    q.setMaxResults(2);
473    
474                    QueryPos qPos = QueryPos.getInstance(q);
475    
476                    qPos.add(userId);
477    
478                    if (orderByComparator != null) {
479                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
480    
481                            for (Object value : values) {
482                                    qPos.add(value);
483                            }
484                    }
485    
486                    List<DLFileRank> list = q.list();
487    
488                    if (list.size() == 2) {
489                            return list.get(1);
490                    }
491                    else {
492                            return null;
493                    }
494            }
495    
496            /**
497             * Removes all the document library file ranks where userId = &#63; from the database.
498             *
499             * @param userId the user ID
500             */
501            @Override
502            public void removeByUserId(long userId) {
503                    for (DLFileRank dlFileRank : findByUserId(userId, QueryUtil.ALL_POS,
504                                    QueryUtil.ALL_POS, null)) {
505                            remove(dlFileRank);
506                    }
507            }
508    
509            /**
510             * Returns the number of document library file ranks where userId = &#63;.
511             *
512             * @param userId the user ID
513             * @return the number of matching document library file ranks
514             */
515            @Override
516            public int countByUserId(long userId) {
517                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
518    
519                    Object[] finderArgs = new Object[] { userId };
520    
521                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
522                                    this);
523    
524                    if (count == null) {
525                            StringBundler query = new StringBundler(2);
526    
527                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
528    
529                            query.append(_FINDER_COLUMN_USERID_USERID_2);
530    
531                            String sql = query.toString();
532    
533                            Session session = null;
534    
535                            try {
536                                    session = openSession();
537    
538                                    Query q = session.createQuery(sql);
539    
540                                    QueryPos qPos = QueryPos.getInstance(q);
541    
542                                    qPos.add(userId);
543    
544                                    count = (Long)q.uniqueResult();
545    
546                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
547                            }
548                            catch (Exception e) {
549                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
550    
551                                    throw processException(e);
552                            }
553                            finally {
554                                    closeSession(session);
555                            }
556                    }
557    
558                    return count.intValue();
559            }
560    
561            private static final String _FINDER_COLUMN_USERID_USERID_2 = "dlFileRank.userId = ?";
562            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID =
563                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
564                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
565                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFileEntryId",
566                            new String[] {
567                                    Long.class.getName(),
568                                    
569                            Integer.class.getName(), Integer.class.getName(),
570                                    OrderByComparator.class.getName()
571                            });
572            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID =
573                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
574                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
575                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFileEntryId",
576                            new String[] { Long.class.getName() },
577                            DLFileRankModelImpl.FILEENTRYID_COLUMN_BITMASK |
578                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
579            public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
580                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
581                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileEntryId",
582                            new String[] { Long.class.getName() });
583    
584            /**
585             * Returns all the document library file ranks where fileEntryId = &#63;.
586             *
587             * @param fileEntryId the file entry ID
588             * @return the matching document library file ranks
589             */
590            @Override
591            public List<DLFileRank> findByFileEntryId(long fileEntryId) {
592                    return findByFileEntryId(fileEntryId, QueryUtil.ALL_POS,
593                            QueryUtil.ALL_POS, null);
594            }
595    
596            /**
597             * Returns a range of all the document library file ranks where fileEntryId = &#63;.
598             *
599             * <p>
600             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
601             * </p>
602             *
603             * @param fileEntryId the file entry ID
604             * @param start the lower bound of the range of document library file ranks
605             * @param end the upper bound of the range of document library file ranks (not inclusive)
606             * @return the range of matching document library file ranks
607             */
608            @Override
609            public List<DLFileRank> findByFileEntryId(long fileEntryId, int start,
610                    int end) {
611                    return findByFileEntryId(fileEntryId, start, end, null);
612            }
613    
614            /**
615             * Returns an ordered range of all the document library file ranks where fileEntryId = &#63;.
616             *
617             * <p>
618             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
619             * </p>
620             *
621             * @param fileEntryId the file entry ID
622             * @param start the lower bound of the range of document library file ranks
623             * @param end the upper bound of the range of document library file ranks (not inclusive)
624             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
625             * @return the ordered range of matching document library file ranks
626             */
627            @Override
628            public List<DLFileRank> findByFileEntryId(long fileEntryId, int start,
629                    int end, OrderByComparator<DLFileRank> orderByComparator) {
630                    boolean pagination = true;
631                    FinderPath finderPath = null;
632                    Object[] finderArgs = null;
633    
634                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
635                                    (orderByComparator == null)) {
636                            pagination = false;
637                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID;
638                            finderArgs = new Object[] { fileEntryId };
639                    }
640                    else {
641                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID;
642                            finderArgs = new Object[] { fileEntryId, start, end, orderByComparator };
643                    }
644    
645                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
646                                    finderArgs, this);
647    
648                    if ((list != null) && !list.isEmpty()) {
649                            for (DLFileRank dlFileRank : list) {
650                                    if ((fileEntryId != dlFileRank.getFileEntryId())) {
651                                            list = null;
652    
653                                            break;
654                                    }
655                            }
656                    }
657    
658                    if (list == null) {
659                            StringBundler query = null;
660    
661                            if (orderByComparator != null) {
662                                    query = new StringBundler(3 +
663                                                    (orderByComparator.getOrderByFields().length * 3));
664                            }
665                            else {
666                                    query = new StringBundler(3);
667                            }
668    
669                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
670    
671                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
672    
673                            if (orderByComparator != null) {
674                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
675                                            orderByComparator);
676                            }
677                            else
678                             if (pagination) {
679                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
680                            }
681    
682                            String sql = query.toString();
683    
684                            Session session = null;
685    
686                            try {
687                                    session = openSession();
688    
689                                    Query q = session.createQuery(sql);
690    
691                                    QueryPos qPos = QueryPos.getInstance(q);
692    
693                                    qPos.add(fileEntryId);
694    
695                                    if (!pagination) {
696                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
697                                                            start, end, false);
698    
699                                            Collections.sort(list);
700    
701                                            list = Collections.unmodifiableList(list);
702                                    }
703                                    else {
704                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
705                                                            start, end);
706                                    }
707    
708                                    cacheResult(list);
709    
710                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
711                            }
712                            catch (Exception e) {
713                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
714    
715                                    throw processException(e);
716                            }
717                            finally {
718                                    closeSession(session);
719                            }
720                    }
721    
722                    return list;
723            }
724    
725            /**
726             * Returns the first document library file rank in the ordered set where fileEntryId = &#63;.
727             *
728             * @param fileEntryId the file entry ID
729             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
730             * @return the first matching document library file rank
731             * @throws NoSuchFileRankException if a matching document library file rank could not be found
732             */
733            @Override
734            public DLFileRank findByFileEntryId_First(long fileEntryId,
735                    OrderByComparator<DLFileRank> orderByComparator)
736                    throws NoSuchFileRankException {
737                    DLFileRank dlFileRank = fetchByFileEntryId_First(fileEntryId,
738                                    orderByComparator);
739    
740                    if (dlFileRank != null) {
741                            return dlFileRank;
742                    }
743    
744                    StringBundler msg = new StringBundler(4);
745    
746                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
747    
748                    msg.append("fileEntryId=");
749                    msg.append(fileEntryId);
750    
751                    msg.append(StringPool.CLOSE_CURLY_BRACE);
752    
753                    throw new NoSuchFileRankException(msg.toString());
754            }
755    
756            /**
757             * Returns the first document library file rank in the ordered set where fileEntryId = &#63;.
758             *
759             * @param fileEntryId the file entry ID
760             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
761             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
762             */
763            @Override
764            public DLFileRank fetchByFileEntryId_First(long fileEntryId,
765                    OrderByComparator<DLFileRank> orderByComparator) {
766                    List<DLFileRank> list = findByFileEntryId(fileEntryId, 0, 1,
767                                    orderByComparator);
768    
769                    if (!list.isEmpty()) {
770                            return list.get(0);
771                    }
772    
773                    return null;
774            }
775    
776            /**
777             * Returns the last document library file rank in the ordered set where fileEntryId = &#63;.
778             *
779             * @param fileEntryId the file entry ID
780             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
781             * @return the last matching document library file rank
782             * @throws NoSuchFileRankException if a matching document library file rank could not be found
783             */
784            @Override
785            public DLFileRank findByFileEntryId_Last(long fileEntryId,
786                    OrderByComparator<DLFileRank> orderByComparator)
787                    throws NoSuchFileRankException {
788                    DLFileRank dlFileRank = fetchByFileEntryId_Last(fileEntryId,
789                                    orderByComparator);
790    
791                    if (dlFileRank != null) {
792                            return dlFileRank;
793                    }
794    
795                    StringBundler msg = new StringBundler(4);
796    
797                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
798    
799                    msg.append("fileEntryId=");
800                    msg.append(fileEntryId);
801    
802                    msg.append(StringPool.CLOSE_CURLY_BRACE);
803    
804                    throw new NoSuchFileRankException(msg.toString());
805            }
806    
807            /**
808             * Returns the last document library file rank in the ordered set where fileEntryId = &#63;.
809             *
810             * @param fileEntryId the file entry ID
811             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
812             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
813             */
814            @Override
815            public DLFileRank fetchByFileEntryId_Last(long fileEntryId,
816                    OrderByComparator<DLFileRank> orderByComparator) {
817                    int count = countByFileEntryId(fileEntryId);
818    
819                    if (count == 0) {
820                            return null;
821                    }
822    
823                    List<DLFileRank> list = findByFileEntryId(fileEntryId, count - 1,
824                                    count, orderByComparator);
825    
826                    if (!list.isEmpty()) {
827                            return list.get(0);
828                    }
829    
830                    return null;
831            }
832    
833            /**
834             * Returns the document library file ranks before and after the current document library file rank in the ordered set where fileEntryId = &#63;.
835             *
836             * @param fileRankId the primary key of the current document library file rank
837             * @param fileEntryId the file entry ID
838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
839             * @return the previous, current, and next document library file rank
840             * @throws NoSuchFileRankException if a document library file rank with the primary key could not be found
841             */
842            @Override
843            public DLFileRank[] findByFileEntryId_PrevAndNext(long fileRankId,
844                    long fileEntryId, OrderByComparator<DLFileRank> orderByComparator)
845                    throws NoSuchFileRankException {
846                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
847    
848                    Session session = null;
849    
850                    try {
851                            session = openSession();
852    
853                            DLFileRank[] array = new DLFileRankImpl[3];
854    
855                            array[0] = getByFileEntryId_PrevAndNext(session, dlFileRank,
856                                            fileEntryId, orderByComparator, true);
857    
858                            array[1] = dlFileRank;
859    
860                            array[2] = getByFileEntryId_PrevAndNext(session, dlFileRank,
861                                            fileEntryId, orderByComparator, false);
862    
863                            return array;
864                    }
865                    catch (Exception e) {
866                            throw processException(e);
867                    }
868                    finally {
869                            closeSession(session);
870                    }
871            }
872    
873            protected DLFileRank getByFileEntryId_PrevAndNext(Session session,
874                    DLFileRank dlFileRank, long fileEntryId,
875                    OrderByComparator<DLFileRank> orderByComparator, boolean previous) {
876                    StringBundler query = null;
877    
878                    if (orderByComparator != null) {
879                            query = new StringBundler(6 +
880                                            (orderByComparator.getOrderByFields().length * 6));
881                    }
882                    else {
883                            query = new StringBundler(3);
884                    }
885    
886                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
887    
888                    query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
889    
890                    if (orderByComparator != null) {
891                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
892    
893                            if (orderByConditionFields.length > 0) {
894                                    query.append(WHERE_AND);
895                            }
896    
897                            for (int i = 0; i < orderByConditionFields.length; i++) {
898                                    query.append(_ORDER_BY_ENTITY_ALIAS);
899                                    query.append(orderByConditionFields[i]);
900    
901                                    if ((i + 1) < orderByConditionFields.length) {
902                                            if (orderByComparator.isAscending() ^ previous) {
903                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
904                                            }
905                                            else {
906                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
907                                            }
908                                    }
909                                    else {
910                                            if (orderByComparator.isAscending() ^ previous) {
911                                                    query.append(WHERE_GREATER_THAN);
912                                            }
913                                            else {
914                                                    query.append(WHERE_LESSER_THAN);
915                                            }
916                                    }
917                            }
918    
919                            query.append(ORDER_BY_CLAUSE);
920    
921                            String[] orderByFields = orderByComparator.getOrderByFields();
922    
923                            for (int i = 0; i < orderByFields.length; i++) {
924                                    query.append(_ORDER_BY_ENTITY_ALIAS);
925                                    query.append(orderByFields[i]);
926    
927                                    if ((i + 1) < orderByFields.length) {
928                                            if (orderByComparator.isAscending() ^ previous) {
929                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
930                                            }
931                                            else {
932                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
933                                            }
934                                    }
935                                    else {
936                                            if (orderByComparator.isAscending() ^ previous) {
937                                                    query.append(ORDER_BY_ASC);
938                                            }
939                                            else {
940                                                    query.append(ORDER_BY_DESC);
941                                            }
942                                    }
943                            }
944                    }
945                    else {
946                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
947                    }
948    
949                    String sql = query.toString();
950    
951                    Query q = session.createQuery(sql);
952    
953                    q.setFirstResult(0);
954                    q.setMaxResults(2);
955    
956                    QueryPos qPos = QueryPos.getInstance(q);
957    
958                    qPos.add(fileEntryId);
959    
960                    if (orderByComparator != null) {
961                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
962    
963                            for (Object value : values) {
964                                    qPos.add(value);
965                            }
966                    }
967    
968                    List<DLFileRank> list = q.list();
969    
970                    if (list.size() == 2) {
971                            return list.get(1);
972                    }
973                    else {
974                            return null;
975                    }
976            }
977    
978            /**
979             * Removes all the document library file ranks where fileEntryId = &#63; from the database.
980             *
981             * @param fileEntryId the file entry ID
982             */
983            @Override
984            public void removeByFileEntryId(long fileEntryId) {
985                    for (DLFileRank dlFileRank : findByFileEntryId(fileEntryId,
986                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
987                            remove(dlFileRank);
988                    }
989            }
990    
991            /**
992             * Returns the number of document library file ranks where fileEntryId = &#63;.
993             *
994             * @param fileEntryId the file entry ID
995             * @return the number of matching document library file ranks
996             */
997            @Override
998            public int countByFileEntryId(long fileEntryId) {
999                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEENTRYID;
1000    
1001                    Object[] finderArgs = new Object[] { fileEntryId };
1002    
1003                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1004                                    this);
1005    
1006                    if (count == null) {
1007                            StringBundler query = new StringBundler(2);
1008    
1009                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
1010    
1011                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1012    
1013                            String sql = query.toString();
1014    
1015                            Session session = null;
1016    
1017                            try {
1018                                    session = openSession();
1019    
1020                                    Query q = session.createQuery(sql);
1021    
1022                                    QueryPos qPos = QueryPos.getInstance(q);
1023    
1024                                    qPos.add(fileEntryId);
1025    
1026                                    count = (Long)q.uniqueResult();
1027    
1028                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1029                            }
1030                            catch (Exception e) {
1031                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1032    
1033                                    throw processException(e);
1034                            }
1035                            finally {
1036                                    closeSession(session);
1037                            }
1038                    }
1039    
1040                    return count.intValue();
1041            }
1042    
1043            private static final String _FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2 = "dlFileRank.fileEntryId = ?";
1044            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1045                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
1046                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
1047                            new String[] {
1048                                    Long.class.getName(), Long.class.getName(),
1049                                    
1050                            Integer.class.getName(), Integer.class.getName(),
1051                                    OrderByComparator.class.getName()
1052                            });
1053            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1054                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
1055                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
1056                            new String[] { Long.class.getName(), Long.class.getName() },
1057                            DLFileRankModelImpl.GROUPID_COLUMN_BITMASK |
1058                            DLFileRankModelImpl.USERID_COLUMN_BITMASK |
1059                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
1060            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1061                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
1062                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
1063                            new String[] { Long.class.getName(), Long.class.getName() });
1064    
1065            /**
1066             * Returns all the document library file ranks where groupId = &#63; and userId = &#63;.
1067             *
1068             * @param groupId the group ID
1069             * @param userId the user ID
1070             * @return the matching document library file ranks
1071             */
1072            @Override
1073            public List<DLFileRank> findByG_U(long groupId, long userId) {
1074                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1075                            null);
1076            }
1077    
1078            /**
1079             * Returns a range of all the document library file ranks where groupId = &#63; and userId = &#63;.
1080             *
1081             * <p>
1082             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1083             * </p>
1084             *
1085             * @param groupId the group ID
1086             * @param userId the user ID
1087             * @param start the lower bound of the range of document library file ranks
1088             * @param end the upper bound of the range of document library file ranks (not inclusive)
1089             * @return the range of matching document library file ranks
1090             */
1091            @Override
1092            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
1093                    int end) {
1094                    return findByG_U(groupId, userId, start, end, null);
1095            }
1096    
1097            /**
1098             * Returns an ordered range of all the document library file ranks where groupId = &#63; and userId = &#63;.
1099             *
1100             * <p>
1101             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1102             * </p>
1103             *
1104             * @param groupId the group ID
1105             * @param userId the user ID
1106             * @param start the lower bound of the range of document library file ranks
1107             * @param end the upper bound of the range of document library file ranks (not inclusive)
1108             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1109             * @return the ordered range of matching document library file ranks
1110             */
1111            @Override
1112            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
1113                    int end, OrderByComparator<DLFileRank> orderByComparator) {
1114                    boolean pagination = true;
1115                    FinderPath finderPath = null;
1116                    Object[] finderArgs = null;
1117    
1118                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1119                                    (orderByComparator == null)) {
1120                            pagination = false;
1121                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
1122                            finderArgs = new Object[] { groupId, userId };
1123                    }
1124                    else {
1125                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
1126                            finderArgs = new Object[] {
1127                                            groupId, userId,
1128                                            
1129                                            start, end, orderByComparator
1130                                    };
1131                    }
1132    
1133                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
1134                                    finderArgs, this);
1135    
1136                    if ((list != null) && !list.isEmpty()) {
1137                            for (DLFileRank dlFileRank : list) {
1138                                    if ((groupId != dlFileRank.getGroupId()) ||
1139                                                    (userId != dlFileRank.getUserId())) {
1140                                            list = null;
1141    
1142                                            break;
1143                                    }
1144                            }
1145                    }
1146    
1147                    if (list == null) {
1148                            StringBundler query = null;
1149    
1150                            if (orderByComparator != null) {
1151                                    query = new StringBundler(4 +
1152                                                    (orderByComparator.getOrderByFields().length * 3));
1153                            }
1154                            else {
1155                                    query = new StringBundler(4);
1156                            }
1157    
1158                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
1159    
1160                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1161    
1162                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1163    
1164                            if (orderByComparator != null) {
1165                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1166                                            orderByComparator);
1167                            }
1168                            else
1169                             if (pagination) {
1170                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1171                            }
1172    
1173                            String sql = query.toString();
1174    
1175                            Session session = null;
1176    
1177                            try {
1178                                    session = openSession();
1179    
1180                                    Query q = session.createQuery(sql);
1181    
1182                                    QueryPos qPos = QueryPos.getInstance(q);
1183    
1184                                    qPos.add(groupId);
1185    
1186                                    qPos.add(userId);
1187    
1188                                    if (!pagination) {
1189                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1190                                                            start, end, false);
1191    
1192                                            Collections.sort(list);
1193    
1194                                            list = Collections.unmodifiableList(list);
1195                                    }
1196                                    else {
1197                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1198                                                            start, end);
1199                                    }
1200    
1201                                    cacheResult(list);
1202    
1203                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1204                            }
1205                            catch (Exception e) {
1206                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1207    
1208                                    throw processException(e);
1209                            }
1210                            finally {
1211                                    closeSession(session);
1212                            }
1213                    }
1214    
1215                    return list;
1216            }
1217    
1218            /**
1219             * Returns the first document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
1220             *
1221             * @param groupId the group ID
1222             * @param userId the user ID
1223             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1224             * @return the first matching document library file rank
1225             * @throws NoSuchFileRankException if a matching document library file rank could not be found
1226             */
1227            @Override
1228            public DLFileRank findByG_U_First(long groupId, long userId,
1229                    OrderByComparator<DLFileRank> orderByComparator)
1230                    throws NoSuchFileRankException {
1231                    DLFileRank dlFileRank = fetchByG_U_First(groupId, userId,
1232                                    orderByComparator);
1233    
1234                    if (dlFileRank != null) {
1235                            return dlFileRank;
1236                    }
1237    
1238                    StringBundler msg = new StringBundler(6);
1239    
1240                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1241    
1242                    msg.append("groupId=");
1243                    msg.append(groupId);
1244    
1245                    msg.append(", userId=");
1246                    msg.append(userId);
1247    
1248                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1249    
1250                    throw new NoSuchFileRankException(msg.toString());
1251            }
1252    
1253            /**
1254             * Returns the first document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
1255             *
1256             * @param groupId the group ID
1257             * @param userId the user ID
1258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1259             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1260             */
1261            @Override
1262            public DLFileRank fetchByG_U_First(long groupId, long userId,
1263                    OrderByComparator<DLFileRank> orderByComparator) {
1264                    List<DLFileRank> list = findByG_U(groupId, userId, 0, 1,
1265                                    orderByComparator);
1266    
1267                    if (!list.isEmpty()) {
1268                            return list.get(0);
1269                    }
1270    
1271                    return null;
1272            }
1273    
1274            /**
1275             * Returns the last document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
1276             *
1277             * @param groupId the group ID
1278             * @param userId the user ID
1279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1280             * @return the last matching document library file rank
1281             * @throws NoSuchFileRankException if a matching document library file rank could not be found
1282             */
1283            @Override
1284            public DLFileRank findByG_U_Last(long groupId, long userId,
1285                    OrderByComparator<DLFileRank> orderByComparator)
1286                    throws NoSuchFileRankException {
1287                    DLFileRank dlFileRank = fetchByG_U_Last(groupId, userId,
1288                                    orderByComparator);
1289    
1290                    if (dlFileRank != null) {
1291                            return dlFileRank;
1292                    }
1293    
1294                    StringBundler msg = new StringBundler(6);
1295    
1296                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1297    
1298                    msg.append("groupId=");
1299                    msg.append(groupId);
1300    
1301                    msg.append(", userId=");
1302                    msg.append(userId);
1303    
1304                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1305    
1306                    throw new NoSuchFileRankException(msg.toString());
1307            }
1308    
1309            /**
1310             * Returns the last document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
1311             *
1312             * @param groupId the group ID
1313             * @param userId the user ID
1314             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1315             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1316             */
1317            @Override
1318            public DLFileRank fetchByG_U_Last(long groupId, long userId,
1319                    OrderByComparator<DLFileRank> orderByComparator) {
1320                    int count = countByG_U(groupId, userId);
1321    
1322                    if (count == 0) {
1323                            return null;
1324                    }
1325    
1326                    List<DLFileRank> list = findByG_U(groupId, userId, count - 1, count,
1327                                    orderByComparator);
1328    
1329                    if (!list.isEmpty()) {
1330                            return list.get(0);
1331                    }
1332    
1333                    return null;
1334            }
1335    
1336            /**
1337             * Returns the document library file ranks before and after the current document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
1338             *
1339             * @param fileRankId the primary key of the current document library file rank
1340             * @param groupId the group ID
1341             * @param userId the user ID
1342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1343             * @return the previous, current, and next document library file rank
1344             * @throws NoSuchFileRankException if a document library file rank with the primary key could not be found
1345             */
1346            @Override
1347            public DLFileRank[] findByG_U_PrevAndNext(long fileRankId, long groupId,
1348                    long userId, OrderByComparator<DLFileRank> orderByComparator)
1349                    throws NoSuchFileRankException {
1350                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1351    
1352                    Session session = null;
1353    
1354                    try {
1355                            session = openSession();
1356    
1357                            DLFileRank[] array = new DLFileRankImpl[3];
1358    
1359                            array[0] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1360                                            userId, orderByComparator, true);
1361    
1362                            array[1] = dlFileRank;
1363    
1364                            array[2] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1365                                            userId, orderByComparator, false);
1366    
1367                            return array;
1368                    }
1369                    catch (Exception e) {
1370                            throw processException(e);
1371                    }
1372                    finally {
1373                            closeSession(session);
1374                    }
1375            }
1376    
1377            protected DLFileRank getByG_U_PrevAndNext(Session session,
1378                    DLFileRank dlFileRank, long groupId, long userId,
1379                    OrderByComparator<DLFileRank> orderByComparator, boolean previous) {
1380                    StringBundler query = null;
1381    
1382                    if (orderByComparator != null) {
1383                            query = new StringBundler(6 +
1384                                            (orderByComparator.getOrderByFields().length * 6));
1385                    }
1386                    else {
1387                            query = new StringBundler(3);
1388                    }
1389    
1390                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1391    
1392                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1393    
1394                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1395    
1396                    if (orderByComparator != null) {
1397                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1398    
1399                            if (orderByConditionFields.length > 0) {
1400                                    query.append(WHERE_AND);
1401                            }
1402    
1403                            for (int i = 0; i < orderByConditionFields.length; i++) {
1404                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1405                                    query.append(orderByConditionFields[i]);
1406    
1407                                    if ((i + 1) < orderByConditionFields.length) {
1408                                            if (orderByComparator.isAscending() ^ previous) {
1409                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1410                                            }
1411                                            else {
1412                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1413                                            }
1414                                    }
1415                                    else {
1416                                            if (orderByComparator.isAscending() ^ previous) {
1417                                                    query.append(WHERE_GREATER_THAN);
1418                                            }
1419                                            else {
1420                                                    query.append(WHERE_LESSER_THAN);
1421                                            }
1422                                    }
1423                            }
1424    
1425                            query.append(ORDER_BY_CLAUSE);
1426    
1427                            String[] orderByFields = orderByComparator.getOrderByFields();
1428    
1429                            for (int i = 0; i < orderByFields.length; i++) {
1430                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1431                                    query.append(orderByFields[i]);
1432    
1433                                    if ((i + 1) < orderByFields.length) {
1434                                            if (orderByComparator.isAscending() ^ previous) {
1435                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1436                                            }
1437                                            else {
1438                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1439                                            }
1440                                    }
1441                                    else {
1442                                            if (orderByComparator.isAscending() ^ previous) {
1443                                                    query.append(ORDER_BY_ASC);
1444                                            }
1445                                            else {
1446                                                    query.append(ORDER_BY_DESC);
1447                                            }
1448                                    }
1449                            }
1450                    }
1451                    else {
1452                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1453                    }
1454    
1455                    String sql = query.toString();
1456    
1457                    Query q = session.createQuery(sql);
1458    
1459                    q.setFirstResult(0);
1460                    q.setMaxResults(2);
1461    
1462                    QueryPos qPos = QueryPos.getInstance(q);
1463    
1464                    qPos.add(groupId);
1465    
1466                    qPos.add(userId);
1467    
1468                    if (orderByComparator != null) {
1469                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
1470    
1471                            for (Object value : values) {
1472                                    qPos.add(value);
1473                            }
1474                    }
1475    
1476                    List<DLFileRank> list = q.list();
1477    
1478                    if (list.size() == 2) {
1479                            return list.get(1);
1480                    }
1481                    else {
1482                            return null;
1483                    }
1484            }
1485    
1486            /**
1487             * Removes all the document library file ranks where groupId = &#63; and userId = &#63; from the database.
1488             *
1489             * @param groupId the group ID
1490             * @param userId the user ID
1491             */
1492            @Override
1493            public void removeByG_U(long groupId, long userId) {
1494                    for (DLFileRank dlFileRank : findByG_U(groupId, userId,
1495                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1496                            remove(dlFileRank);
1497                    }
1498            }
1499    
1500            /**
1501             * Returns the number of document library file ranks where groupId = &#63; and userId = &#63;.
1502             *
1503             * @param groupId the group ID
1504             * @param userId the user ID
1505             * @return the number of matching document library file ranks
1506             */
1507            @Override
1508            public int countByG_U(long groupId, long userId) {
1509                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
1510    
1511                    Object[] finderArgs = new Object[] { groupId, userId };
1512    
1513                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1514                                    this);
1515    
1516                    if (count == null) {
1517                            StringBundler query = new StringBundler(3);
1518    
1519                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
1520    
1521                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1522    
1523                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1524    
1525                            String sql = query.toString();
1526    
1527                            Session session = null;
1528    
1529                            try {
1530                                    session = openSession();
1531    
1532                                    Query q = session.createQuery(sql);
1533    
1534                                    QueryPos qPos = QueryPos.getInstance(q);
1535    
1536                                    qPos.add(groupId);
1537    
1538                                    qPos.add(userId);
1539    
1540                                    count = (Long)q.uniqueResult();
1541    
1542                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1543                            }
1544                            catch (Exception e) {
1545                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1546    
1547                                    throw processException(e);
1548                            }
1549                            finally {
1550                                    closeSession(session);
1551                            }
1552                    }
1553    
1554                    return count.intValue();
1555            }
1556    
1557            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "dlFileRank.groupId = ? AND ";
1558            private static final String _FINDER_COLUMN_G_U_USERID_2 = "dlFileRank.userId = ?";
1559            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_A = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1560                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
1561                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_A",
1562                            new String[] {
1563                                    Long.class.getName(), Long.class.getName(),
1564                                    Boolean.class.getName(),
1565                                    
1566                            Integer.class.getName(), Integer.class.getName(),
1567                                    OrderByComparator.class.getName()
1568                            });
1569            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1570                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
1571                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_A",
1572                            new String[] {
1573                                    Long.class.getName(), Long.class.getName(),
1574                                    Boolean.class.getName()
1575                            },
1576                            DLFileRankModelImpl.GROUPID_COLUMN_BITMASK |
1577                            DLFileRankModelImpl.USERID_COLUMN_BITMASK |
1578                            DLFileRankModelImpl.ACTIVE_COLUMN_BITMASK |
1579                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
1580            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_A = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1581                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
1582                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_A",
1583                            new String[] {
1584                                    Long.class.getName(), Long.class.getName(),
1585                                    Boolean.class.getName()
1586                            });
1587    
1588            /**
1589             * Returns all the document library file ranks where groupId = &#63; and userId = &#63; and active = &#63;.
1590             *
1591             * @param groupId the group ID
1592             * @param userId the user ID
1593             * @param active the active
1594             * @return the matching document library file ranks
1595             */
1596            @Override
1597            public List<DLFileRank> findByG_U_A(long groupId, long userId,
1598                    boolean active) {
1599                    return findByG_U_A(groupId, userId, active, QueryUtil.ALL_POS,
1600                            QueryUtil.ALL_POS, null);
1601            }
1602    
1603            /**
1604             * Returns a range of all the document library file ranks where groupId = &#63; and userId = &#63; and active = &#63;.
1605             *
1606             * <p>
1607             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1608             * </p>
1609             *
1610             * @param groupId the group ID
1611             * @param userId the user ID
1612             * @param active the active
1613             * @param start the lower bound of the range of document library file ranks
1614             * @param end the upper bound of the range of document library file ranks (not inclusive)
1615             * @return the range of matching document library file ranks
1616             */
1617            @Override
1618            public List<DLFileRank> findByG_U_A(long groupId, long userId,
1619                    boolean active, int start, int end) {
1620                    return findByG_U_A(groupId, userId, active, start, end, null);
1621            }
1622    
1623            /**
1624             * Returns an ordered range of all the document library file ranks where groupId = &#63; and userId = &#63; and active = &#63;.
1625             *
1626             * <p>
1627             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1628             * </p>
1629             *
1630             * @param groupId the group ID
1631             * @param userId the user ID
1632             * @param active the active
1633             * @param start the lower bound of the range of document library file ranks
1634             * @param end the upper bound of the range of document library file ranks (not inclusive)
1635             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1636             * @return the ordered range of matching document library file ranks
1637             */
1638            @Override
1639            public List<DLFileRank> findByG_U_A(long groupId, long userId,
1640                    boolean active, int start, int end,
1641                    OrderByComparator<DLFileRank> orderByComparator) {
1642                    boolean pagination = true;
1643                    FinderPath finderPath = null;
1644                    Object[] finderArgs = null;
1645    
1646                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1647                                    (orderByComparator == null)) {
1648                            pagination = false;
1649                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A;
1650                            finderArgs = new Object[] { groupId, userId, active };
1651                    }
1652                    else {
1653                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_A;
1654                            finderArgs = new Object[] {
1655                                            groupId, userId, active,
1656                                            
1657                                            start, end, orderByComparator
1658                                    };
1659                    }
1660    
1661                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
1662                                    finderArgs, this);
1663    
1664                    if ((list != null) && !list.isEmpty()) {
1665                            for (DLFileRank dlFileRank : list) {
1666                                    if ((groupId != dlFileRank.getGroupId()) ||
1667                                                    (userId != dlFileRank.getUserId()) ||
1668                                                    (active != dlFileRank.getActive())) {
1669                                            list = null;
1670    
1671                                            break;
1672                                    }
1673                            }
1674                    }
1675    
1676                    if (list == null) {
1677                            StringBundler query = null;
1678    
1679                            if (orderByComparator != null) {
1680                                    query = new StringBundler(5 +
1681                                                    (orderByComparator.getOrderByFields().length * 3));
1682                            }
1683                            else {
1684                                    query = new StringBundler(5);
1685                            }
1686    
1687                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
1688    
1689                            query.append(_FINDER_COLUMN_G_U_A_GROUPID_2);
1690    
1691                            query.append(_FINDER_COLUMN_G_U_A_USERID_2);
1692    
1693                            query.append(_FINDER_COLUMN_G_U_A_ACTIVE_2);
1694    
1695                            if (orderByComparator != null) {
1696                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1697                                            orderByComparator);
1698                            }
1699                            else
1700                             if (pagination) {
1701                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1702                            }
1703    
1704                            String sql = query.toString();
1705    
1706                            Session session = null;
1707    
1708                            try {
1709                                    session = openSession();
1710    
1711                                    Query q = session.createQuery(sql);
1712    
1713                                    QueryPos qPos = QueryPos.getInstance(q);
1714    
1715                                    qPos.add(groupId);
1716    
1717                                    qPos.add(userId);
1718    
1719                                    qPos.add(active);
1720    
1721                                    if (!pagination) {
1722                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1723                                                            start, end, false);
1724    
1725                                            Collections.sort(list);
1726    
1727                                            list = Collections.unmodifiableList(list);
1728                                    }
1729                                    else {
1730                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1731                                                            start, end);
1732                                    }
1733    
1734                                    cacheResult(list);
1735    
1736                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1737                            }
1738                            catch (Exception e) {
1739                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1740    
1741                                    throw processException(e);
1742                            }
1743                            finally {
1744                                    closeSession(session);
1745                            }
1746                    }
1747    
1748                    return list;
1749            }
1750    
1751            /**
1752             * Returns the first document library file rank in the ordered set where groupId = &#63; and userId = &#63; and active = &#63;.
1753             *
1754             * @param groupId the group ID
1755             * @param userId the user ID
1756             * @param active the active
1757             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1758             * @return the first matching document library file rank
1759             * @throws NoSuchFileRankException if a matching document library file rank could not be found
1760             */
1761            @Override
1762            public DLFileRank findByG_U_A_First(long groupId, long userId,
1763                    boolean active, OrderByComparator<DLFileRank> orderByComparator)
1764                    throws NoSuchFileRankException {
1765                    DLFileRank dlFileRank = fetchByG_U_A_First(groupId, userId, active,
1766                                    orderByComparator);
1767    
1768                    if (dlFileRank != null) {
1769                            return dlFileRank;
1770                    }
1771    
1772                    StringBundler msg = new StringBundler(8);
1773    
1774                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1775    
1776                    msg.append("groupId=");
1777                    msg.append(groupId);
1778    
1779                    msg.append(", userId=");
1780                    msg.append(userId);
1781    
1782                    msg.append(", active=");
1783                    msg.append(active);
1784    
1785                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1786    
1787                    throw new NoSuchFileRankException(msg.toString());
1788            }
1789    
1790            /**
1791             * Returns the first document library file rank in the ordered set where groupId = &#63; and userId = &#63; and active = &#63;.
1792             *
1793             * @param groupId the group ID
1794             * @param userId the user ID
1795             * @param active the active
1796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1797             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1798             */
1799            @Override
1800            public DLFileRank fetchByG_U_A_First(long groupId, long userId,
1801                    boolean active, OrderByComparator<DLFileRank> orderByComparator) {
1802                    List<DLFileRank> list = findByG_U_A(groupId, userId, active, 0, 1,
1803                                    orderByComparator);
1804    
1805                    if (!list.isEmpty()) {
1806                            return list.get(0);
1807                    }
1808    
1809                    return null;
1810            }
1811    
1812            /**
1813             * Returns the last document library file rank in the ordered set where groupId = &#63; and userId = &#63; and active = &#63;.
1814             *
1815             * @param groupId the group ID
1816             * @param userId the user ID
1817             * @param active the active
1818             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1819             * @return the last matching document library file rank
1820             * @throws NoSuchFileRankException if a matching document library file rank could not be found
1821             */
1822            @Override
1823            public DLFileRank findByG_U_A_Last(long groupId, long userId,
1824                    boolean active, OrderByComparator<DLFileRank> orderByComparator)
1825                    throws NoSuchFileRankException {
1826                    DLFileRank dlFileRank = fetchByG_U_A_Last(groupId, userId, active,
1827                                    orderByComparator);
1828    
1829                    if (dlFileRank != null) {
1830                            return dlFileRank;
1831                    }
1832    
1833                    StringBundler msg = new StringBundler(8);
1834    
1835                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1836    
1837                    msg.append("groupId=");
1838                    msg.append(groupId);
1839    
1840                    msg.append(", userId=");
1841                    msg.append(userId);
1842    
1843                    msg.append(", active=");
1844                    msg.append(active);
1845    
1846                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1847    
1848                    throw new NoSuchFileRankException(msg.toString());
1849            }
1850    
1851            /**
1852             * Returns the last document library file rank in the ordered set where groupId = &#63; and userId = &#63; and active = &#63;.
1853             *
1854             * @param groupId the group ID
1855             * @param userId the user ID
1856             * @param active the active
1857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1858             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1859             */
1860            @Override
1861            public DLFileRank fetchByG_U_A_Last(long groupId, long userId,
1862                    boolean active, OrderByComparator<DLFileRank> orderByComparator) {
1863                    int count = countByG_U_A(groupId, userId, active);
1864    
1865                    if (count == 0) {
1866                            return null;
1867                    }
1868    
1869                    List<DLFileRank> list = findByG_U_A(groupId, userId, active, count - 1,
1870                                    count, orderByComparator);
1871    
1872                    if (!list.isEmpty()) {
1873                            return list.get(0);
1874                    }
1875    
1876                    return null;
1877            }
1878    
1879            /**
1880             * Returns the document library file ranks before and after the current document library file rank in the ordered set where groupId = &#63; and userId = &#63; and active = &#63;.
1881             *
1882             * @param fileRankId the primary key of the current document library file rank
1883             * @param groupId the group ID
1884             * @param userId the user ID
1885             * @param active the active
1886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1887             * @return the previous, current, and next document library file rank
1888             * @throws NoSuchFileRankException if a document library file rank with the primary key could not be found
1889             */
1890            @Override
1891            public DLFileRank[] findByG_U_A_PrevAndNext(long fileRankId, long groupId,
1892                    long userId, boolean active,
1893                    OrderByComparator<DLFileRank> orderByComparator)
1894                    throws NoSuchFileRankException {
1895                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1896    
1897                    Session session = null;
1898    
1899                    try {
1900                            session = openSession();
1901    
1902                            DLFileRank[] array = new DLFileRankImpl[3];
1903    
1904                            array[0] = getByG_U_A_PrevAndNext(session, dlFileRank, groupId,
1905                                            userId, active, orderByComparator, true);
1906    
1907                            array[1] = dlFileRank;
1908    
1909                            array[2] = getByG_U_A_PrevAndNext(session, dlFileRank, groupId,
1910                                            userId, active, orderByComparator, false);
1911    
1912                            return array;
1913                    }
1914                    catch (Exception e) {
1915                            throw processException(e);
1916                    }
1917                    finally {
1918                            closeSession(session);
1919                    }
1920            }
1921    
1922            protected DLFileRank getByG_U_A_PrevAndNext(Session session,
1923                    DLFileRank dlFileRank, long groupId, long userId, boolean active,
1924                    OrderByComparator<DLFileRank> orderByComparator, boolean previous) {
1925                    StringBundler query = null;
1926    
1927                    if (orderByComparator != null) {
1928                            query = new StringBundler(6 +
1929                                            (orderByComparator.getOrderByFields().length * 6));
1930                    }
1931                    else {
1932                            query = new StringBundler(3);
1933                    }
1934    
1935                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1936    
1937                    query.append(_FINDER_COLUMN_G_U_A_GROUPID_2);
1938    
1939                    query.append(_FINDER_COLUMN_G_U_A_USERID_2);
1940    
1941                    query.append(_FINDER_COLUMN_G_U_A_ACTIVE_2);
1942    
1943                    if (orderByComparator != null) {
1944                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1945    
1946                            if (orderByConditionFields.length > 0) {
1947                                    query.append(WHERE_AND);
1948                            }
1949    
1950                            for (int i = 0; i < orderByConditionFields.length; i++) {
1951                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1952                                    query.append(orderByConditionFields[i]);
1953    
1954                                    if ((i + 1) < orderByConditionFields.length) {
1955                                            if (orderByComparator.isAscending() ^ previous) {
1956                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1957                                            }
1958                                            else {
1959                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1960                                            }
1961                                    }
1962                                    else {
1963                                            if (orderByComparator.isAscending() ^ previous) {
1964                                                    query.append(WHERE_GREATER_THAN);
1965                                            }
1966                                            else {
1967                                                    query.append(WHERE_LESSER_THAN);
1968                                            }
1969                                    }
1970                            }
1971    
1972                            query.append(ORDER_BY_CLAUSE);
1973    
1974                            String[] orderByFields = orderByComparator.getOrderByFields();
1975    
1976                            for (int i = 0; i < orderByFields.length; i++) {
1977                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1978                                    query.append(orderByFields[i]);
1979    
1980                                    if ((i + 1) < orderByFields.length) {
1981                                            if (orderByComparator.isAscending() ^ previous) {
1982                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1983                                            }
1984                                            else {
1985                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1986                                            }
1987                                    }
1988                                    else {
1989                                            if (orderByComparator.isAscending() ^ previous) {
1990                                                    query.append(ORDER_BY_ASC);
1991                                            }
1992                                            else {
1993                                                    query.append(ORDER_BY_DESC);
1994                                            }
1995                                    }
1996                            }
1997                    }
1998                    else {
1999                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
2000                    }
2001    
2002                    String sql = query.toString();
2003    
2004                    Query q = session.createQuery(sql);
2005    
2006                    q.setFirstResult(0);
2007                    q.setMaxResults(2);
2008    
2009                    QueryPos qPos = QueryPos.getInstance(q);
2010    
2011                    qPos.add(groupId);
2012    
2013                    qPos.add(userId);
2014    
2015                    qPos.add(active);
2016    
2017                    if (orderByComparator != null) {
2018                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
2019    
2020                            for (Object value : values) {
2021                                    qPos.add(value);
2022                            }
2023                    }
2024    
2025                    List<DLFileRank> list = q.list();
2026    
2027                    if (list.size() == 2) {
2028                            return list.get(1);
2029                    }
2030                    else {
2031                            return null;
2032                    }
2033            }
2034    
2035            /**
2036             * Removes all the document library file ranks where groupId = &#63; and userId = &#63; and active = &#63; from the database.
2037             *
2038             * @param groupId the group ID
2039             * @param userId the user ID
2040             * @param active the active
2041             */
2042            @Override
2043            public void removeByG_U_A(long groupId, long userId, boolean active) {
2044                    for (DLFileRank dlFileRank : findByG_U_A(groupId, userId, active,
2045                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2046                            remove(dlFileRank);
2047                    }
2048            }
2049    
2050            /**
2051             * Returns the number of document library file ranks where groupId = &#63; and userId = &#63; and active = &#63;.
2052             *
2053             * @param groupId the group ID
2054             * @param userId the user ID
2055             * @param active the active
2056             * @return the number of matching document library file ranks
2057             */
2058            @Override
2059            public int countByG_U_A(long groupId, long userId, boolean active) {
2060                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_A;
2061    
2062                    Object[] finderArgs = new Object[] { groupId, userId, active };
2063    
2064                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2065                                    this);
2066    
2067                    if (count == null) {
2068                            StringBundler query = new StringBundler(4);
2069    
2070                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2071    
2072                            query.append(_FINDER_COLUMN_G_U_A_GROUPID_2);
2073    
2074                            query.append(_FINDER_COLUMN_G_U_A_USERID_2);
2075    
2076                            query.append(_FINDER_COLUMN_G_U_A_ACTIVE_2);
2077    
2078                            String sql = query.toString();
2079    
2080                            Session session = null;
2081    
2082                            try {
2083                                    session = openSession();
2084    
2085                                    Query q = session.createQuery(sql);
2086    
2087                                    QueryPos qPos = QueryPos.getInstance(q);
2088    
2089                                    qPos.add(groupId);
2090    
2091                                    qPos.add(userId);
2092    
2093                                    qPos.add(active);
2094    
2095                                    count = (Long)q.uniqueResult();
2096    
2097                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2098                            }
2099                            catch (Exception e) {
2100                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2101    
2102                                    throw processException(e);
2103                            }
2104                            finally {
2105                                    closeSession(session);
2106                            }
2107                    }
2108    
2109                    return count.intValue();
2110            }
2111    
2112            private static final String _FINDER_COLUMN_G_U_A_GROUPID_2 = "dlFileRank.groupId = ? AND ";
2113            private static final String _FINDER_COLUMN_G_U_A_USERID_2 = "dlFileRank.userId = ? AND ";
2114            private static final String _FINDER_COLUMN_G_U_A_ACTIVE_2 = "dlFileRank.active = ?";
2115            public static final FinderPath FINDER_PATH_FETCH_BY_C_U_F = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2116                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
2117                            FINDER_CLASS_NAME_ENTITY, "fetchByC_U_F",
2118                            new String[] {
2119                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
2120                            },
2121                            DLFileRankModelImpl.COMPANYID_COLUMN_BITMASK |
2122                            DLFileRankModelImpl.USERID_COLUMN_BITMASK |
2123                            DLFileRankModelImpl.FILEENTRYID_COLUMN_BITMASK);
2124            public static final FinderPath FINDER_PATH_COUNT_BY_C_U_F = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2125                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
2126                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U_F",
2127                            new String[] {
2128                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
2129                            });
2130    
2131            /**
2132             * Returns the document library file rank where companyId = &#63; and userId = &#63; and fileEntryId = &#63; or throws a {@link NoSuchFileRankException} if it could not be found.
2133             *
2134             * @param companyId the company ID
2135             * @param userId the user ID
2136             * @param fileEntryId the file entry ID
2137             * @return the matching document library file rank
2138             * @throws NoSuchFileRankException if a matching document library file rank could not be found
2139             */
2140            @Override
2141            public DLFileRank findByC_U_F(long companyId, long userId, long fileEntryId)
2142                    throws NoSuchFileRankException {
2143                    DLFileRank dlFileRank = fetchByC_U_F(companyId, userId, fileEntryId);
2144    
2145                    if (dlFileRank == null) {
2146                            StringBundler msg = new StringBundler(8);
2147    
2148                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2149    
2150                            msg.append("companyId=");
2151                            msg.append(companyId);
2152    
2153                            msg.append(", userId=");
2154                            msg.append(userId);
2155    
2156                            msg.append(", fileEntryId=");
2157                            msg.append(fileEntryId);
2158    
2159                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2160    
2161                            if (_log.isWarnEnabled()) {
2162                                    _log.warn(msg.toString());
2163                            }
2164    
2165                            throw new NoSuchFileRankException(msg.toString());
2166                    }
2167    
2168                    return dlFileRank;
2169            }
2170    
2171            /**
2172             * Returns the document library file rank where companyId = &#63; and userId = &#63; and fileEntryId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2173             *
2174             * @param companyId the company ID
2175             * @param userId the user ID
2176             * @param fileEntryId the file entry ID
2177             * @return the matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
2178             */
2179            @Override
2180            public DLFileRank fetchByC_U_F(long companyId, long userId, long fileEntryId) {
2181                    return fetchByC_U_F(companyId, userId, fileEntryId, true);
2182            }
2183    
2184            /**
2185             * Returns the document library file rank where companyId = &#63; and userId = &#63; and fileEntryId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2186             *
2187             * @param companyId the company ID
2188             * @param userId the user ID
2189             * @param fileEntryId the file entry ID
2190             * @param retrieveFromCache whether to use the finder cache
2191             * @return the matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
2192             */
2193            @Override
2194            public DLFileRank fetchByC_U_F(long companyId, long userId,
2195                    long fileEntryId, boolean retrieveFromCache) {
2196                    Object[] finderArgs = new Object[] { companyId, userId, fileEntryId };
2197    
2198                    Object result = null;
2199    
2200                    if (retrieveFromCache) {
2201                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_F,
2202                                            finderArgs, this);
2203                    }
2204    
2205                    if (result instanceof DLFileRank) {
2206                            DLFileRank dlFileRank = (DLFileRank)result;
2207    
2208                            if ((companyId != dlFileRank.getCompanyId()) ||
2209                                            (userId != dlFileRank.getUserId()) ||
2210                                            (fileEntryId != dlFileRank.getFileEntryId())) {
2211                                    result = null;
2212                            }
2213                    }
2214    
2215                    if (result == null) {
2216                            StringBundler query = new StringBundler(5);
2217    
2218                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
2219    
2220                            query.append(_FINDER_COLUMN_C_U_F_COMPANYID_2);
2221    
2222                            query.append(_FINDER_COLUMN_C_U_F_USERID_2);
2223    
2224                            query.append(_FINDER_COLUMN_C_U_F_FILEENTRYID_2);
2225    
2226                            String sql = query.toString();
2227    
2228                            Session session = null;
2229    
2230                            try {
2231                                    session = openSession();
2232    
2233                                    Query q = session.createQuery(sql);
2234    
2235                                    QueryPos qPos = QueryPos.getInstance(q);
2236    
2237                                    qPos.add(companyId);
2238    
2239                                    qPos.add(userId);
2240    
2241                                    qPos.add(fileEntryId);
2242    
2243                                    List<DLFileRank> list = q.list();
2244    
2245                                    if (list.isEmpty()) {
2246                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
2247                                                    finderArgs, list);
2248                                    }
2249                                    else {
2250                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2251                                                    _log.warn(
2252                                                            "DLFileRankPersistenceImpl.fetchByC_U_F(long, long, long, boolean) with parameters (" +
2253                                                            StringUtil.merge(finderArgs) +
2254                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
2255                                            }
2256    
2257                                            DLFileRank dlFileRank = list.get(0);
2258    
2259                                            result = dlFileRank;
2260    
2261                                            cacheResult(dlFileRank);
2262    
2263                                            if ((dlFileRank.getCompanyId() != companyId) ||
2264                                                            (dlFileRank.getUserId() != userId) ||
2265                                                            (dlFileRank.getFileEntryId() != fileEntryId)) {
2266                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
2267                                                            finderArgs, dlFileRank);
2268                                            }
2269                                    }
2270                            }
2271                            catch (Exception e) {
2272                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F,
2273                                            finderArgs);
2274    
2275                                    throw processException(e);
2276                            }
2277                            finally {
2278                                    closeSession(session);
2279                            }
2280                    }
2281    
2282                    if (result instanceof List<?>) {
2283                            return null;
2284                    }
2285                    else {
2286                            return (DLFileRank)result;
2287                    }
2288            }
2289    
2290            /**
2291             * Removes the document library file rank where companyId = &#63; and userId = &#63; and fileEntryId = &#63; from the database.
2292             *
2293             * @param companyId the company ID
2294             * @param userId the user ID
2295             * @param fileEntryId the file entry ID
2296             * @return the document library file rank that was removed
2297             */
2298            @Override
2299            public DLFileRank removeByC_U_F(long companyId, long userId,
2300                    long fileEntryId) throws NoSuchFileRankException {
2301                    DLFileRank dlFileRank = findByC_U_F(companyId, userId, fileEntryId);
2302    
2303                    return remove(dlFileRank);
2304            }
2305    
2306            /**
2307             * Returns the number of document library file ranks where companyId = &#63; and userId = &#63; and fileEntryId = &#63;.
2308             *
2309             * @param companyId the company ID
2310             * @param userId the user ID
2311             * @param fileEntryId the file entry ID
2312             * @return the number of matching document library file ranks
2313             */
2314            @Override
2315            public int countByC_U_F(long companyId, long userId, long fileEntryId) {
2316                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U_F;
2317    
2318                    Object[] finderArgs = new Object[] { companyId, userId, fileEntryId };
2319    
2320                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2321                                    this);
2322    
2323                    if (count == null) {
2324                            StringBundler query = new StringBundler(4);
2325    
2326                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2327    
2328                            query.append(_FINDER_COLUMN_C_U_F_COMPANYID_2);
2329    
2330                            query.append(_FINDER_COLUMN_C_U_F_USERID_2);
2331    
2332                            query.append(_FINDER_COLUMN_C_U_F_FILEENTRYID_2);
2333    
2334                            String sql = query.toString();
2335    
2336                            Session session = null;
2337    
2338                            try {
2339                                    session = openSession();
2340    
2341                                    Query q = session.createQuery(sql);
2342    
2343                                    QueryPos qPos = QueryPos.getInstance(q);
2344    
2345                                    qPos.add(companyId);
2346    
2347                                    qPos.add(userId);
2348    
2349                                    qPos.add(fileEntryId);
2350    
2351                                    count = (Long)q.uniqueResult();
2352    
2353                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2354                            }
2355                            catch (Exception e) {
2356                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2357    
2358                                    throw processException(e);
2359                            }
2360                            finally {
2361                                    closeSession(session);
2362                            }
2363                    }
2364    
2365                    return count.intValue();
2366            }
2367    
2368            private static final String _FINDER_COLUMN_C_U_F_COMPANYID_2 = "dlFileRank.companyId = ? AND ";
2369            private static final String _FINDER_COLUMN_C_U_F_USERID_2 = "dlFileRank.userId = ? AND ";
2370            private static final String _FINDER_COLUMN_C_U_F_FILEENTRYID_2 = "dlFileRank.fileEntryId = ?";
2371    
2372            public DLFileRankPersistenceImpl() {
2373                    setModelClass(DLFileRank.class);
2374            }
2375    
2376            /**
2377             * Caches the document library file rank in the entity cache if it is enabled.
2378             *
2379             * @param dlFileRank the document library file rank
2380             */
2381            @Override
2382            public void cacheResult(DLFileRank dlFileRank) {
2383                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2384                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
2385    
2386                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
2387                            new Object[] {
2388                                    dlFileRank.getCompanyId(), dlFileRank.getUserId(),
2389                                    dlFileRank.getFileEntryId()
2390                            }, dlFileRank);
2391    
2392                    dlFileRank.resetOriginalValues();
2393            }
2394    
2395            /**
2396             * Caches the document library file ranks in the entity cache if it is enabled.
2397             *
2398             * @param dlFileRanks the document library file ranks
2399             */
2400            @Override
2401            public void cacheResult(List<DLFileRank> dlFileRanks) {
2402                    for (DLFileRank dlFileRank : dlFileRanks) {
2403                            if (EntityCacheUtil.getResult(
2404                                                    DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2405                                                    DLFileRankImpl.class, dlFileRank.getPrimaryKey()) == null) {
2406                                    cacheResult(dlFileRank);
2407                            }
2408                            else {
2409                                    dlFileRank.resetOriginalValues();
2410                            }
2411                    }
2412            }
2413    
2414            /**
2415             * Clears the cache for all document library file ranks.
2416             *
2417             * <p>
2418             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2419             * </p>
2420             */
2421            @Override
2422            public void clearCache() {
2423                    EntityCacheUtil.clearCache(DLFileRankImpl.class);
2424    
2425                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2426                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2427                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2428            }
2429    
2430            /**
2431             * Clears the cache for the document library file rank.
2432             *
2433             * <p>
2434             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2435             * </p>
2436             */
2437            @Override
2438            public void clearCache(DLFileRank dlFileRank) {
2439                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2440                            DLFileRankImpl.class, dlFileRank.getPrimaryKey());
2441    
2442                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2443                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2444    
2445                    clearUniqueFindersCache(dlFileRank);
2446            }
2447    
2448            @Override
2449            public void clearCache(List<DLFileRank> dlFileRanks) {
2450                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2451                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2452    
2453                    for (DLFileRank dlFileRank : dlFileRanks) {
2454                            EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2455                                    DLFileRankImpl.class, dlFileRank.getPrimaryKey());
2456    
2457                            clearUniqueFindersCache(dlFileRank);
2458                    }
2459            }
2460    
2461            protected void cacheUniqueFindersCache(DLFileRank dlFileRank) {
2462                    if (dlFileRank.isNew()) {
2463                            Object[] args = new Object[] {
2464                                            dlFileRank.getCompanyId(), dlFileRank.getUserId(),
2465                                            dlFileRank.getFileEntryId()
2466                                    };
2467    
2468                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F, args,
2469                                    Long.valueOf(1));
2470                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F, args,
2471                                    dlFileRank);
2472                    }
2473                    else {
2474                            DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
2475    
2476                            if ((dlFileRankModelImpl.getColumnBitmask() &
2477                                            FINDER_PATH_FETCH_BY_C_U_F.getColumnBitmask()) != 0) {
2478                                    Object[] args = new Object[] {
2479                                                    dlFileRank.getCompanyId(), dlFileRank.getUserId(),
2480                                                    dlFileRank.getFileEntryId()
2481                                            };
2482    
2483                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F, args,
2484                                            Long.valueOf(1));
2485                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F, args,
2486                                            dlFileRank);
2487                            }
2488                    }
2489            }
2490    
2491            protected void clearUniqueFindersCache(DLFileRank dlFileRank) {
2492                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
2493    
2494                    Object[] args = new Object[] {
2495                                    dlFileRank.getCompanyId(), dlFileRank.getUserId(),
2496                                    dlFileRank.getFileEntryId()
2497                            };
2498    
2499                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_F, args);
2500                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F, args);
2501    
2502                    if ((dlFileRankModelImpl.getColumnBitmask() &
2503                                    FINDER_PATH_FETCH_BY_C_U_F.getColumnBitmask()) != 0) {
2504                            args = new Object[] {
2505                                            dlFileRankModelImpl.getOriginalCompanyId(),
2506                                            dlFileRankModelImpl.getOriginalUserId(),
2507                                            dlFileRankModelImpl.getOriginalFileEntryId()
2508                                    };
2509    
2510                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_F, args);
2511                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F, args);
2512                    }
2513            }
2514    
2515            /**
2516             * Creates a new document library file rank with the primary key. Does not add the document library file rank to the database.
2517             *
2518             * @param fileRankId the primary key for the new document library file rank
2519             * @return the new document library file rank
2520             */
2521            @Override
2522            public DLFileRank create(long fileRankId) {
2523                    DLFileRank dlFileRank = new DLFileRankImpl();
2524    
2525                    dlFileRank.setNew(true);
2526                    dlFileRank.setPrimaryKey(fileRankId);
2527    
2528                    return dlFileRank;
2529            }
2530    
2531            /**
2532             * Removes the document library file rank with the primary key from the database. Also notifies the appropriate model listeners.
2533             *
2534             * @param fileRankId the primary key of the document library file rank
2535             * @return the document library file rank that was removed
2536             * @throws NoSuchFileRankException if a document library file rank with the primary key could not be found
2537             */
2538            @Override
2539            public DLFileRank remove(long fileRankId) throws NoSuchFileRankException {
2540                    return remove((Serializable)fileRankId);
2541            }
2542    
2543            /**
2544             * Removes the document library file rank with the primary key from the database. Also notifies the appropriate model listeners.
2545             *
2546             * @param primaryKey the primary key of the document library file rank
2547             * @return the document library file rank that was removed
2548             * @throws NoSuchFileRankException if a document library file rank with the primary key could not be found
2549             */
2550            @Override
2551            public DLFileRank remove(Serializable primaryKey)
2552                    throws NoSuchFileRankException {
2553                    Session session = null;
2554    
2555                    try {
2556                            session = openSession();
2557    
2558                            DLFileRank dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
2559                                            primaryKey);
2560    
2561                            if (dlFileRank == null) {
2562                                    if (_log.isWarnEnabled()) {
2563                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2564                                    }
2565    
2566                                    throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2567                                            primaryKey);
2568                            }
2569    
2570                            return remove(dlFileRank);
2571                    }
2572                    catch (NoSuchFileRankException nsee) {
2573                            throw nsee;
2574                    }
2575                    catch (Exception e) {
2576                            throw processException(e);
2577                    }
2578                    finally {
2579                            closeSession(session);
2580                    }
2581            }
2582    
2583            @Override
2584            protected DLFileRank removeImpl(DLFileRank dlFileRank) {
2585                    dlFileRank = toUnwrappedModel(dlFileRank);
2586    
2587                    Session session = null;
2588    
2589                    try {
2590                            session = openSession();
2591    
2592                            if (!session.contains(dlFileRank)) {
2593                                    dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
2594                                                    dlFileRank.getPrimaryKeyObj());
2595                            }
2596    
2597                            if (dlFileRank != null) {
2598                                    session.delete(dlFileRank);
2599                            }
2600                    }
2601                    catch (Exception e) {
2602                            throw processException(e);
2603                    }
2604                    finally {
2605                            closeSession(session);
2606                    }
2607    
2608                    if (dlFileRank != null) {
2609                            clearCache(dlFileRank);
2610                    }
2611    
2612                    return dlFileRank;
2613            }
2614    
2615            @Override
2616            public DLFileRank updateImpl(DLFileRank dlFileRank) {
2617                    dlFileRank = toUnwrappedModel(dlFileRank);
2618    
2619                    boolean isNew = dlFileRank.isNew();
2620    
2621                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
2622    
2623                    Session session = null;
2624    
2625                    try {
2626                            session = openSession();
2627    
2628                            if (dlFileRank.isNew()) {
2629                                    session.save(dlFileRank);
2630    
2631                                    dlFileRank.setNew(false);
2632                            }
2633                            else {
2634                                    session.merge(dlFileRank);
2635                            }
2636                    }
2637                    catch (Exception e) {
2638                            throw processException(e);
2639                    }
2640                    finally {
2641                            closeSession(session);
2642                    }
2643    
2644                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2645    
2646                    if (isNew || !DLFileRankModelImpl.COLUMN_BITMASK_ENABLED) {
2647                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2648                    }
2649    
2650                    else {
2651                            if ((dlFileRankModelImpl.getColumnBitmask() &
2652                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2653                                    Object[] args = new Object[] {
2654                                                    dlFileRankModelImpl.getOriginalUserId()
2655                                            };
2656    
2657                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2658                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2659                                            args);
2660    
2661                                    args = new Object[] { dlFileRankModelImpl.getUserId() };
2662    
2663                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2664                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2665                                            args);
2666                            }
2667    
2668                            if ((dlFileRankModelImpl.getColumnBitmask() &
2669                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
2670                                    Object[] args = new Object[] {
2671                                                    dlFileRankModelImpl.getOriginalFileEntryId()
2672                                            };
2673    
2674                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
2675                                            args);
2676                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
2677                                            args);
2678    
2679                                    args = new Object[] { dlFileRankModelImpl.getFileEntryId() };
2680    
2681                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
2682                                            args);
2683                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
2684                                            args);
2685                            }
2686    
2687                            if ((dlFileRankModelImpl.getColumnBitmask() &
2688                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
2689                                    Object[] args = new Object[] {
2690                                                    dlFileRankModelImpl.getOriginalGroupId(),
2691                                                    dlFileRankModelImpl.getOriginalUserId()
2692                                            };
2693    
2694                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
2695                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
2696                                            args);
2697    
2698                                    args = new Object[] {
2699                                                    dlFileRankModelImpl.getGroupId(),
2700                                                    dlFileRankModelImpl.getUserId()
2701                                            };
2702    
2703                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
2704                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
2705                                            args);
2706                            }
2707    
2708                            if ((dlFileRankModelImpl.getColumnBitmask() &
2709                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A.getColumnBitmask()) != 0) {
2710                                    Object[] args = new Object[] {
2711                                                    dlFileRankModelImpl.getOriginalGroupId(),
2712                                                    dlFileRankModelImpl.getOriginalUserId(),
2713                                                    dlFileRankModelImpl.getOriginalActive()
2714                                            };
2715    
2716                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_A, args);
2717                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A,
2718                                            args);
2719    
2720                                    args = new Object[] {
2721                                                    dlFileRankModelImpl.getGroupId(),
2722                                                    dlFileRankModelImpl.getUserId(),
2723                                                    dlFileRankModelImpl.getActive()
2724                                            };
2725    
2726                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_A, args);
2727                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A,
2728                                            args);
2729                            }
2730                    }
2731    
2732                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2733                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank, false);
2734    
2735                    clearUniqueFindersCache(dlFileRank);
2736                    cacheUniqueFindersCache(dlFileRank);
2737    
2738                    dlFileRank.resetOriginalValues();
2739    
2740                    return dlFileRank;
2741            }
2742    
2743            protected DLFileRank toUnwrappedModel(DLFileRank dlFileRank) {
2744                    if (dlFileRank instanceof DLFileRankImpl) {
2745                            return dlFileRank;
2746                    }
2747    
2748                    DLFileRankImpl dlFileRankImpl = new DLFileRankImpl();
2749    
2750                    dlFileRankImpl.setNew(dlFileRank.isNew());
2751                    dlFileRankImpl.setPrimaryKey(dlFileRank.getPrimaryKey());
2752    
2753                    dlFileRankImpl.setFileRankId(dlFileRank.getFileRankId());
2754                    dlFileRankImpl.setGroupId(dlFileRank.getGroupId());
2755                    dlFileRankImpl.setCompanyId(dlFileRank.getCompanyId());
2756                    dlFileRankImpl.setUserId(dlFileRank.getUserId());
2757                    dlFileRankImpl.setCreateDate(dlFileRank.getCreateDate());
2758                    dlFileRankImpl.setFileEntryId(dlFileRank.getFileEntryId());
2759                    dlFileRankImpl.setActive(dlFileRank.isActive());
2760    
2761                    return dlFileRankImpl;
2762            }
2763    
2764            /**
2765             * Returns the document library file rank with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2766             *
2767             * @param primaryKey the primary key of the document library file rank
2768             * @return the document library file rank
2769             * @throws NoSuchFileRankException if a document library file rank with the primary key could not be found
2770             */
2771            @Override
2772            public DLFileRank findByPrimaryKey(Serializable primaryKey)
2773                    throws NoSuchFileRankException {
2774                    DLFileRank dlFileRank = fetchByPrimaryKey(primaryKey);
2775    
2776                    if (dlFileRank == null) {
2777                            if (_log.isWarnEnabled()) {
2778                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2779                            }
2780    
2781                            throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2782                                    primaryKey);
2783                    }
2784    
2785                    return dlFileRank;
2786            }
2787    
2788            /**
2789             * Returns the document library file rank with the primary key or throws a {@link NoSuchFileRankException} if it could not be found.
2790             *
2791             * @param fileRankId the primary key of the document library file rank
2792             * @return the document library file rank
2793             * @throws NoSuchFileRankException if a document library file rank with the primary key could not be found
2794             */
2795            @Override
2796            public DLFileRank findByPrimaryKey(long fileRankId)
2797                    throws NoSuchFileRankException {
2798                    return findByPrimaryKey((Serializable)fileRankId);
2799            }
2800    
2801            /**
2802             * Returns the document library file rank with the primary key or returns <code>null</code> if it could not be found.
2803             *
2804             * @param primaryKey the primary key of the document library file rank
2805             * @return the document library file rank, or <code>null</code> if a document library file rank with the primary key could not be found
2806             */
2807            @Override
2808            public DLFileRank fetchByPrimaryKey(Serializable primaryKey) {
2809                    DLFileRank dlFileRank = (DLFileRank)EntityCacheUtil.getResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2810                                    DLFileRankImpl.class, primaryKey);
2811    
2812                    if (dlFileRank == _nullDLFileRank) {
2813                            return null;
2814                    }
2815    
2816                    if (dlFileRank == null) {
2817                            Session session = null;
2818    
2819                            try {
2820                                    session = openSession();
2821    
2822                                    dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
2823                                                    primaryKey);
2824    
2825                                    if (dlFileRank != null) {
2826                                            cacheResult(dlFileRank);
2827                                    }
2828                                    else {
2829                                            EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2830                                                    DLFileRankImpl.class, primaryKey, _nullDLFileRank);
2831                                    }
2832                            }
2833                            catch (Exception e) {
2834                                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2835                                            DLFileRankImpl.class, primaryKey);
2836    
2837                                    throw processException(e);
2838                            }
2839                            finally {
2840                                    closeSession(session);
2841                            }
2842                    }
2843    
2844                    return dlFileRank;
2845            }
2846    
2847            /**
2848             * Returns the document library file rank with the primary key or returns <code>null</code> if it could not be found.
2849             *
2850             * @param fileRankId the primary key of the document library file rank
2851             * @return the document library file rank, or <code>null</code> if a document library file rank with the primary key could not be found
2852             */
2853            @Override
2854            public DLFileRank fetchByPrimaryKey(long fileRankId) {
2855                    return fetchByPrimaryKey((Serializable)fileRankId);
2856            }
2857    
2858            @Override
2859            public Map<Serializable, DLFileRank> fetchByPrimaryKeys(
2860                    Set<Serializable> primaryKeys) {
2861                    if (primaryKeys.isEmpty()) {
2862                            return Collections.emptyMap();
2863                    }
2864    
2865                    Map<Serializable, DLFileRank> map = new HashMap<Serializable, DLFileRank>();
2866    
2867                    if (primaryKeys.size() == 1) {
2868                            Iterator<Serializable> iterator = primaryKeys.iterator();
2869    
2870                            Serializable primaryKey = iterator.next();
2871    
2872                            DLFileRank dlFileRank = fetchByPrimaryKey(primaryKey);
2873    
2874                            if (dlFileRank != null) {
2875                                    map.put(primaryKey, dlFileRank);
2876                            }
2877    
2878                            return map;
2879                    }
2880    
2881                    Set<Serializable> uncachedPrimaryKeys = null;
2882    
2883                    for (Serializable primaryKey : primaryKeys) {
2884                            DLFileRank dlFileRank = (DLFileRank)EntityCacheUtil.getResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2885                                            DLFileRankImpl.class, primaryKey);
2886    
2887                            if (dlFileRank == null) {
2888                                    if (uncachedPrimaryKeys == null) {
2889                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2890                                    }
2891    
2892                                    uncachedPrimaryKeys.add(primaryKey);
2893                            }
2894                            else {
2895                                    map.put(primaryKey, dlFileRank);
2896                            }
2897                    }
2898    
2899                    if (uncachedPrimaryKeys == null) {
2900                            return map;
2901                    }
2902    
2903                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2904                                    1);
2905    
2906                    query.append(_SQL_SELECT_DLFILERANK_WHERE_PKS_IN);
2907    
2908                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2909                            query.append(String.valueOf(primaryKey));
2910    
2911                            query.append(StringPool.COMMA);
2912                    }
2913    
2914                    query.setIndex(query.index() - 1);
2915    
2916                    query.append(StringPool.CLOSE_PARENTHESIS);
2917    
2918                    String sql = query.toString();
2919    
2920                    Session session = null;
2921    
2922                    try {
2923                            session = openSession();
2924    
2925                            Query q = session.createQuery(sql);
2926    
2927                            for (DLFileRank dlFileRank : (List<DLFileRank>)q.list()) {
2928                                    map.put(dlFileRank.getPrimaryKeyObj(), dlFileRank);
2929    
2930                                    cacheResult(dlFileRank);
2931    
2932                                    uncachedPrimaryKeys.remove(dlFileRank.getPrimaryKeyObj());
2933                            }
2934    
2935                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2936                                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2937                                            DLFileRankImpl.class, primaryKey, _nullDLFileRank);
2938                            }
2939                    }
2940                    catch (Exception e) {
2941                            throw processException(e);
2942                    }
2943                    finally {
2944                            closeSession(session);
2945                    }
2946    
2947                    return map;
2948            }
2949    
2950            /**
2951             * Returns all the document library file ranks.
2952             *
2953             * @return the document library file ranks
2954             */
2955            @Override
2956            public List<DLFileRank> findAll() {
2957                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2958            }
2959    
2960            /**
2961             * Returns a range of all the document library file ranks.
2962             *
2963             * <p>
2964             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2965             * </p>
2966             *
2967             * @param start the lower bound of the range of document library file ranks
2968             * @param end the upper bound of the range of document library file ranks (not inclusive)
2969             * @return the range of document library file ranks
2970             */
2971            @Override
2972            public List<DLFileRank> findAll(int start, int end) {
2973                    return findAll(start, end, null);
2974            }
2975    
2976            /**
2977             * Returns an ordered range of all the document library file ranks.
2978             *
2979             * <p>
2980             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileRankModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2981             * </p>
2982             *
2983             * @param start the lower bound of the range of document library file ranks
2984             * @param end the upper bound of the range of document library file ranks (not inclusive)
2985             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2986             * @return the ordered range of document library file ranks
2987             */
2988            @Override
2989            public List<DLFileRank> findAll(int start, int end,
2990                    OrderByComparator<DLFileRank> orderByComparator) {
2991                    boolean pagination = true;
2992                    FinderPath finderPath = null;
2993                    Object[] finderArgs = null;
2994    
2995                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2996                                    (orderByComparator == null)) {
2997                            pagination = false;
2998                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2999                            finderArgs = FINDER_ARGS_EMPTY;
3000                    }
3001                    else {
3002                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3003                            finderArgs = new Object[] { start, end, orderByComparator };
3004                    }
3005    
3006                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
3007                                    finderArgs, this);
3008    
3009                    if (list == null) {
3010                            StringBundler query = null;
3011                            String sql = null;
3012    
3013                            if (orderByComparator != null) {
3014                                    query = new StringBundler(2 +
3015                                                    (orderByComparator.getOrderByFields().length * 3));
3016    
3017                                    query.append(_SQL_SELECT_DLFILERANK);
3018    
3019                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3020                                            orderByComparator);
3021    
3022                                    sql = query.toString();
3023                            }
3024                            else {
3025                                    sql = _SQL_SELECT_DLFILERANK;
3026    
3027                                    if (pagination) {
3028                                            sql = sql.concat(DLFileRankModelImpl.ORDER_BY_JPQL);
3029                                    }
3030                            }
3031    
3032                            Session session = null;
3033    
3034                            try {
3035                                    session = openSession();
3036    
3037                                    Query q = session.createQuery(sql);
3038    
3039                                    if (!pagination) {
3040                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
3041                                                            start, end, false);
3042    
3043                                            Collections.sort(list);
3044    
3045                                            list = Collections.unmodifiableList(list);
3046                                    }
3047                                    else {
3048                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
3049                                                            start, end);
3050                                    }
3051    
3052                                    cacheResult(list);
3053    
3054                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3055                            }
3056                            catch (Exception e) {
3057                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3058    
3059                                    throw processException(e);
3060                            }
3061                            finally {
3062                                    closeSession(session);
3063                            }
3064                    }
3065    
3066                    return list;
3067            }
3068    
3069            /**
3070             * Removes all the document library file ranks from the database.
3071             *
3072             */
3073            @Override
3074            public void removeAll() {
3075                    for (DLFileRank dlFileRank : findAll()) {
3076                            remove(dlFileRank);
3077                    }
3078            }
3079    
3080            /**
3081             * Returns the number of document library file ranks.
3082             *
3083             * @return the number of document library file ranks
3084             */
3085            @Override
3086            public int countAll() {
3087                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3088                                    FINDER_ARGS_EMPTY, this);
3089    
3090                    if (count == null) {
3091                            Session session = null;
3092    
3093                            try {
3094                                    session = openSession();
3095    
3096                                    Query q = session.createQuery(_SQL_COUNT_DLFILERANK);
3097    
3098                                    count = (Long)q.uniqueResult();
3099    
3100                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3101                                            FINDER_ARGS_EMPTY, count);
3102                            }
3103                            catch (Exception e) {
3104                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3105                                            FINDER_ARGS_EMPTY);
3106    
3107                                    throw processException(e);
3108                            }
3109                            finally {
3110                                    closeSession(session);
3111                            }
3112                    }
3113    
3114                    return count.intValue();
3115            }
3116    
3117            @Override
3118            protected Set<String> getBadColumnNames() {
3119                    return _badColumnNames;
3120            }
3121    
3122            /**
3123             * Initializes the document library file rank persistence.
3124             */
3125            public void afterPropertiesSet() {
3126            }
3127    
3128            public void destroy() {
3129                    EntityCacheUtil.removeCache(DLFileRankImpl.class.getName());
3130                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3131                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3132                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3133            }
3134    
3135            private static final String _SQL_SELECT_DLFILERANK = "SELECT dlFileRank FROM DLFileRank dlFileRank";
3136            private static final String _SQL_SELECT_DLFILERANK_WHERE_PKS_IN = "SELECT dlFileRank FROM DLFileRank dlFileRank WHERE fileRankId IN (";
3137            private static final String _SQL_SELECT_DLFILERANK_WHERE = "SELECT dlFileRank FROM DLFileRank dlFileRank WHERE ";
3138            private static final String _SQL_COUNT_DLFILERANK = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank";
3139            private static final String _SQL_COUNT_DLFILERANK_WHERE = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank WHERE ";
3140            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileRank.";
3141            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileRank exists with the primary key ";
3142            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileRank exists with the key {";
3143            private static final Log _log = LogFactoryUtil.getLog(DLFileRankPersistenceImpl.class);
3144            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3145                                    "active"
3146                            });
3147            private static final DLFileRank _nullDLFileRank = new DLFileRankImpl() {
3148                            @Override
3149                            public Object clone() {
3150                                    return this;
3151                            }
3152    
3153                            @Override
3154                            public CacheModel<DLFileRank> toCacheModel() {
3155                                    return _nullDLFileRankCacheModel;
3156                            }
3157                    };
3158    
3159            private static final CacheModel<DLFileRank> _nullDLFileRankCacheModel = new CacheModel<DLFileRank>() {
3160                            @Override
3161                            public DLFileRank toEntityModel() {
3162                                    return _nullDLFileRank;
3163                            }
3164                    };
3165    }