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