001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.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                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2301                                                    _log.warn(
2302                                                            "DLFileRankPersistenceImpl.fetchByC_U_F(long, long, long, boolean) with parameters (" +
2303                                                            StringUtil.merge(finderArgs) +
2304                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
2305                                            }
2306    
2307                                            DLFileRank dlFileRank = list.get(0);
2308    
2309                                            result = dlFileRank;
2310    
2311                                            cacheResult(dlFileRank);
2312    
2313                                            if ((dlFileRank.getCompanyId() != companyId) ||
2314                                                            (dlFileRank.getUserId() != userId) ||
2315                                                            (dlFileRank.getFileEntryId() != fileEntryId)) {
2316                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
2317                                                            finderArgs, dlFileRank);
2318                                            }
2319                                    }
2320                            }
2321                            catch (Exception e) {
2322                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F,
2323                                            finderArgs);
2324    
2325                                    throw processException(e);
2326                            }
2327                            finally {
2328                                    closeSession(session);
2329                            }
2330                    }
2331    
2332                    if (result instanceof List<?>) {
2333                            return null;
2334                    }
2335                    else {
2336                            return (DLFileRank)result;
2337                    }
2338            }
2339    
2340            /**
2341             * Removes the document library file rank where companyId = &#63; and userId = &#63; and fileEntryId = &#63; from the database.
2342             *
2343             * @param companyId the company ID
2344             * @param userId the user ID
2345             * @param fileEntryId the file entry ID
2346             * @return the document library file rank that was removed
2347             * @throws SystemException if a system exception occurred
2348             */
2349            @Override
2350            public DLFileRank removeByC_U_F(long companyId, long userId,
2351                    long fileEntryId) throws NoSuchFileRankException, SystemException {
2352                    DLFileRank dlFileRank = findByC_U_F(companyId, userId, fileEntryId);
2353    
2354                    return remove(dlFileRank);
2355            }
2356    
2357            /**
2358             * Returns the number of document library file ranks where companyId = &#63; and userId = &#63; and fileEntryId = &#63;.
2359             *
2360             * @param companyId the company ID
2361             * @param userId the user ID
2362             * @param fileEntryId the file entry ID
2363             * @return the number of matching document library file ranks
2364             * @throws SystemException if a system exception occurred
2365             */
2366            @Override
2367            public int countByC_U_F(long companyId, long userId, long fileEntryId)
2368                    throws SystemException {
2369                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U_F;
2370    
2371                    Object[] finderArgs = new Object[] { companyId, userId, fileEntryId };
2372    
2373                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2374                                    this);
2375    
2376                    if (count == null) {
2377                            StringBundler query = new StringBundler(4);
2378    
2379                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2380    
2381                            query.append(_FINDER_COLUMN_C_U_F_COMPANYID_2);
2382    
2383                            query.append(_FINDER_COLUMN_C_U_F_USERID_2);
2384    
2385                            query.append(_FINDER_COLUMN_C_U_F_FILEENTRYID_2);
2386    
2387                            String sql = query.toString();
2388    
2389                            Session session = null;
2390    
2391                            try {
2392                                    session = openSession();
2393    
2394                                    Query q = session.createQuery(sql);
2395    
2396                                    QueryPos qPos = QueryPos.getInstance(q);
2397    
2398                                    qPos.add(companyId);
2399    
2400                                    qPos.add(userId);
2401    
2402                                    qPos.add(fileEntryId);
2403    
2404                                    count = (Long)q.uniqueResult();
2405    
2406                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2407                            }
2408                            catch (Exception e) {
2409                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2410    
2411                                    throw processException(e);
2412                            }
2413                            finally {
2414                                    closeSession(session);
2415                            }
2416                    }
2417    
2418                    return count.intValue();
2419            }
2420    
2421            private static final String _FINDER_COLUMN_C_U_F_COMPANYID_2 = "dlFileRank.companyId = ? AND ";
2422            private static final String _FINDER_COLUMN_C_U_F_USERID_2 = "dlFileRank.userId = ? AND ";
2423            private static final String _FINDER_COLUMN_C_U_F_FILEENTRYID_2 = "dlFileRank.fileEntryId = ?";
2424    
2425            public DLFileRankPersistenceImpl() {
2426                    setModelClass(DLFileRank.class);
2427            }
2428    
2429            /**
2430             * Caches the document library file rank in the entity cache if it is enabled.
2431             *
2432             * @param dlFileRank the document library file rank
2433             */
2434            @Override
2435            public void cacheResult(DLFileRank dlFileRank) {
2436                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2437                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
2438    
2439                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
2440                            new Object[] {
2441                                    dlFileRank.getCompanyId(), dlFileRank.getUserId(),
2442                                    dlFileRank.getFileEntryId()
2443                            }, dlFileRank);
2444    
2445                    dlFileRank.resetOriginalValues();
2446            }
2447    
2448            /**
2449             * Caches the document library file ranks in the entity cache if it is enabled.
2450             *
2451             * @param dlFileRanks the document library file ranks
2452             */
2453            @Override
2454            public void cacheResult(List<DLFileRank> dlFileRanks) {
2455                    for (DLFileRank dlFileRank : dlFileRanks) {
2456                            if (EntityCacheUtil.getResult(
2457                                                    DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2458                                                    DLFileRankImpl.class, dlFileRank.getPrimaryKey()) == null) {
2459                                    cacheResult(dlFileRank);
2460                            }
2461                            else {
2462                                    dlFileRank.resetOriginalValues();
2463                            }
2464                    }
2465            }
2466    
2467            /**
2468             * Clears the cache for all document library file ranks.
2469             *
2470             * <p>
2471             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2472             * </p>
2473             */
2474            @Override
2475            public void clearCache() {
2476                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2477                            CacheRegistryUtil.clear(DLFileRankImpl.class.getName());
2478                    }
2479    
2480                    EntityCacheUtil.clearCache(DLFileRankImpl.class.getName());
2481    
2482                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2483                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2484                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2485            }
2486    
2487            /**
2488             * Clears the cache for the document library file rank.
2489             *
2490             * <p>
2491             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2492             * </p>
2493             */
2494            @Override
2495            public void clearCache(DLFileRank dlFileRank) {
2496                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2497                            DLFileRankImpl.class, dlFileRank.getPrimaryKey());
2498    
2499                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2500                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2501    
2502                    clearUniqueFindersCache(dlFileRank);
2503            }
2504    
2505            @Override
2506            public void clearCache(List<DLFileRank> dlFileRanks) {
2507                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2508                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2509    
2510                    for (DLFileRank dlFileRank : dlFileRanks) {
2511                            EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2512                                    DLFileRankImpl.class, dlFileRank.getPrimaryKey());
2513    
2514                            clearUniqueFindersCache(dlFileRank);
2515                    }
2516            }
2517    
2518            protected void cacheUniqueFindersCache(DLFileRank dlFileRank) {
2519                    if (dlFileRank.isNew()) {
2520                            Object[] args = new Object[] {
2521                                            dlFileRank.getCompanyId(), dlFileRank.getUserId(),
2522                                            dlFileRank.getFileEntryId()
2523                                    };
2524    
2525                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F, args,
2526                                    Long.valueOf(1));
2527                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F, args,
2528                                    dlFileRank);
2529                    }
2530                    else {
2531                            DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
2532    
2533                            if ((dlFileRankModelImpl.getColumnBitmask() &
2534                                            FINDER_PATH_FETCH_BY_C_U_F.getColumnBitmask()) != 0) {
2535                                    Object[] args = new Object[] {
2536                                                    dlFileRank.getCompanyId(), dlFileRank.getUserId(),
2537                                                    dlFileRank.getFileEntryId()
2538                                            };
2539    
2540                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F, args,
2541                                            Long.valueOf(1));
2542                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F, args,
2543                                            dlFileRank);
2544                            }
2545                    }
2546            }
2547    
2548            protected void clearUniqueFindersCache(DLFileRank dlFileRank) {
2549                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
2550    
2551                    Object[] args = new Object[] {
2552                                    dlFileRank.getCompanyId(), dlFileRank.getUserId(),
2553                                    dlFileRank.getFileEntryId()
2554                            };
2555    
2556                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_F, args);
2557                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F, args);
2558    
2559                    if ((dlFileRankModelImpl.getColumnBitmask() &
2560                                    FINDER_PATH_FETCH_BY_C_U_F.getColumnBitmask()) != 0) {
2561                            args = new Object[] {
2562                                            dlFileRankModelImpl.getOriginalCompanyId(),
2563                                            dlFileRankModelImpl.getOriginalUserId(),
2564                                            dlFileRankModelImpl.getOriginalFileEntryId()
2565                                    };
2566    
2567                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_F, args);
2568                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F, args);
2569                    }
2570            }
2571    
2572            /**
2573             * Creates a new document library file rank with the primary key. Does not add the document library file rank to the database.
2574             *
2575             * @param fileRankId the primary key for the new document library file rank
2576             * @return the new document library file rank
2577             */
2578            @Override
2579            public DLFileRank create(long fileRankId) {
2580                    DLFileRank dlFileRank = new DLFileRankImpl();
2581    
2582                    dlFileRank.setNew(true);
2583                    dlFileRank.setPrimaryKey(fileRankId);
2584    
2585                    return dlFileRank;
2586            }
2587    
2588            /**
2589             * Removes the document library file rank with the primary key from the database. Also notifies the appropriate model listeners.
2590             *
2591             * @param fileRankId the primary key of the document library file rank
2592             * @return the document library file rank that was removed
2593             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
2594             * @throws SystemException if a system exception occurred
2595             */
2596            @Override
2597            public DLFileRank remove(long fileRankId)
2598                    throws NoSuchFileRankException, SystemException {
2599                    return remove((Serializable)fileRankId);
2600            }
2601    
2602            /**
2603             * Removes the document library file rank with the primary key from the database. Also notifies the appropriate model listeners.
2604             *
2605             * @param primaryKey the primary key of the document library file rank
2606             * @return the document library file rank that was removed
2607             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
2608             * @throws SystemException if a system exception occurred
2609             */
2610            @Override
2611            public DLFileRank remove(Serializable primaryKey)
2612                    throws NoSuchFileRankException, SystemException {
2613                    Session session = null;
2614    
2615                    try {
2616                            session = openSession();
2617    
2618                            DLFileRank dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
2619                                            primaryKey);
2620    
2621                            if (dlFileRank == null) {
2622                                    if (_log.isWarnEnabled()) {
2623                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2624                                    }
2625    
2626                                    throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2627                                            primaryKey);
2628                            }
2629    
2630                            return remove(dlFileRank);
2631                    }
2632                    catch (NoSuchFileRankException nsee) {
2633                            throw nsee;
2634                    }
2635                    catch (Exception e) {
2636                            throw processException(e);
2637                    }
2638                    finally {
2639                            closeSession(session);
2640                    }
2641            }
2642    
2643            @Override
2644            protected DLFileRank removeImpl(DLFileRank dlFileRank)
2645                    throws SystemException {
2646                    dlFileRank = toUnwrappedModel(dlFileRank);
2647    
2648                    Session session = null;
2649    
2650                    try {
2651                            session = openSession();
2652    
2653                            if (!session.contains(dlFileRank)) {
2654                                    dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
2655                                                    dlFileRank.getPrimaryKeyObj());
2656                            }
2657    
2658                            if (dlFileRank != null) {
2659                                    session.delete(dlFileRank);
2660                            }
2661                    }
2662                    catch (Exception e) {
2663                            throw processException(e);
2664                    }
2665                    finally {
2666                            closeSession(session);
2667                    }
2668    
2669                    if (dlFileRank != null) {
2670                            clearCache(dlFileRank);
2671                    }
2672    
2673                    return dlFileRank;
2674            }
2675    
2676            @Override
2677            public DLFileRank updateImpl(
2678                    com.liferay.portlet.documentlibrary.model.DLFileRank dlFileRank)
2679                    throws SystemException {
2680                    dlFileRank = toUnwrappedModel(dlFileRank);
2681    
2682                    boolean isNew = dlFileRank.isNew();
2683    
2684                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
2685    
2686                    Session session = null;
2687    
2688                    try {
2689                            session = openSession();
2690    
2691                            if (dlFileRank.isNew()) {
2692                                    session.save(dlFileRank);
2693    
2694                                    dlFileRank.setNew(false);
2695                            }
2696                            else {
2697                                    session.merge(dlFileRank);
2698                            }
2699                    }
2700                    catch (Exception e) {
2701                            throw processException(e);
2702                    }
2703                    finally {
2704                            closeSession(session);
2705                    }
2706    
2707                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2708    
2709                    if (isNew || !DLFileRankModelImpl.COLUMN_BITMASK_ENABLED) {
2710                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2711                    }
2712    
2713                    else {
2714                            if ((dlFileRankModelImpl.getColumnBitmask() &
2715                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2716                                    Object[] args = new Object[] {
2717                                                    dlFileRankModelImpl.getOriginalUserId()
2718                                            };
2719    
2720                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2721                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2722                                            args);
2723    
2724                                    args = new Object[] { dlFileRankModelImpl.getUserId() };
2725    
2726                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2727                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2728                                            args);
2729                            }
2730    
2731                            if ((dlFileRankModelImpl.getColumnBitmask() &
2732                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
2733                                    Object[] args = new Object[] {
2734                                                    dlFileRankModelImpl.getOriginalFileEntryId()
2735                                            };
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                                    args = new Object[] { dlFileRankModelImpl.getFileEntryId() };
2743    
2744                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
2745                                            args);
2746                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
2747                                            args);
2748                            }
2749    
2750                            if ((dlFileRankModelImpl.getColumnBitmask() &
2751                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
2752                                    Object[] args = new Object[] {
2753                                                    dlFileRankModelImpl.getOriginalGroupId(),
2754                                                    dlFileRankModelImpl.getOriginalUserId()
2755                                            };
2756    
2757                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
2758                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
2759                                            args);
2760    
2761                                    args = new Object[] {
2762                                                    dlFileRankModelImpl.getGroupId(),
2763                                                    dlFileRankModelImpl.getUserId()
2764                                            };
2765    
2766                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
2767                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
2768                                            args);
2769                            }
2770    
2771                            if ((dlFileRankModelImpl.getColumnBitmask() &
2772                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A.getColumnBitmask()) != 0) {
2773                                    Object[] args = new Object[] {
2774                                                    dlFileRankModelImpl.getOriginalGroupId(),
2775                                                    dlFileRankModelImpl.getOriginalUserId(),
2776                                                    dlFileRankModelImpl.getOriginalActive()
2777                                            };
2778    
2779                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_A, args);
2780                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A,
2781                                            args);
2782    
2783                                    args = new Object[] {
2784                                                    dlFileRankModelImpl.getGroupId(),
2785                                                    dlFileRankModelImpl.getUserId(),
2786                                                    dlFileRankModelImpl.getActive()
2787                                            };
2788    
2789                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_A, args);
2790                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A,
2791                                            args);
2792                            }
2793                    }
2794    
2795                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2796                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
2797    
2798                    clearUniqueFindersCache(dlFileRank);
2799                    cacheUniqueFindersCache(dlFileRank);
2800    
2801                    return dlFileRank;
2802            }
2803    
2804            protected DLFileRank toUnwrappedModel(DLFileRank dlFileRank) {
2805                    if (dlFileRank instanceof DLFileRankImpl) {
2806                            return dlFileRank;
2807                    }
2808    
2809                    DLFileRankImpl dlFileRankImpl = new DLFileRankImpl();
2810    
2811                    dlFileRankImpl.setNew(dlFileRank.isNew());
2812                    dlFileRankImpl.setPrimaryKey(dlFileRank.getPrimaryKey());
2813    
2814                    dlFileRankImpl.setFileRankId(dlFileRank.getFileRankId());
2815                    dlFileRankImpl.setGroupId(dlFileRank.getGroupId());
2816                    dlFileRankImpl.setCompanyId(dlFileRank.getCompanyId());
2817                    dlFileRankImpl.setUserId(dlFileRank.getUserId());
2818                    dlFileRankImpl.setCreateDate(dlFileRank.getCreateDate());
2819                    dlFileRankImpl.setFileEntryId(dlFileRank.getFileEntryId());
2820                    dlFileRankImpl.setActive(dlFileRank.isActive());
2821    
2822                    return dlFileRankImpl;
2823            }
2824    
2825            /**
2826             * Returns the document library file rank with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2827             *
2828             * @param primaryKey the primary key of the document library file rank
2829             * @return the document library file rank
2830             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
2831             * @throws SystemException if a system exception occurred
2832             */
2833            @Override
2834            public DLFileRank findByPrimaryKey(Serializable primaryKey)
2835                    throws NoSuchFileRankException, SystemException {
2836                    DLFileRank dlFileRank = fetchByPrimaryKey(primaryKey);
2837    
2838                    if (dlFileRank == null) {
2839                            if (_log.isWarnEnabled()) {
2840                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2841                            }
2842    
2843                            throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2844                                    primaryKey);
2845                    }
2846    
2847                    return dlFileRank;
2848            }
2849    
2850            /**
2851             * 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.
2852             *
2853             * @param fileRankId the primary key of the document library file rank
2854             * @return the document library file rank
2855             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
2856             * @throws SystemException if a system exception occurred
2857             */
2858            @Override
2859            public DLFileRank findByPrimaryKey(long fileRankId)
2860                    throws NoSuchFileRankException, SystemException {
2861                    return findByPrimaryKey((Serializable)fileRankId);
2862            }
2863    
2864            /**
2865             * Returns the document library file rank with the primary key or returns <code>null</code> if it could not be found.
2866             *
2867             * @param primaryKey the primary key of the document library file rank
2868             * @return the document library file rank, or <code>null</code> if a document library file rank with the primary key could not be found
2869             * @throws SystemException if a system exception occurred
2870             */
2871            @Override
2872            public DLFileRank fetchByPrimaryKey(Serializable primaryKey)
2873                    throws SystemException {
2874                    DLFileRank dlFileRank = (DLFileRank)EntityCacheUtil.getResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2875                                    DLFileRankImpl.class, primaryKey);
2876    
2877                    if (dlFileRank == _nullDLFileRank) {
2878                            return null;
2879                    }
2880    
2881                    if (dlFileRank == null) {
2882                            Session session = null;
2883    
2884                            try {
2885                                    session = openSession();
2886    
2887                                    dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
2888                                                    primaryKey);
2889    
2890                                    if (dlFileRank != null) {
2891                                            cacheResult(dlFileRank);
2892                                    }
2893                                    else {
2894                                            EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2895                                                    DLFileRankImpl.class, primaryKey, _nullDLFileRank);
2896                                    }
2897                            }
2898                            catch (Exception e) {
2899                                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2900                                            DLFileRankImpl.class, primaryKey);
2901    
2902                                    throw processException(e);
2903                            }
2904                            finally {
2905                                    closeSession(session);
2906                            }
2907                    }
2908    
2909                    return dlFileRank;
2910            }
2911    
2912            /**
2913             * Returns the document library file rank with the primary key or returns <code>null</code> if it could not be found.
2914             *
2915             * @param fileRankId the primary key of the document library file rank
2916             * @return the document library file rank, or <code>null</code> if a document library file rank with the primary key could not be found
2917             * @throws SystemException if a system exception occurred
2918             */
2919            @Override
2920            public DLFileRank fetchByPrimaryKey(long fileRankId)
2921                    throws SystemException {
2922                    return fetchByPrimaryKey((Serializable)fileRankId);
2923            }
2924    
2925            /**
2926             * Returns all the document library file ranks.
2927             *
2928             * @return the document library file ranks
2929             * @throws SystemException if a system exception occurred
2930             */
2931            @Override
2932            public List<DLFileRank> findAll() throws SystemException {
2933                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2934            }
2935    
2936            /**
2937             * Returns a range of all the document library file ranks.
2938             *
2939             * <p>
2940             * 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.
2941             * </p>
2942             *
2943             * @param start the lower bound of the range of document library file ranks
2944             * @param end the upper bound of the range of document library file ranks (not inclusive)
2945             * @return the range of document library file ranks
2946             * @throws SystemException if a system exception occurred
2947             */
2948            @Override
2949            public List<DLFileRank> findAll(int start, int end)
2950                    throws SystemException {
2951                    return findAll(start, end, null);
2952            }
2953    
2954            /**
2955             * Returns an ordered range of all the document library file ranks.
2956             *
2957             * <p>
2958             * 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.
2959             * </p>
2960             *
2961             * @param start the lower bound of the range of document library file ranks
2962             * @param end the upper bound of the range of document library file ranks (not inclusive)
2963             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2964             * @return the ordered range of document library file ranks
2965             * @throws SystemException if a system exception occurred
2966             */
2967            @Override
2968            public List<DLFileRank> findAll(int start, int end,
2969                    OrderByComparator orderByComparator) throws SystemException {
2970                    boolean pagination = true;
2971                    FinderPath finderPath = null;
2972                    Object[] finderArgs = null;
2973    
2974                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2975                                    (orderByComparator == null)) {
2976                            pagination = false;
2977                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2978                            finderArgs = FINDER_ARGS_EMPTY;
2979                    }
2980                    else {
2981                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2982                            finderArgs = new Object[] { start, end, orderByComparator };
2983                    }
2984    
2985                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
2986                                    finderArgs, this);
2987    
2988                    if (list == null) {
2989                            StringBundler query = null;
2990                            String sql = null;
2991    
2992                            if (orderByComparator != null) {
2993                                    query = new StringBundler(2 +
2994                                                    (orderByComparator.getOrderByFields().length * 3));
2995    
2996                                    query.append(_SQL_SELECT_DLFILERANK);
2997    
2998                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2999                                            orderByComparator);
3000    
3001                                    sql = query.toString();
3002                            }
3003                            else {
3004                                    sql = _SQL_SELECT_DLFILERANK;
3005    
3006                                    if (pagination) {
3007                                            sql = sql.concat(DLFileRankModelImpl.ORDER_BY_JPQL);
3008                                    }
3009                            }
3010    
3011                            Session session = null;
3012    
3013                            try {
3014                                    session = openSession();
3015    
3016                                    Query q = session.createQuery(sql);
3017    
3018                                    if (!pagination) {
3019                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
3020                                                            start, end, false);
3021    
3022                                            Collections.sort(list);
3023    
3024                                            list = new UnmodifiableList<DLFileRank>(list);
3025                                    }
3026                                    else {
3027                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
3028                                                            start, end);
3029                                    }
3030    
3031                                    cacheResult(list);
3032    
3033                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3034                            }
3035                            catch (Exception e) {
3036                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3037    
3038                                    throw processException(e);
3039                            }
3040                            finally {
3041                                    closeSession(session);
3042                            }
3043                    }
3044    
3045                    return list;
3046            }
3047    
3048            /**
3049             * Removes all the document library file ranks from the database.
3050             *
3051             * @throws SystemException if a system exception occurred
3052             */
3053            @Override
3054            public void removeAll() throws SystemException {
3055                    for (DLFileRank dlFileRank : findAll()) {
3056                            remove(dlFileRank);
3057                    }
3058            }
3059    
3060            /**
3061             * Returns the number of document library file ranks.
3062             *
3063             * @return the number of document library file ranks
3064             * @throws SystemException if a system exception occurred
3065             */
3066            @Override
3067            public int countAll() throws SystemException {
3068                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3069                                    FINDER_ARGS_EMPTY, this);
3070    
3071                    if (count == null) {
3072                            Session session = null;
3073    
3074                            try {
3075                                    session = openSession();
3076    
3077                                    Query q = session.createQuery(_SQL_COUNT_DLFILERANK);
3078    
3079                                    count = (Long)q.uniqueResult();
3080    
3081                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3082                                            FINDER_ARGS_EMPTY, count);
3083                            }
3084                            catch (Exception e) {
3085                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3086                                            FINDER_ARGS_EMPTY);
3087    
3088                                    throw processException(e);
3089                            }
3090                            finally {
3091                                    closeSession(session);
3092                            }
3093                    }
3094    
3095                    return count.intValue();
3096            }
3097    
3098            @Override
3099            protected Set<String> getBadColumnNames() {
3100                    return _badColumnNames;
3101            }
3102    
3103            /**
3104             * Initializes the document library file rank persistence.
3105             */
3106            public void afterPropertiesSet() {
3107                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3108                                            com.liferay.portal.util.PropsUtil.get(
3109                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileRank")));
3110    
3111                    if (listenerClassNames.length > 0) {
3112                            try {
3113                                    List<ModelListener<DLFileRank>> listenersList = new ArrayList<ModelListener<DLFileRank>>();
3114    
3115                                    for (String listenerClassName : listenerClassNames) {
3116                                            listenersList.add((ModelListener<DLFileRank>)InstanceFactory.newInstance(
3117                                                            getClassLoader(), listenerClassName));
3118                                    }
3119    
3120                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3121                            }
3122                            catch (Exception e) {
3123                                    _log.error(e);
3124                            }
3125                    }
3126            }
3127    
3128            public void destroy() {
3129                    EntityCacheUtil.removeCache(DLFileRankImpl.class.getName());
3130                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3131                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3132                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3133            }
3134    
3135            private static final String _SQL_SELECT_DLFILERANK = "SELECT dlFileRank FROM DLFileRank dlFileRank";
3136            private static final String _SQL_SELECT_DLFILERANK_WHERE = "SELECT dlFileRank FROM DLFileRank dlFileRank WHERE ";
3137            private static final String _SQL_COUNT_DLFILERANK = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank";
3138            private static final String _SQL_COUNT_DLFILERANK_WHERE = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank WHERE ";
3139            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileRank.";
3140            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileRank exists with the primary key ";
3141            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileRank exists with the key {";
3142            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3143            private static Log _log = LogFactoryUtil.getLog(DLFileRankPersistenceImpl.class);
3144            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3145                                    "active"
3146                            });
3147            private static DLFileRank _nullDLFileRank = new DLFileRankImpl() {
3148                            @Override
3149                            public Object clone() {
3150                                    return this;
3151                            }
3152    
3153                            @Override
3154                            public CacheModel<DLFileRank> toCacheModel() {
3155                                    return _nullDLFileRankCacheModel;
3156                            }
3157                    };
3158    
3159            private static CacheModel<DLFileRank> _nullDLFileRankCacheModel = new CacheModel<DLFileRank>() {
3160                            @Override
3161                            public DLFileRank toEntityModel() {
3162                                    return _nullDLFileRank;
3163                            }
3164                    };
3165    }