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