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