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