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