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