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