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