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