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.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.kernel.util.UnmodifiableList;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040    
041    import com.liferay.portlet.documentlibrary.NoSuchFileRankException;
042    import com.liferay.portlet.documentlibrary.model.DLFileRank;
043    import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
044    import com.liferay.portlet.documentlibrary.model.impl.DLFileRankModelImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the document library file rank service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see DLFileRankPersistence
061     * @see DLFileRankUtil
062     * @generated
063     */
064    public class DLFileRankPersistenceImpl extends BasePersistenceImpl<DLFileRank>
065            implements DLFileRankPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link DLFileRankUtil} to access the document library file rank persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = DLFileRankImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
077                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
080                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
083                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
086                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
088                            new String[] {
089                                    String.class.getName(),
090                                    
091                            Integer.class.getName(), Integer.class.getName(),
092                                    OrderByComparator.class.getName()
093                            });
094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
095                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
097                            new String[] { String.class.getName() },
098                            DLFileRankModelImpl.UUID_COLUMN_BITMASK |
099                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
100            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
101                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
103                            new String[] { String.class.getName() });
104    
105            /**
106             * Returns all the document library file ranks where uuid = &#63;.
107             *
108             * @param uuid the uuid
109             * @return the matching document library file ranks
110             * @throws SystemException if a system exception occurred
111             */
112            public List<DLFileRank> findByUuid(String uuid) throws SystemException {
113                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
114            }
115    
116            /**
117             * Returns a range of all the document library file ranks where uuid = &#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 uuid the uuid
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> findByUuid(String uuid, int start, int end)
130                    throws SystemException {
131                    return findByUuid(uuid, start, end, null);
132            }
133    
134            /**
135             * Returns an ordered range of all the document library file ranks where uuid = &#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 uuid the uuid
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> findByUuid(String uuid, 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_UUID;
158                            finderArgs = new Object[] { uuid };
159                    }
160                    else {
161                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
162                            finderArgs = new Object[] { uuid, 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 (!Validator.equals(uuid, dlFileRank.getUuid())) {
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                            boolean bindUuid = false;
192    
193                            if (uuid == null) {
194                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
195                            }
196                            else if (uuid.equals(StringPool.BLANK)) {
197                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
198                            }
199                            else {
200                                    bindUuid = true;
201    
202                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
203                            }
204    
205                            if (orderByComparator != null) {
206                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
207                                            orderByComparator);
208                            }
209                            else
210                             if (pagination) {
211                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
212                            }
213    
214                            String sql = query.toString();
215    
216                            Session session = null;
217    
218                            try {
219                                    session = openSession();
220    
221                                    Query q = session.createQuery(sql);
222    
223                                    QueryPos qPos = QueryPos.getInstance(q);
224    
225                                    if (bindUuid) {
226                                            qPos.add(uuid);
227                                    }
228    
229                                    if (!pagination) {
230                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
231                                                            start, end, false);
232    
233                                            Collections.sort(list);
234    
235                                            list = new UnmodifiableList<DLFileRank>(list);
236                                    }
237                                    else {
238                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
239                                                            start, end);
240                                    }
241    
242                                    cacheResult(list);
243    
244                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
245                            }
246                            catch (Exception e) {
247                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
248    
249                                    throw processException(e);
250                            }
251                            finally {
252                                    closeSession(session);
253                            }
254                    }
255    
256                    return list;
257            }
258    
259            /**
260             * Returns the first document library file rank in the ordered set where uuid = &#63;.
261             *
262             * @param uuid the uuid
263             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
264             * @return the first matching document library file rank
265             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
266             * @throws SystemException if a system exception occurred
267             */
268            public DLFileRank findByUuid_First(String uuid,
269                    OrderByComparator orderByComparator)
270                    throws NoSuchFileRankException, SystemException {
271                    DLFileRank dlFileRank = fetchByUuid_First(uuid, orderByComparator);
272    
273                    if (dlFileRank != null) {
274                            return dlFileRank;
275                    }
276    
277                    StringBundler msg = new StringBundler(4);
278    
279                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
280    
281                    msg.append("uuid=");
282                    msg.append(uuid);
283    
284                    msg.append(StringPool.CLOSE_CURLY_BRACE);
285    
286                    throw new NoSuchFileRankException(msg.toString());
287            }
288    
289            /**
290             * Returns the first document library file rank in the ordered set where uuid = &#63;.
291             *
292             * @param uuid the uuid
293             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
294             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
295             * @throws SystemException if a system exception occurred
296             */
297            public DLFileRank fetchByUuid_First(String uuid,
298                    OrderByComparator orderByComparator) throws SystemException {
299                    List<DLFileRank> list = findByUuid(uuid, 0, 1, orderByComparator);
300    
301                    if (!list.isEmpty()) {
302                            return list.get(0);
303                    }
304    
305                    return null;
306            }
307    
308            /**
309             * Returns the last document library file rank in the ordered set where uuid = &#63;.
310             *
311             * @param uuid the uuid
312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
313             * @return the last matching document library file rank
314             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
315             * @throws SystemException if a system exception occurred
316             */
317            public DLFileRank findByUuid_Last(String uuid,
318                    OrderByComparator orderByComparator)
319                    throws NoSuchFileRankException, SystemException {
320                    DLFileRank dlFileRank = fetchByUuid_Last(uuid, orderByComparator);
321    
322                    if (dlFileRank != null) {
323                            return dlFileRank;
324                    }
325    
326                    StringBundler msg = new StringBundler(4);
327    
328                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
329    
330                    msg.append("uuid=");
331                    msg.append(uuid);
332    
333                    msg.append(StringPool.CLOSE_CURLY_BRACE);
334    
335                    throw new NoSuchFileRankException(msg.toString());
336            }
337    
338            /**
339             * Returns the last document library file rank in the ordered set where uuid = &#63;.
340             *
341             * @param uuid the uuid
342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
343             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
344             * @throws SystemException if a system exception occurred
345             */
346            public DLFileRank fetchByUuid_Last(String uuid,
347                    OrderByComparator orderByComparator) throws SystemException {
348                    int count = countByUuid(uuid);
349    
350                    List<DLFileRank> list = findByUuid(uuid, count - 1, count,
351                                    orderByComparator);
352    
353                    if (!list.isEmpty()) {
354                            return list.get(0);
355                    }
356    
357                    return null;
358            }
359    
360            /**
361             * Returns the document library file ranks before and after the current document library file rank in the ordered set where uuid = &#63;.
362             *
363             * @param fileRankId the primary key of the current document library file rank
364             * @param uuid the uuid
365             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
366             * @return the previous, current, and next document library file rank
367             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
368             * @throws SystemException if a system exception occurred
369             */
370            public DLFileRank[] findByUuid_PrevAndNext(long fileRankId, String uuid,
371                    OrderByComparator orderByComparator)
372                    throws NoSuchFileRankException, SystemException {
373                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
374    
375                    Session session = null;
376    
377                    try {
378                            session = openSession();
379    
380                            DLFileRank[] array = new DLFileRankImpl[3];
381    
382                            array[0] = getByUuid_PrevAndNext(session, dlFileRank, uuid,
383                                            orderByComparator, true);
384    
385                            array[1] = dlFileRank;
386    
387                            array[2] = getByUuid_PrevAndNext(session, dlFileRank, uuid,
388                                            orderByComparator, false);
389    
390                            return array;
391                    }
392                    catch (Exception e) {
393                            throw processException(e);
394                    }
395                    finally {
396                            closeSession(session);
397                    }
398            }
399    
400            protected DLFileRank getByUuid_PrevAndNext(Session session,
401                    DLFileRank dlFileRank, String uuid,
402                    OrderByComparator orderByComparator, boolean previous) {
403                    StringBundler query = null;
404    
405                    if (orderByComparator != null) {
406                            query = new StringBundler(6 +
407                                            (orderByComparator.getOrderByFields().length * 6));
408                    }
409                    else {
410                            query = new StringBundler(3);
411                    }
412    
413                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
414    
415                    boolean bindUuid = false;
416    
417                    if (uuid == null) {
418                            query.append(_FINDER_COLUMN_UUID_UUID_1);
419                    }
420                    else if (uuid.equals(StringPool.BLANK)) {
421                            query.append(_FINDER_COLUMN_UUID_UUID_3);
422                    }
423                    else {
424                            bindUuid = true;
425    
426                            query.append(_FINDER_COLUMN_UUID_UUID_2);
427                    }
428    
429                    if (orderByComparator != null) {
430                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
431    
432                            if (orderByConditionFields.length > 0) {
433                                    query.append(WHERE_AND);
434                            }
435    
436                            for (int i = 0; i < orderByConditionFields.length; i++) {
437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
438                                    query.append(orderByConditionFields[i]);
439    
440                                    if ((i + 1) < orderByConditionFields.length) {
441                                            if (orderByComparator.isAscending() ^ previous) {
442                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
443                                            }
444                                            else {
445                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
446                                            }
447                                    }
448                                    else {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(WHERE_GREATER_THAN);
451                                            }
452                                            else {
453                                                    query.append(WHERE_LESSER_THAN);
454                                            }
455                                    }
456                            }
457    
458                            query.append(ORDER_BY_CLAUSE);
459    
460                            String[] orderByFields = orderByComparator.getOrderByFields();
461    
462                            for (int i = 0; i < orderByFields.length; i++) {
463                                    query.append(_ORDER_BY_ENTITY_ALIAS);
464                                    query.append(orderByFields[i]);
465    
466                                    if ((i + 1) < orderByFields.length) {
467                                            if (orderByComparator.isAscending() ^ previous) {
468                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
469                                            }
470                                            else {
471                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
472                                            }
473                                    }
474                                    else {
475                                            if (orderByComparator.isAscending() ^ previous) {
476                                                    query.append(ORDER_BY_ASC);
477                                            }
478                                            else {
479                                                    query.append(ORDER_BY_DESC);
480                                            }
481                                    }
482                            }
483                    }
484                    else {
485                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
486                    }
487    
488                    String sql = query.toString();
489    
490                    Query q = session.createQuery(sql);
491    
492                    q.setFirstResult(0);
493                    q.setMaxResults(2);
494    
495                    QueryPos qPos = QueryPos.getInstance(q);
496    
497                    if (bindUuid) {
498                            qPos.add(uuid);
499                    }
500    
501                    if (orderByComparator != null) {
502                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
503    
504                            for (Object value : values) {
505                                    qPos.add(value);
506                            }
507                    }
508    
509                    List<DLFileRank> list = q.list();
510    
511                    if (list.size() == 2) {
512                            return list.get(1);
513                    }
514                    else {
515                            return null;
516                    }
517            }
518    
519            /**
520             * Removes all the document library file ranks where uuid = &#63; from the database.
521             *
522             * @param uuid the uuid
523             * @throws SystemException if a system exception occurred
524             */
525            public void removeByUuid(String uuid) throws SystemException {
526                    for (DLFileRank dlFileRank : findByUuid(uuid, QueryUtil.ALL_POS,
527                                    QueryUtil.ALL_POS, null)) {
528                            remove(dlFileRank);
529                    }
530            }
531    
532            /**
533             * Returns the number of document library file ranks where uuid = &#63;.
534             *
535             * @param uuid the uuid
536             * @return the number of matching document library file ranks
537             * @throws SystemException if a system exception occurred
538             */
539            public int countByUuid(String uuid) throws SystemException {
540                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
541    
542                    Object[] finderArgs = new Object[] { uuid };
543    
544                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
545                                    this);
546    
547                    if (count == null) {
548                            StringBundler query = new StringBundler(2);
549    
550                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
551    
552                            boolean bindUuid = false;
553    
554                            if (uuid == null) {
555                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
556                            }
557                            else if (uuid.equals(StringPool.BLANK)) {
558                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
559                            }
560                            else {
561                                    bindUuid = true;
562    
563                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
564                            }
565    
566                            String sql = query.toString();
567    
568                            Session session = null;
569    
570                            try {
571                                    session = openSession();
572    
573                                    Query q = session.createQuery(sql);
574    
575                                    QueryPos qPos = QueryPos.getInstance(q);
576    
577                                    if (bindUuid) {
578                                            qPos.add(uuid);
579                                    }
580    
581                                    count = (Long)q.uniqueResult();
582    
583                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
584                            }
585                            catch (Exception e) {
586                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
587    
588                                    throw processException(e);
589                            }
590                            finally {
591                                    closeSession(session);
592                            }
593                    }
594    
595                    return count.intValue();
596            }
597    
598            private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFileRank.uuid IS NULL";
599            private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFileRank.uuid = ?";
600            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFileRank.uuid IS NULL OR dlFileRank.uuid = '')";
601            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
602                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
603                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
604                            new String[] { String.class.getName(), Long.class.getName() },
605                            DLFileRankModelImpl.UUID_COLUMN_BITMASK |
606                            DLFileRankModelImpl.GROUPID_COLUMN_BITMASK);
607            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
608                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
609                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
610                            new String[] { String.class.getName(), Long.class.getName() });
611    
612            /**
613             * Returns the document library file rank where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFileRankException} if it could not be found.
614             *
615             * @param uuid the uuid
616             * @param groupId the group ID
617             * @return the matching document library file rank
618             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
619             * @throws SystemException if a system exception occurred
620             */
621            public DLFileRank findByUUID_G(String uuid, long groupId)
622                    throws NoSuchFileRankException, SystemException {
623                    DLFileRank dlFileRank = fetchByUUID_G(uuid, groupId);
624    
625                    if (dlFileRank == null) {
626                            StringBundler msg = new StringBundler(6);
627    
628                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
629    
630                            msg.append("uuid=");
631                            msg.append(uuid);
632    
633                            msg.append(", groupId=");
634                            msg.append(groupId);
635    
636                            msg.append(StringPool.CLOSE_CURLY_BRACE);
637    
638                            if (_log.isWarnEnabled()) {
639                                    _log.warn(msg.toString());
640                            }
641    
642                            throw new NoSuchFileRankException(msg.toString());
643                    }
644    
645                    return dlFileRank;
646            }
647    
648            /**
649             * Returns the document library file rank where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
650             *
651             * @param uuid the uuid
652             * @param groupId the group ID
653             * @return the matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
654             * @throws SystemException if a system exception occurred
655             */
656            public DLFileRank fetchByUUID_G(String uuid, long groupId)
657                    throws SystemException {
658                    return fetchByUUID_G(uuid, groupId, true);
659            }
660    
661            /**
662             * Returns the document library file rank where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
663             *
664             * @param uuid the uuid
665             * @param groupId the group ID
666             * @param retrieveFromCache whether to use the finder cache
667             * @return the matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
668             * @throws SystemException if a system exception occurred
669             */
670            public DLFileRank fetchByUUID_G(String uuid, long groupId,
671                    boolean retrieveFromCache) throws SystemException {
672                    Object[] finderArgs = new Object[] { uuid, groupId };
673    
674                    Object result = null;
675    
676                    if (retrieveFromCache) {
677                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
678                                            finderArgs, this);
679                    }
680    
681                    if (result instanceof DLFileRank) {
682                            DLFileRank dlFileRank = (DLFileRank)result;
683    
684                            if (!Validator.equals(uuid, dlFileRank.getUuid()) ||
685                                            (groupId != dlFileRank.getGroupId())) {
686                                    result = null;
687                            }
688                    }
689    
690                    if (result == null) {
691                            StringBundler query = new StringBundler(4);
692    
693                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
694    
695                            boolean bindUuid = false;
696    
697                            if (uuid == null) {
698                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
699                            }
700                            else if (uuid.equals(StringPool.BLANK)) {
701                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
702                            }
703                            else {
704                                    bindUuid = true;
705    
706                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
707                            }
708    
709                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
710    
711                            String sql = query.toString();
712    
713                            Session session = null;
714    
715                            try {
716                                    session = openSession();
717    
718                                    Query q = session.createQuery(sql);
719    
720                                    QueryPos qPos = QueryPos.getInstance(q);
721    
722                                    if (bindUuid) {
723                                            qPos.add(uuid);
724                                    }
725    
726                                    qPos.add(groupId);
727    
728                                    List<DLFileRank> list = q.list();
729    
730                                    if (list.isEmpty()) {
731                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
732                                                    finderArgs, list);
733                                    }
734                                    else {
735                                            DLFileRank dlFileRank = list.get(0);
736    
737                                            result = dlFileRank;
738    
739                                            cacheResult(dlFileRank);
740    
741                                            if ((dlFileRank.getUuid() == null) ||
742                                                            !dlFileRank.getUuid().equals(uuid) ||
743                                                            (dlFileRank.getGroupId() != groupId)) {
744                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
745                                                            finderArgs, dlFileRank);
746                                            }
747                                    }
748                            }
749                            catch (Exception e) {
750                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
751                                            finderArgs);
752    
753                                    throw processException(e);
754                            }
755                            finally {
756                                    closeSession(session);
757                            }
758                    }
759    
760                    if (result instanceof List<?>) {
761                            return null;
762                    }
763                    else {
764                            return (DLFileRank)result;
765                    }
766            }
767    
768            /**
769             * Removes the document library file rank where uuid = &#63; and groupId = &#63; from the database.
770             *
771             * @param uuid the uuid
772             * @param groupId the group ID
773             * @return the document library file rank that was removed
774             * @throws SystemException if a system exception occurred
775             */
776            public DLFileRank removeByUUID_G(String uuid, long groupId)
777                    throws NoSuchFileRankException, SystemException {
778                    DLFileRank dlFileRank = findByUUID_G(uuid, groupId);
779    
780                    return remove(dlFileRank);
781            }
782    
783            /**
784             * Returns the number of document library file ranks where uuid = &#63; and groupId = &#63;.
785             *
786             * @param uuid the uuid
787             * @param groupId the group ID
788             * @return the number of matching document library file ranks
789             * @throws SystemException if a system exception occurred
790             */
791            public int countByUUID_G(String uuid, long groupId)
792                    throws SystemException {
793                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
794    
795                    Object[] finderArgs = new Object[] { uuid, groupId };
796    
797                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
798                                    this);
799    
800                    if (count == null) {
801                            StringBundler query = new StringBundler(3);
802    
803                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
804    
805                            boolean bindUuid = false;
806    
807                            if (uuid == null) {
808                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
809                            }
810                            else if (uuid.equals(StringPool.BLANK)) {
811                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
812                            }
813                            else {
814                                    bindUuid = true;
815    
816                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
817                            }
818    
819                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
820    
821                            String sql = query.toString();
822    
823                            Session session = null;
824    
825                            try {
826                                    session = openSession();
827    
828                                    Query q = session.createQuery(sql);
829    
830                                    QueryPos qPos = QueryPos.getInstance(q);
831    
832                                    if (bindUuid) {
833                                            qPos.add(uuid);
834                                    }
835    
836                                    qPos.add(groupId);
837    
838                                    count = (Long)q.uniqueResult();
839    
840                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
841                            }
842                            catch (Exception e) {
843                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
844    
845                                    throw processException(e);
846                            }
847                            finally {
848                                    closeSession(session);
849                            }
850                    }
851    
852                    return count.intValue();
853            }
854    
855            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "dlFileRank.uuid IS NULL AND ";
856            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "dlFileRank.uuid = ? AND ";
857            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(dlFileRank.uuid IS NULL OR dlFileRank.uuid = '') AND ";
858            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "dlFileRank.groupId = ?";
859            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
860                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
861                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
862                            new String[] {
863                                    String.class.getName(), Long.class.getName(),
864                                    
865                            Integer.class.getName(), Integer.class.getName(),
866                                    OrderByComparator.class.getName()
867                            });
868            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
869                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
870                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
871                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
872                            new String[] { String.class.getName(), Long.class.getName() },
873                            DLFileRankModelImpl.UUID_COLUMN_BITMASK |
874                            DLFileRankModelImpl.COMPANYID_COLUMN_BITMASK |
875                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
876            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
877                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
878                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
879                            new String[] { String.class.getName(), Long.class.getName() });
880    
881            /**
882             * Returns all the document library file ranks where uuid = &#63; and companyId = &#63;.
883             *
884             * @param uuid the uuid
885             * @param companyId the company ID
886             * @return the matching document library file ranks
887             * @throws SystemException if a system exception occurred
888             */
889            public List<DLFileRank> findByUuid_C(String uuid, long companyId)
890                    throws SystemException {
891                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
892                            QueryUtil.ALL_POS, null);
893            }
894    
895            /**
896             * Returns a range of all the document library file ranks where uuid = &#63; and companyId = &#63;.
897             *
898             * <p>
899             * 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.
900             * </p>
901             *
902             * @param uuid the uuid
903             * @param companyId the company ID
904             * @param start the lower bound of the range of document library file ranks
905             * @param end the upper bound of the range of document library file ranks (not inclusive)
906             * @return the range of matching document library file ranks
907             * @throws SystemException if a system exception occurred
908             */
909            public List<DLFileRank> findByUuid_C(String uuid, long companyId,
910                    int start, int end) throws SystemException {
911                    return findByUuid_C(uuid, companyId, start, end, null);
912            }
913    
914            /**
915             * Returns an ordered range of all the document library file ranks where uuid = &#63; and companyId = &#63;.
916             *
917             * <p>
918             * 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.
919             * </p>
920             *
921             * @param uuid the uuid
922             * @param companyId the company ID
923             * @param start the lower bound of the range of document library file ranks
924             * @param end the upper bound of the range of document library file ranks (not inclusive)
925             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
926             * @return the ordered range of matching document library file ranks
927             * @throws SystemException if a system exception occurred
928             */
929            public List<DLFileRank> findByUuid_C(String uuid, long companyId,
930                    int start, int end, OrderByComparator orderByComparator)
931                    throws SystemException {
932                    boolean pagination = true;
933                    FinderPath finderPath = null;
934                    Object[] finderArgs = null;
935    
936                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
937                                    (orderByComparator == null)) {
938                            pagination = false;
939                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
940                            finderArgs = new Object[] { uuid, companyId };
941                    }
942                    else {
943                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
944                            finderArgs = new Object[] {
945                                            uuid, companyId,
946                                            
947                                            start, end, orderByComparator
948                                    };
949                    }
950    
951                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
952                                    finderArgs, this);
953    
954                    if ((list != null) && !list.isEmpty()) {
955                            for (DLFileRank dlFileRank : list) {
956                                    if (!Validator.equals(uuid, dlFileRank.getUuid()) ||
957                                                    (companyId != dlFileRank.getCompanyId())) {
958                                            list = null;
959    
960                                            break;
961                                    }
962                            }
963                    }
964    
965                    if (list == null) {
966                            StringBundler query = null;
967    
968                            if (orderByComparator != null) {
969                                    query = new StringBundler(4 +
970                                                    (orderByComparator.getOrderByFields().length * 3));
971                            }
972                            else {
973                                    query = new StringBundler(4);
974                            }
975    
976                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
977    
978                            boolean bindUuid = false;
979    
980                            if (uuid == null) {
981                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
982                            }
983                            else if (uuid.equals(StringPool.BLANK)) {
984                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
985                            }
986                            else {
987                                    bindUuid = true;
988    
989                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
990                            }
991    
992                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
993    
994                            if (orderByComparator != null) {
995                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
996                                            orderByComparator);
997                            }
998                            else
999                             if (pagination) {
1000                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1001                            }
1002    
1003                            String sql = query.toString();
1004    
1005                            Session session = null;
1006    
1007                            try {
1008                                    session = openSession();
1009    
1010                                    Query q = session.createQuery(sql);
1011    
1012                                    QueryPos qPos = QueryPos.getInstance(q);
1013    
1014                                    if (bindUuid) {
1015                                            qPos.add(uuid);
1016                                    }
1017    
1018                                    qPos.add(companyId);
1019    
1020                                    if (!pagination) {
1021                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1022                                                            start, end, false);
1023    
1024                                            Collections.sort(list);
1025    
1026                                            list = new UnmodifiableList<DLFileRank>(list);
1027                                    }
1028                                    else {
1029                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1030                                                            start, end);
1031                                    }
1032    
1033                                    cacheResult(list);
1034    
1035                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1036                            }
1037                            catch (Exception e) {
1038                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1039    
1040                                    throw processException(e);
1041                            }
1042                            finally {
1043                                    closeSession(session);
1044                            }
1045                    }
1046    
1047                    return list;
1048            }
1049    
1050            /**
1051             * Returns the first document library file rank in the ordered set where uuid = &#63; and companyId = &#63;.
1052             *
1053             * @param uuid the uuid
1054             * @param companyId the company ID
1055             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1056             * @return the first matching document library file rank
1057             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
1058             * @throws SystemException if a system exception occurred
1059             */
1060            public DLFileRank findByUuid_C_First(String uuid, long companyId,
1061                    OrderByComparator orderByComparator)
1062                    throws NoSuchFileRankException, SystemException {
1063                    DLFileRank dlFileRank = fetchByUuid_C_First(uuid, companyId,
1064                                    orderByComparator);
1065    
1066                    if (dlFileRank != null) {
1067                            return dlFileRank;
1068                    }
1069    
1070                    StringBundler msg = new StringBundler(6);
1071    
1072                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1073    
1074                    msg.append("uuid=");
1075                    msg.append(uuid);
1076    
1077                    msg.append(", companyId=");
1078                    msg.append(companyId);
1079    
1080                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1081    
1082                    throw new NoSuchFileRankException(msg.toString());
1083            }
1084    
1085            /**
1086             * Returns the first document library file rank in the ordered set where uuid = &#63; and companyId = &#63;.
1087             *
1088             * @param uuid the uuid
1089             * @param companyId the company ID
1090             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1091             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1092             * @throws SystemException if a system exception occurred
1093             */
1094            public DLFileRank fetchByUuid_C_First(String uuid, long companyId,
1095                    OrderByComparator orderByComparator) throws SystemException {
1096                    List<DLFileRank> list = findByUuid_C(uuid, companyId, 0, 1,
1097                                    orderByComparator);
1098    
1099                    if (!list.isEmpty()) {
1100                            return list.get(0);
1101                    }
1102    
1103                    return null;
1104            }
1105    
1106            /**
1107             * Returns the last document library file rank in the ordered set where uuid = &#63; and companyId = &#63;.
1108             *
1109             * @param uuid the uuid
1110             * @param companyId the company ID
1111             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1112             * @return the last matching document library file rank
1113             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
1114             * @throws SystemException if a system exception occurred
1115             */
1116            public DLFileRank findByUuid_C_Last(String uuid, long companyId,
1117                    OrderByComparator orderByComparator)
1118                    throws NoSuchFileRankException, SystemException {
1119                    DLFileRank dlFileRank = fetchByUuid_C_Last(uuid, companyId,
1120                                    orderByComparator);
1121    
1122                    if (dlFileRank != null) {
1123                            return dlFileRank;
1124                    }
1125    
1126                    StringBundler msg = new StringBundler(6);
1127    
1128                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1129    
1130                    msg.append("uuid=");
1131                    msg.append(uuid);
1132    
1133                    msg.append(", companyId=");
1134                    msg.append(companyId);
1135    
1136                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1137    
1138                    throw new NoSuchFileRankException(msg.toString());
1139            }
1140    
1141            /**
1142             * Returns the last document library file rank in the ordered set where uuid = &#63; and companyId = &#63;.
1143             *
1144             * @param uuid the uuid
1145             * @param companyId the company ID
1146             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1147             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1148             * @throws SystemException if a system exception occurred
1149             */
1150            public DLFileRank fetchByUuid_C_Last(String uuid, long companyId,
1151                    OrderByComparator orderByComparator) throws SystemException {
1152                    int count = countByUuid_C(uuid, companyId);
1153    
1154                    List<DLFileRank> list = findByUuid_C(uuid, companyId, count - 1, count,
1155                                    orderByComparator);
1156    
1157                    if (!list.isEmpty()) {
1158                            return list.get(0);
1159                    }
1160    
1161                    return null;
1162            }
1163    
1164            /**
1165             * Returns the document library file ranks before and after the current document library file rank in the ordered set where uuid = &#63; and companyId = &#63;.
1166             *
1167             * @param fileRankId the primary key of the current document library file rank
1168             * @param uuid the uuid
1169             * @param companyId the company ID
1170             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1171             * @return the previous, current, and next document library file rank
1172             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
1173             * @throws SystemException if a system exception occurred
1174             */
1175            public DLFileRank[] findByUuid_C_PrevAndNext(long fileRankId, String uuid,
1176                    long companyId, OrderByComparator orderByComparator)
1177                    throws NoSuchFileRankException, SystemException {
1178                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1179    
1180                    Session session = null;
1181    
1182                    try {
1183                            session = openSession();
1184    
1185                            DLFileRank[] array = new DLFileRankImpl[3];
1186    
1187                            array[0] = getByUuid_C_PrevAndNext(session, dlFileRank, uuid,
1188                                            companyId, orderByComparator, true);
1189    
1190                            array[1] = dlFileRank;
1191    
1192                            array[2] = getByUuid_C_PrevAndNext(session, dlFileRank, uuid,
1193                                            companyId, orderByComparator, false);
1194    
1195                            return array;
1196                    }
1197                    catch (Exception e) {
1198                            throw processException(e);
1199                    }
1200                    finally {
1201                            closeSession(session);
1202                    }
1203            }
1204    
1205            protected DLFileRank getByUuid_C_PrevAndNext(Session session,
1206                    DLFileRank dlFileRank, String uuid, long companyId,
1207                    OrderByComparator orderByComparator, boolean previous) {
1208                    StringBundler query = null;
1209    
1210                    if (orderByComparator != null) {
1211                            query = new StringBundler(6 +
1212                                            (orderByComparator.getOrderByFields().length * 6));
1213                    }
1214                    else {
1215                            query = new StringBundler(3);
1216                    }
1217    
1218                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1219    
1220                    boolean bindUuid = false;
1221    
1222                    if (uuid == null) {
1223                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1224                    }
1225                    else if (uuid.equals(StringPool.BLANK)) {
1226                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1227                    }
1228                    else {
1229                            bindUuid = true;
1230    
1231                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1232                    }
1233    
1234                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1235    
1236                    if (orderByComparator != null) {
1237                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1238    
1239                            if (orderByConditionFields.length > 0) {
1240                                    query.append(WHERE_AND);
1241                            }
1242    
1243                            for (int i = 0; i < orderByConditionFields.length; i++) {
1244                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1245                                    query.append(orderByConditionFields[i]);
1246    
1247                                    if ((i + 1) < orderByConditionFields.length) {
1248                                            if (orderByComparator.isAscending() ^ previous) {
1249                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1250                                            }
1251                                            else {
1252                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1253                                            }
1254                                    }
1255                                    else {
1256                                            if (orderByComparator.isAscending() ^ previous) {
1257                                                    query.append(WHERE_GREATER_THAN);
1258                                            }
1259                                            else {
1260                                                    query.append(WHERE_LESSER_THAN);
1261                                            }
1262                                    }
1263                            }
1264    
1265                            query.append(ORDER_BY_CLAUSE);
1266    
1267                            String[] orderByFields = orderByComparator.getOrderByFields();
1268    
1269                            for (int i = 0; i < orderByFields.length; i++) {
1270                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1271                                    query.append(orderByFields[i]);
1272    
1273                                    if ((i + 1) < orderByFields.length) {
1274                                            if (orderByComparator.isAscending() ^ previous) {
1275                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1276                                            }
1277                                            else {
1278                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1279                                            }
1280                                    }
1281                                    else {
1282                                            if (orderByComparator.isAscending() ^ previous) {
1283                                                    query.append(ORDER_BY_ASC);
1284                                            }
1285                                            else {
1286                                                    query.append(ORDER_BY_DESC);
1287                                            }
1288                                    }
1289                            }
1290                    }
1291                    else {
1292                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1293                    }
1294    
1295                    String sql = query.toString();
1296    
1297                    Query q = session.createQuery(sql);
1298    
1299                    q.setFirstResult(0);
1300                    q.setMaxResults(2);
1301    
1302                    QueryPos qPos = QueryPos.getInstance(q);
1303    
1304                    if (bindUuid) {
1305                            qPos.add(uuid);
1306                    }
1307    
1308                    qPos.add(companyId);
1309    
1310                    if (orderByComparator != null) {
1311                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
1312    
1313                            for (Object value : values) {
1314                                    qPos.add(value);
1315                            }
1316                    }
1317    
1318                    List<DLFileRank> list = q.list();
1319    
1320                    if (list.size() == 2) {
1321                            return list.get(1);
1322                    }
1323                    else {
1324                            return null;
1325                    }
1326            }
1327    
1328            /**
1329             * Removes all the document library file ranks where uuid = &#63; and companyId = &#63; from the database.
1330             *
1331             * @param uuid the uuid
1332             * @param companyId the company ID
1333             * @throws SystemException if a system exception occurred
1334             */
1335            public void removeByUuid_C(String uuid, long companyId)
1336                    throws SystemException {
1337                    for (DLFileRank dlFileRank : findByUuid_C(uuid, companyId,
1338                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1339                            remove(dlFileRank);
1340                    }
1341            }
1342    
1343            /**
1344             * Returns the number of document library file ranks where uuid = &#63; and companyId = &#63;.
1345             *
1346             * @param uuid the uuid
1347             * @param companyId the company ID
1348             * @return the number of matching document library file ranks
1349             * @throws SystemException if a system exception occurred
1350             */
1351            public int countByUuid_C(String uuid, long companyId)
1352                    throws SystemException {
1353                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1354    
1355                    Object[] finderArgs = new Object[] { uuid, companyId };
1356    
1357                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1358                                    this);
1359    
1360                    if (count == null) {
1361                            StringBundler query = new StringBundler(3);
1362    
1363                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
1364    
1365                            boolean bindUuid = false;
1366    
1367                            if (uuid == null) {
1368                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1369                            }
1370                            else if (uuid.equals(StringPool.BLANK)) {
1371                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1372                            }
1373                            else {
1374                                    bindUuid = true;
1375    
1376                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1377                            }
1378    
1379                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1380    
1381                            String sql = query.toString();
1382    
1383                            Session session = null;
1384    
1385                            try {
1386                                    session = openSession();
1387    
1388                                    Query q = session.createQuery(sql);
1389    
1390                                    QueryPos qPos = QueryPos.getInstance(q);
1391    
1392                                    if (bindUuid) {
1393                                            qPos.add(uuid);
1394                                    }
1395    
1396                                    qPos.add(companyId);
1397    
1398                                    count = (Long)q.uniqueResult();
1399    
1400                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1401                            }
1402                            catch (Exception e) {
1403                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1404    
1405                                    throw processException(e);
1406                            }
1407                            finally {
1408                                    closeSession(session);
1409                            }
1410                    }
1411    
1412                    return count.intValue();
1413            }
1414    
1415            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "dlFileRank.uuid IS NULL AND ";
1416            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "dlFileRank.uuid = ? AND ";
1417            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(dlFileRank.uuid IS NULL OR dlFileRank.uuid = '') AND ";
1418            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "dlFileRank.companyId = ?";
1419            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1420                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
1421                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1422                            new String[] {
1423                                    Long.class.getName(),
1424                                    
1425                            Integer.class.getName(), Integer.class.getName(),
1426                                    OrderByComparator.class.getName()
1427                            });
1428            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1429                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1430                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
1431                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1432                            new String[] { Long.class.getName() },
1433                            DLFileRankModelImpl.USERID_COLUMN_BITMASK |
1434                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
1435            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1436                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
1437                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1438                            new String[] { Long.class.getName() });
1439    
1440            /**
1441             * Returns all the document library file ranks where userId = &#63;.
1442             *
1443             * @param userId the user ID
1444             * @return the matching document library file ranks
1445             * @throws SystemException if a system exception occurred
1446             */
1447            public List<DLFileRank> findByUserId(long userId) throws SystemException {
1448                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1449            }
1450    
1451            /**
1452             * Returns a range of all the document library file ranks where userId = &#63;.
1453             *
1454             * <p>
1455             * 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.
1456             * </p>
1457             *
1458             * @param userId the user ID
1459             * @param start the lower bound of the range of document library file ranks
1460             * @param end the upper bound of the range of document library file ranks (not inclusive)
1461             * @return the range of matching document library file ranks
1462             * @throws SystemException if a system exception occurred
1463             */
1464            public List<DLFileRank> findByUserId(long userId, int start, int end)
1465                    throws SystemException {
1466                    return findByUserId(userId, start, end, null);
1467            }
1468    
1469            /**
1470             * Returns an ordered range of all the document library file ranks where userId = &#63;.
1471             *
1472             * <p>
1473             * 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.
1474             * </p>
1475             *
1476             * @param userId the user ID
1477             * @param start the lower bound of the range of document library file ranks
1478             * @param end the upper bound of the range of document library file ranks (not inclusive)
1479             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1480             * @return the ordered range of matching document library file ranks
1481             * @throws SystemException if a system exception occurred
1482             */
1483            public List<DLFileRank> findByUserId(long userId, int start, int end,
1484                    OrderByComparator orderByComparator) throws SystemException {
1485                    boolean pagination = true;
1486                    FinderPath finderPath = null;
1487                    Object[] finderArgs = null;
1488    
1489                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1490                                    (orderByComparator == null)) {
1491                            pagination = false;
1492                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1493                            finderArgs = new Object[] { userId };
1494                    }
1495                    else {
1496                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1497                            finderArgs = new Object[] { userId, start, end, orderByComparator };
1498                    }
1499    
1500                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
1501                                    finderArgs, this);
1502    
1503                    if ((list != null) && !list.isEmpty()) {
1504                            for (DLFileRank dlFileRank : list) {
1505                                    if ((userId != dlFileRank.getUserId())) {
1506                                            list = null;
1507    
1508                                            break;
1509                                    }
1510                            }
1511                    }
1512    
1513                    if (list == null) {
1514                            StringBundler query = null;
1515    
1516                            if (orderByComparator != null) {
1517                                    query = new StringBundler(3 +
1518                                                    (orderByComparator.getOrderByFields().length * 3));
1519                            }
1520                            else {
1521                                    query = new StringBundler(3);
1522                            }
1523    
1524                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
1525    
1526                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1527    
1528                            if (orderByComparator != null) {
1529                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1530                                            orderByComparator);
1531                            }
1532                            else
1533                             if (pagination) {
1534                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1535                            }
1536    
1537                            String sql = query.toString();
1538    
1539                            Session session = null;
1540    
1541                            try {
1542                                    session = openSession();
1543    
1544                                    Query q = session.createQuery(sql);
1545    
1546                                    QueryPos qPos = QueryPos.getInstance(q);
1547    
1548                                    qPos.add(userId);
1549    
1550                                    if (!pagination) {
1551                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1552                                                            start, end, false);
1553    
1554                                            Collections.sort(list);
1555    
1556                                            list = new UnmodifiableList<DLFileRank>(list);
1557                                    }
1558                                    else {
1559                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1560                                                            start, end);
1561                                    }
1562    
1563                                    cacheResult(list);
1564    
1565                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1566                            }
1567                            catch (Exception e) {
1568                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1569    
1570                                    throw processException(e);
1571                            }
1572                            finally {
1573                                    closeSession(session);
1574                            }
1575                    }
1576    
1577                    return list;
1578            }
1579    
1580            /**
1581             * Returns the first document library file rank in the ordered set where userId = &#63;.
1582             *
1583             * @param userId the user ID
1584             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1585             * @return the first matching document library file rank
1586             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
1587             * @throws SystemException if a system exception occurred
1588             */
1589            public DLFileRank findByUserId_First(long userId,
1590                    OrderByComparator orderByComparator)
1591                    throws NoSuchFileRankException, SystemException {
1592                    DLFileRank dlFileRank = fetchByUserId_First(userId, orderByComparator);
1593    
1594                    if (dlFileRank != null) {
1595                            return dlFileRank;
1596                    }
1597    
1598                    StringBundler msg = new StringBundler(4);
1599    
1600                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1601    
1602                    msg.append("userId=");
1603                    msg.append(userId);
1604    
1605                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1606    
1607                    throw new NoSuchFileRankException(msg.toString());
1608            }
1609    
1610            /**
1611             * Returns the first document library file rank in the ordered set where userId = &#63;.
1612             *
1613             * @param userId the user ID
1614             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1615             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1616             * @throws SystemException if a system exception occurred
1617             */
1618            public DLFileRank fetchByUserId_First(long userId,
1619                    OrderByComparator orderByComparator) throws SystemException {
1620                    List<DLFileRank> list = findByUserId(userId, 0, 1, orderByComparator);
1621    
1622                    if (!list.isEmpty()) {
1623                            return list.get(0);
1624                    }
1625    
1626                    return null;
1627            }
1628    
1629            /**
1630             * Returns the last document library file rank in the ordered set where userId = &#63;.
1631             *
1632             * @param userId the user ID
1633             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1634             * @return the last matching document library file rank
1635             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
1636             * @throws SystemException if a system exception occurred
1637             */
1638            public DLFileRank findByUserId_Last(long userId,
1639                    OrderByComparator orderByComparator)
1640                    throws NoSuchFileRankException, SystemException {
1641                    DLFileRank dlFileRank = fetchByUserId_Last(userId, orderByComparator);
1642    
1643                    if (dlFileRank != null) {
1644                            return dlFileRank;
1645                    }
1646    
1647                    StringBundler msg = new StringBundler(4);
1648    
1649                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1650    
1651                    msg.append("userId=");
1652                    msg.append(userId);
1653    
1654                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1655    
1656                    throw new NoSuchFileRankException(msg.toString());
1657            }
1658    
1659            /**
1660             * Returns the last document library file rank in the ordered set where userId = &#63;.
1661             *
1662             * @param userId the user ID
1663             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1664             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1665             * @throws SystemException if a system exception occurred
1666             */
1667            public DLFileRank fetchByUserId_Last(long userId,
1668                    OrderByComparator orderByComparator) throws SystemException {
1669                    int count = countByUserId(userId);
1670    
1671                    List<DLFileRank> list = findByUserId(userId, count - 1, count,
1672                                    orderByComparator);
1673    
1674                    if (!list.isEmpty()) {
1675                            return list.get(0);
1676                    }
1677    
1678                    return null;
1679            }
1680    
1681            /**
1682             * Returns the document library file ranks before and after the current document library file rank in the ordered set where userId = &#63;.
1683             *
1684             * @param fileRankId the primary key of the current document library file rank
1685             * @param userId the user ID
1686             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1687             * @return the previous, current, and next document library file rank
1688             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
1689             * @throws SystemException if a system exception occurred
1690             */
1691            public DLFileRank[] findByUserId_PrevAndNext(long fileRankId, long userId,
1692                    OrderByComparator orderByComparator)
1693                    throws NoSuchFileRankException, SystemException {
1694                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1695    
1696                    Session session = null;
1697    
1698                    try {
1699                            session = openSession();
1700    
1701                            DLFileRank[] array = new DLFileRankImpl[3];
1702    
1703                            array[0] = getByUserId_PrevAndNext(session, dlFileRank, userId,
1704                                            orderByComparator, true);
1705    
1706                            array[1] = dlFileRank;
1707    
1708                            array[2] = getByUserId_PrevAndNext(session, dlFileRank, userId,
1709                                            orderByComparator, false);
1710    
1711                            return array;
1712                    }
1713                    catch (Exception e) {
1714                            throw processException(e);
1715                    }
1716                    finally {
1717                            closeSession(session);
1718                    }
1719            }
1720    
1721            protected DLFileRank getByUserId_PrevAndNext(Session session,
1722                    DLFileRank dlFileRank, long userId,
1723                    OrderByComparator orderByComparator, boolean previous) {
1724                    StringBundler query = null;
1725    
1726                    if (orderByComparator != null) {
1727                            query = new StringBundler(6 +
1728                                            (orderByComparator.getOrderByFields().length * 6));
1729                    }
1730                    else {
1731                            query = new StringBundler(3);
1732                    }
1733    
1734                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1735    
1736                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1737    
1738                    if (orderByComparator != null) {
1739                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1740    
1741                            if (orderByConditionFields.length > 0) {
1742                                    query.append(WHERE_AND);
1743                            }
1744    
1745                            for (int i = 0; i < orderByConditionFields.length; i++) {
1746                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1747                                    query.append(orderByConditionFields[i]);
1748    
1749                                    if ((i + 1) < orderByConditionFields.length) {
1750                                            if (orderByComparator.isAscending() ^ previous) {
1751                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1752                                            }
1753                                            else {
1754                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1755                                            }
1756                                    }
1757                                    else {
1758                                            if (orderByComparator.isAscending() ^ previous) {
1759                                                    query.append(WHERE_GREATER_THAN);
1760                                            }
1761                                            else {
1762                                                    query.append(WHERE_LESSER_THAN);
1763                                            }
1764                                    }
1765                            }
1766    
1767                            query.append(ORDER_BY_CLAUSE);
1768    
1769                            String[] orderByFields = orderByComparator.getOrderByFields();
1770    
1771                            for (int i = 0; i < orderByFields.length; i++) {
1772                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1773                                    query.append(orderByFields[i]);
1774    
1775                                    if ((i + 1) < orderByFields.length) {
1776                                            if (orderByComparator.isAscending() ^ previous) {
1777                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1778                                            }
1779                                            else {
1780                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1781                                            }
1782                                    }
1783                                    else {
1784                                            if (orderByComparator.isAscending() ^ previous) {
1785                                                    query.append(ORDER_BY_ASC);
1786                                            }
1787                                            else {
1788                                                    query.append(ORDER_BY_DESC);
1789                                            }
1790                                    }
1791                            }
1792                    }
1793                    else {
1794                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1795                    }
1796    
1797                    String sql = query.toString();
1798    
1799                    Query q = session.createQuery(sql);
1800    
1801                    q.setFirstResult(0);
1802                    q.setMaxResults(2);
1803    
1804                    QueryPos qPos = QueryPos.getInstance(q);
1805    
1806                    qPos.add(userId);
1807    
1808                    if (orderByComparator != null) {
1809                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
1810    
1811                            for (Object value : values) {
1812                                    qPos.add(value);
1813                            }
1814                    }
1815    
1816                    List<DLFileRank> list = q.list();
1817    
1818                    if (list.size() == 2) {
1819                            return list.get(1);
1820                    }
1821                    else {
1822                            return null;
1823                    }
1824            }
1825    
1826            /**
1827             * Removes all the document library file ranks where userId = &#63; from the database.
1828             *
1829             * @param userId the user ID
1830             * @throws SystemException if a system exception occurred
1831             */
1832            public void removeByUserId(long userId) throws SystemException {
1833                    for (DLFileRank dlFileRank : findByUserId(userId, QueryUtil.ALL_POS,
1834                                    QueryUtil.ALL_POS, null)) {
1835                            remove(dlFileRank);
1836                    }
1837            }
1838    
1839            /**
1840             * Returns the number of document library file ranks where userId = &#63;.
1841             *
1842             * @param userId the user ID
1843             * @return the number of matching document library file ranks
1844             * @throws SystemException if a system exception occurred
1845             */
1846            public int countByUserId(long userId) throws SystemException {
1847                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1848    
1849                    Object[] finderArgs = new Object[] { userId };
1850    
1851                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1852                                    this);
1853    
1854                    if (count == null) {
1855                            StringBundler query = new StringBundler(2);
1856    
1857                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
1858    
1859                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1860    
1861                            String sql = query.toString();
1862    
1863                            Session session = null;
1864    
1865                            try {
1866                                    session = openSession();
1867    
1868                                    Query q = session.createQuery(sql);
1869    
1870                                    QueryPos qPos = QueryPos.getInstance(q);
1871    
1872                                    qPos.add(userId);
1873    
1874                                    count = (Long)q.uniqueResult();
1875    
1876                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1877                            }
1878                            catch (Exception e) {
1879                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1880    
1881                                    throw processException(e);
1882                            }
1883                            finally {
1884                                    closeSession(session);
1885                            }
1886                    }
1887    
1888                    return count.intValue();
1889            }
1890    
1891            private static final String _FINDER_COLUMN_USERID_USERID_2 = "dlFileRank.userId = ?";
1892            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID =
1893                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1894                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
1895                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFileEntryId",
1896                            new String[] {
1897                                    Long.class.getName(),
1898                                    
1899                            Integer.class.getName(), Integer.class.getName(),
1900                                    OrderByComparator.class.getName()
1901                            });
1902            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID =
1903                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1904                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
1905                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFileEntryId",
1906                            new String[] { Long.class.getName() },
1907                            DLFileRankModelImpl.FILEENTRYID_COLUMN_BITMASK |
1908                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
1909            public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
1910                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
1911                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileEntryId",
1912                            new String[] { Long.class.getName() });
1913    
1914            /**
1915             * Returns all the document library file ranks where fileEntryId = &#63;.
1916             *
1917             * @param fileEntryId the file entry ID
1918             * @return the matching document library file ranks
1919             * @throws SystemException if a system exception occurred
1920             */
1921            public List<DLFileRank> findByFileEntryId(long fileEntryId)
1922                    throws SystemException {
1923                    return findByFileEntryId(fileEntryId, QueryUtil.ALL_POS,
1924                            QueryUtil.ALL_POS, null);
1925            }
1926    
1927            /**
1928             * Returns a range of all the document library file ranks where fileEntryId = &#63;.
1929             *
1930             * <p>
1931             * 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.
1932             * </p>
1933             *
1934             * @param fileEntryId the file entry ID
1935             * @param start the lower bound of the range of document library file ranks
1936             * @param end the upper bound of the range of document library file ranks (not inclusive)
1937             * @return the range of matching document library file ranks
1938             * @throws SystemException if a system exception occurred
1939             */
1940            public List<DLFileRank> findByFileEntryId(long fileEntryId, int start,
1941                    int end) throws SystemException {
1942                    return findByFileEntryId(fileEntryId, start, end, null);
1943            }
1944    
1945            /**
1946             * Returns an ordered range of all the document library file ranks where fileEntryId = &#63;.
1947             *
1948             * <p>
1949             * 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.
1950             * </p>
1951             *
1952             * @param fileEntryId the file entry ID
1953             * @param start the lower bound of the range of document library file ranks
1954             * @param end the upper bound of the range of document library file ranks (not inclusive)
1955             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1956             * @return the ordered range of matching document library file ranks
1957             * @throws SystemException if a system exception occurred
1958             */
1959            public List<DLFileRank> findByFileEntryId(long fileEntryId, int start,
1960                    int end, OrderByComparator orderByComparator) throws SystemException {
1961                    boolean pagination = true;
1962                    FinderPath finderPath = null;
1963                    Object[] finderArgs = null;
1964    
1965                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1966                                    (orderByComparator == null)) {
1967                            pagination = false;
1968                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID;
1969                            finderArgs = new Object[] { fileEntryId };
1970                    }
1971                    else {
1972                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID;
1973                            finderArgs = new Object[] { fileEntryId, start, end, orderByComparator };
1974                    }
1975    
1976                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
1977                                    finderArgs, this);
1978    
1979                    if ((list != null) && !list.isEmpty()) {
1980                            for (DLFileRank dlFileRank : list) {
1981                                    if ((fileEntryId != dlFileRank.getFileEntryId())) {
1982                                            list = null;
1983    
1984                                            break;
1985                                    }
1986                            }
1987                    }
1988    
1989                    if (list == null) {
1990                            StringBundler query = null;
1991    
1992                            if (orderByComparator != null) {
1993                                    query = new StringBundler(3 +
1994                                                    (orderByComparator.getOrderByFields().length * 3));
1995                            }
1996                            else {
1997                                    query = new StringBundler(3);
1998                            }
1999    
2000                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
2001    
2002                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2003    
2004                            if (orderByComparator != null) {
2005                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2006                                            orderByComparator);
2007                            }
2008                            else
2009                             if (pagination) {
2010                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
2011                            }
2012    
2013                            String sql = query.toString();
2014    
2015                            Session session = null;
2016    
2017                            try {
2018                                    session = openSession();
2019    
2020                                    Query q = session.createQuery(sql);
2021    
2022                                    QueryPos qPos = QueryPos.getInstance(q);
2023    
2024                                    qPos.add(fileEntryId);
2025    
2026                                    if (!pagination) {
2027                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
2028                                                            start, end, false);
2029    
2030                                            Collections.sort(list);
2031    
2032                                            list = new UnmodifiableList<DLFileRank>(list);
2033                                    }
2034                                    else {
2035                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
2036                                                            start, end);
2037                                    }
2038    
2039                                    cacheResult(list);
2040    
2041                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2042                            }
2043                            catch (Exception e) {
2044                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2045    
2046                                    throw processException(e);
2047                            }
2048                            finally {
2049                                    closeSession(session);
2050                            }
2051                    }
2052    
2053                    return list;
2054            }
2055    
2056            /**
2057             * Returns the first document library file rank in the ordered set where fileEntryId = &#63;.
2058             *
2059             * @param fileEntryId the file entry ID
2060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2061             * @return the first matching document library file rank
2062             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
2063             * @throws SystemException if a system exception occurred
2064             */
2065            public DLFileRank findByFileEntryId_First(long fileEntryId,
2066                    OrderByComparator orderByComparator)
2067                    throws NoSuchFileRankException, SystemException {
2068                    DLFileRank dlFileRank = fetchByFileEntryId_First(fileEntryId,
2069                                    orderByComparator);
2070    
2071                    if (dlFileRank != null) {
2072                            return dlFileRank;
2073                    }
2074    
2075                    StringBundler msg = new StringBundler(4);
2076    
2077                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2078    
2079                    msg.append("fileEntryId=");
2080                    msg.append(fileEntryId);
2081    
2082                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2083    
2084                    throw new NoSuchFileRankException(msg.toString());
2085            }
2086    
2087            /**
2088             * Returns the first document library file rank in the ordered set where fileEntryId = &#63;.
2089             *
2090             * @param fileEntryId the file entry ID
2091             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2092             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
2093             * @throws SystemException if a system exception occurred
2094             */
2095            public DLFileRank fetchByFileEntryId_First(long fileEntryId,
2096                    OrderByComparator orderByComparator) throws SystemException {
2097                    List<DLFileRank> list = findByFileEntryId(fileEntryId, 0, 1,
2098                                    orderByComparator);
2099    
2100                    if (!list.isEmpty()) {
2101                            return list.get(0);
2102                    }
2103    
2104                    return null;
2105            }
2106    
2107            /**
2108             * Returns the last document library file rank in the ordered set where fileEntryId = &#63;.
2109             *
2110             * @param fileEntryId the file entry ID
2111             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2112             * @return the last matching document library file rank
2113             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
2114             * @throws SystemException if a system exception occurred
2115             */
2116            public DLFileRank findByFileEntryId_Last(long fileEntryId,
2117                    OrderByComparator orderByComparator)
2118                    throws NoSuchFileRankException, SystemException {
2119                    DLFileRank dlFileRank = fetchByFileEntryId_Last(fileEntryId,
2120                                    orderByComparator);
2121    
2122                    if (dlFileRank != null) {
2123                            return dlFileRank;
2124                    }
2125    
2126                    StringBundler msg = new StringBundler(4);
2127    
2128                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2129    
2130                    msg.append("fileEntryId=");
2131                    msg.append(fileEntryId);
2132    
2133                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2134    
2135                    throw new NoSuchFileRankException(msg.toString());
2136            }
2137    
2138            /**
2139             * Returns the last document library file rank in the ordered set where fileEntryId = &#63;.
2140             *
2141             * @param fileEntryId the file entry ID
2142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2143             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
2144             * @throws SystemException if a system exception occurred
2145             */
2146            public DLFileRank fetchByFileEntryId_Last(long fileEntryId,
2147                    OrderByComparator orderByComparator) throws SystemException {
2148                    int count = countByFileEntryId(fileEntryId);
2149    
2150                    List<DLFileRank> list = findByFileEntryId(fileEntryId, count - 1,
2151                                    count, orderByComparator);
2152    
2153                    if (!list.isEmpty()) {
2154                            return list.get(0);
2155                    }
2156    
2157                    return null;
2158            }
2159    
2160            /**
2161             * Returns the document library file ranks before and after the current document library file rank in the ordered set where fileEntryId = &#63;.
2162             *
2163             * @param fileRankId the primary key of the current document library file rank
2164             * @param fileEntryId the file entry ID
2165             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2166             * @return the previous, current, and next document library file rank
2167             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
2168             * @throws SystemException if a system exception occurred
2169             */
2170            public DLFileRank[] findByFileEntryId_PrevAndNext(long fileRankId,
2171                    long fileEntryId, OrderByComparator orderByComparator)
2172                    throws NoSuchFileRankException, SystemException {
2173                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
2174    
2175                    Session session = null;
2176    
2177                    try {
2178                            session = openSession();
2179    
2180                            DLFileRank[] array = new DLFileRankImpl[3];
2181    
2182                            array[0] = getByFileEntryId_PrevAndNext(session, dlFileRank,
2183                                            fileEntryId, orderByComparator, true);
2184    
2185                            array[1] = dlFileRank;
2186    
2187                            array[2] = getByFileEntryId_PrevAndNext(session, dlFileRank,
2188                                            fileEntryId, orderByComparator, false);
2189    
2190                            return array;
2191                    }
2192                    catch (Exception e) {
2193                            throw processException(e);
2194                    }
2195                    finally {
2196                            closeSession(session);
2197                    }
2198            }
2199    
2200            protected DLFileRank getByFileEntryId_PrevAndNext(Session session,
2201                    DLFileRank dlFileRank, long fileEntryId,
2202                    OrderByComparator orderByComparator, boolean previous) {
2203                    StringBundler query = null;
2204    
2205                    if (orderByComparator != null) {
2206                            query = new StringBundler(6 +
2207                                            (orderByComparator.getOrderByFields().length * 6));
2208                    }
2209                    else {
2210                            query = new StringBundler(3);
2211                    }
2212    
2213                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
2214    
2215                    query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2216    
2217                    if (orderByComparator != null) {
2218                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2219    
2220                            if (orderByConditionFields.length > 0) {
2221                                    query.append(WHERE_AND);
2222                            }
2223    
2224                            for (int i = 0; i < orderByConditionFields.length; i++) {
2225                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2226                                    query.append(orderByConditionFields[i]);
2227    
2228                                    if ((i + 1) < orderByConditionFields.length) {
2229                                            if (orderByComparator.isAscending() ^ previous) {
2230                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2231                                            }
2232                                            else {
2233                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2234                                            }
2235                                    }
2236                                    else {
2237                                            if (orderByComparator.isAscending() ^ previous) {
2238                                                    query.append(WHERE_GREATER_THAN);
2239                                            }
2240                                            else {
2241                                                    query.append(WHERE_LESSER_THAN);
2242                                            }
2243                                    }
2244                            }
2245    
2246                            query.append(ORDER_BY_CLAUSE);
2247    
2248                            String[] orderByFields = orderByComparator.getOrderByFields();
2249    
2250                            for (int i = 0; i < orderByFields.length; i++) {
2251                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2252                                    query.append(orderByFields[i]);
2253    
2254                                    if ((i + 1) < orderByFields.length) {
2255                                            if (orderByComparator.isAscending() ^ previous) {
2256                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2257                                            }
2258                                            else {
2259                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2260                                            }
2261                                    }
2262                                    else {
2263                                            if (orderByComparator.isAscending() ^ previous) {
2264                                                    query.append(ORDER_BY_ASC);
2265                                            }
2266                                            else {
2267                                                    query.append(ORDER_BY_DESC);
2268                                            }
2269                                    }
2270                            }
2271                    }
2272                    else {
2273                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
2274                    }
2275    
2276                    String sql = query.toString();
2277    
2278                    Query q = session.createQuery(sql);
2279    
2280                    q.setFirstResult(0);
2281                    q.setMaxResults(2);
2282    
2283                    QueryPos qPos = QueryPos.getInstance(q);
2284    
2285                    qPos.add(fileEntryId);
2286    
2287                    if (orderByComparator != null) {
2288                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
2289    
2290                            for (Object value : values) {
2291                                    qPos.add(value);
2292                            }
2293                    }
2294    
2295                    List<DLFileRank> list = q.list();
2296    
2297                    if (list.size() == 2) {
2298                            return list.get(1);
2299                    }
2300                    else {
2301                            return null;
2302                    }
2303            }
2304    
2305            /**
2306             * Removes all the document library file ranks where fileEntryId = &#63; from the database.
2307             *
2308             * @param fileEntryId the file entry ID
2309             * @throws SystemException if a system exception occurred
2310             */
2311            public void removeByFileEntryId(long fileEntryId) throws SystemException {
2312                    for (DLFileRank dlFileRank : findByFileEntryId(fileEntryId,
2313                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2314                            remove(dlFileRank);
2315                    }
2316            }
2317    
2318            /**
2319             * Returns the number of document library file ranks where fileEntryId = &#63;.
2320             *
2321             * @param fileEntryId the file entry ID
2322             * @return the number of matching document library file ranks
2323             * @throws SystemException if a system exception occurred
2324             */
2325            public int countByFileEntryId(long fileEntryId) throws SystemException {
2326                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEENTRYID;
2327    
2328                    Object[] finderArgs = new Object[] { fileEntryId };
2329    
2330                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2331                                    this);
2332    
2333                    if (count == null) {
2334                            StringBundler query = new StringBundler(2);
2335    
2336                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2337    
2338                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2339    
2340                            String sql = query.toString();
2341    
2342                            Session session = null;
2343    
2344                            try {
2345                                    session = openSession();
2346    
2347                                    Query q = session.createQuery(sql);
2348    
2349                                    QueryPos qPos = QueryPos.getInstance(q);
2350    
2351                                    qPos.add(fileEntryId);
2352    
2353                                    count = (Long)q.uniqueResult();
2354    
2355                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2356                            }
2357                            catch (Exception e) {
2358                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2359    
2360                                    throw processException(e);
2361                            }
2362                            finally {
2363                                    closeSession(session);
2364                            }
2365                    }
2366    
2367                    return count.intValue();
2368            }
2369    
2370            private static final String _FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2 = "dlFileRank.fileEntryId = ?";
2371            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2372                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
2373                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
2374                            new String[] {
2375                                    Long.class.getName(), Long.class.getName(),
2376                                    
2377                            Integer.class.getName(), Integer.class.getName(),
2378                                    OrderByComparator.class.getName()
2379                            });
2380            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2381                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
2382                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
2383                            new String[] { Long.class.getName(), Long.class.getName() },
2384                            DLFileRankModelImpl.GROUPID_COLUMN_BITMASK |
2385                            DLFileRankModelImpl.USERID_COLUMN_BITMASK |
2386                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
2387            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2388                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
2389                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
2390                            new String[] { Long.class.getName(), Long.class.getName() });
2391    
2392            /**
2393             * Returns all the document library file ranks where groupId = &#63; and userId = &#63;.
2394             *
2395             * @param groupId the group ID
2396             * @param userId the user ID
2397             * @return the matching document library file ranks
2398             * @throws SystemException if a system exception occurred
2399             */
2400            public List<DLFileRank> findByG_U(long groupId, long userId)
2401                    throws SystemException {
2402                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2403                            null);
2404            }
2405    
2406            /**
2407             * Returns a range of all the document library file ranks where groupId = &#63; and userId = &#63;.
2408             *
2409             * <p>
2410             * 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.
2411             * </p>
2412             *
2413             * @param groupId the group ID
2414             * @param userId the user ID
2415             * @param start the lower bound of the range of document library file ranks
2416             * @param end the upper bound of the range of document library file ranks (not inclusive)
2417             * @return the range of matching document library file ranks
2418             * @throws SystemException if a system exception occurred
2419             */
2420            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
2421                    int end) throws SystemException {
2422                    return findByG_U(groupId, userId, start, end, null);
2423            }
2424    
2425            /**
2426             * Returns an ordered range of all the document library file ranks where groupId = &#63; and userId = &#63;.
2427             *
2428             * <p>
2429             * 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.
2430             * </p>
2431             *
2432             * @param groupId the group ID
2433             * @param userId the user ID
2434             * @param start the lower bound of the range of document library file ranks
2435             * @param end the upper bound of the range of document library file ranks (not inclusive)
2436             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2437             * @return the ordered range of matching document library file ranks
2438             * @throws SystemException if a system exception occurred
2439             */
2440            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
2441                    int end, OrderByComparator orderByComparator) throws SystemException {
2442                    boolean pagination = true;
2443                    FinderPath finderPath = null;
2444                    Object[] finderArgs = null;
2445    
2446                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2447                                    (orderByComparator == null)) {
2448                            pagination = false;
2449                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
2450                            finderArgs = new Object[] { groupId, userId };
2451                    }
2452                    else {
2453                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
2454                            finderArgs = new Object[] {
2455                                            groupId, userId,
2456                                            
2457                                            start, end, orderByComparator
2458                                    };
2459                    }
2460    
2461                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
2462                                    finderArgs, this);
2463    
2464                    if ((list != null) && !list.isEmpty()) {
2465                            for (DLFileRank dlFileRank : list) {
2466                                    if ((groupId != dlFileRank.getGroupId()) ||
2467                                                    (userId != dlFileRank.getUserId())) {
2468                                            list = null;
2469    
2470                                            break;
2471                                    }
2472                            }
2473                    }
2474    
2475                    if (list == null) {
2476                            StringBundler query = null;
2477    
2478                            if (orderByComparator != null) {
2479                                    query = new StringBundler(4 +
2480                                                    (orderByComparator.getOrderByFields().length * 3));
2481                            }
2482                            else {
2483                                    query = new StringBundler(4);
2484                            }
2485    
2486                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
2487    
2488                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2489    
2490                            query.append(_FINDER_COLUMN_G_U_USERID_2);
2491    
2492                            if (orderByComparator != null) {
2493                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2494                                            orderByComparator);
2495                            }
2496                            else
2497                             if (pagination) {
2498                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
2499                            }
2500    
2501                            String sql = query.toString();
2502    
2503                            Session session = null;
2504    
2505                            try {
2506                                    session = openSession();
2507    
2508                                    Query q = session.createQuery(sql);
2509    
2510                                    QueryPos qPos = QueryPos.getInstance(q);
2511    
2512                                    qPos.add(groupId);
2513    
2514                                    qPos.add(userId);
2515    
2516                                    if (!pagination) {
2517                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
2518                                                            start, end, false);
2519    
2520                                            Collections.sort(list);
2521    
2522                                            list = new UnmodifiableList<DLFileRank>(list);
2523                                    }
2524                                    else {
2525                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
2526                                                            start, end);
2527                                    }
2528    
2529                                    cacheResult(list);
2530    
2531                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2532                            }
2533                            catch (Exception e) {
2534                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2535    
2536                                    throw processException(e);
2537                            }
2538                            finally {
2539                                    closeSession(session);
2540                            }
2541                    }
2542    
2543                    return list;
2544            }
2545    
2546            /**
2547             * Returns the first document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
2548             *
2549             * @param groupId the group ID
2550             * @param userId the user ID
2551             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2552             * @return the first matching document library file rank
2553             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
2554             * @throws SystemException if a system exception occurred
2555             */
2556            public DLFileRank findByG_U_First(long groupId, long userId,
2557                    OrderByComparator orderByComparator)
2558                    throws NoSuchFileRankException, SystemException {
2559                    DLFileRank dlFileRank = fetchByG_U_First(groupId, userId,
2560                                    orderByComparator);
2561    
2562                    if (dlFileRank != null) {
2563                            return dlFileRank;
2564                    }
2565    
2566                    StringBundler msg = new StringBundler(6);
2567    
2568                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2569    
2570                    msg.append("groupId=");
2571                    msg.append(groupId);
2572    
2573                    msg.append(", userId=");
2574                    msg.append(userId);
2575    
2576                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2577    
2578                    throw new NoSuchFileRankException(msg.toString());
2579            }
2580    
2581            /**
2582             * Returns the first document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
2583             *
2584             * @param groupId the group ID
2585             * @param userId the user ID
2586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2587             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
2588             * @throws SystemException if a system exception occurred
2589             */
2590            public DLFileRank fetchByG_U_First(long groupId, long userId,
2591                    OrderByComparator orderByComparator) throws SystemException {
2592                    List<DLFileRank> list = findByG_U(groupId, userId, 0, 1,
2593                                    orderByComparator);
2594    
2595                    if (!list.isEmpty()) {
2596                            return list.get(0);
2597                    }
2598    
2599                    return null;
2600            }
2601    
2602            /**
2603             * Returns the last document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
2604             *
2605             * @param groupId the group ID
2606             * @param userId the user ID
2607             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2608             * @return the last matching document library file rank
2609             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
2610             * @throws SystemException if a system exception occurred
2611             */
2612            public DLFileRank findByG_U_Last(long groupId, long userId,
2613                    OrderByComparator orderByComparator)
2614                    throws NoSuchFileRankException, SystemException {
2615                    DLFileRank dlFileRank = fetchByG_U_Last(groupId, userId,
2616                                    orderByComparator);
2617    
2618                    if (dlFileRank != null) {
2619                            return dlFileRank;
2620                    }
2621    
2622                    StringBundler msg = new StringBundler(6);
2623    
2624                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2625    
2626                    msg.append("groupId=");
2627                    msg.append(groupId);
2628    
2629                    msg.append(", userId=");
2630                    msg.append(userId);
2631    
2632                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2633    
2634                    throw new NoSuchFileRankException(msg.toString());
2635            }
2636    
2637            /**
2638             * Returns the last document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
2639             *
2640             * @param groupId the group ID
2641             * @param userId the user ID
2642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2643             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
2644             * @throws SystemException if a system exception occurred
2645             */
2646            public DLFileRank fetchByG_U_Last(long groupId, long userId,
2647                    OrderByComparator orderByComparator) throws SystemException {
2648                    int count = countByG_U(groupId, userId);
2649    
2650                    List<DLFileRank> list = findByG_U(groupId, userId, count - 1, count,
2651                                    orderByComparator);
2652    
2653                    if (!list.isEmpty()) {
2654                            return list.get(0);
2655                    }
2656    
2657                    return null;
2658            }
2659    
2660            /**
2661             * 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;.
2662             *
2663             * @param fileRankId the primary key of the current document library file rank
2664             * @param groupId the group ID
2665             * @param userId the user ID
2666             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2667             * @return the previous, current, and next document library file rank
2668             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
2669             * @throws SystemException if a system exception occurred
2670             */
2671            public DLFileRank[] findByG_U_PrevAndNext(long fileRankId, long groupId,
2672                    long userId, OrderByComparator orderByComparator)
2673                    throws NoSuchFileRankException, SystemException {
2674                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
2675    
2676                    Session session = null;
2677    
2678                    try {
2679                            session = openSession();
2680    
2681                            DLFileRank[] array = new DLFileRankImpl[3];
2682    
2683                            array[0] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
2684                                            userId, orderByComparator, true);
2685    
2686                            array[1] = dlFileRank;
2687    
2688                            array[2] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
2689                                            userId, orderByComparator, false);
2690    
2691                            return array;
2692                    }
2693                    catch (Exception e) {
2694                            throw processException(e);
2695                    }
2696                    finally {
2697                            closeSession(session);
2698                    }
2699            }
2700    
2701            protected DLFileRank getByG_U_PrevAndNext(Session session,
2702                    DLFileRank dlFileRank, long groupId, long userId,
2703                    OrderByComparator orderByComparator, boolean previous) {
2704                    StringBundler query = null;
2705    
2706                    if (orderByComparator != null) {
2707                            query = new StringBundler(6 +
2708                                            (orderByComparator.getOrderByFields().length * 6));
2709                    }
2710                    else {
2711                            query = new StringBundler(3);
2712                    }
2713    
2714                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
2715    
2716                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2717    
2718                    query.append(_FINDER_COLUMN_G_U_USERID_2);
2719    
2720                    if (orderByComparator != null) {
2721                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2722    
2723                            if (orderByConditionFields.length > 0) {
2724                                    query.append(WHERE_AND);
2725                            }
2726    
2727                            for (int i = 0; i < orderByConditionFields.length; i++) {
2728                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2729                                    query.append(orderByConditionFields[i]);
2730    
2731                                    if ((i + 1) < orderByConditionFields.length) {
2732                                            if (orderByComparator.isAscending() ^ previous) {
2733                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2734                                            }
2735                                            else {
2736                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2737                                            }
2738                                    }
2739                                    else {
2740                                            if (orderByComparator.isAscending() ^ previous) {
2741                                                    query.append(WHERE_GREATER_THAN);
2742                                            }
2743                                            else {
2744                                                    query.append(WHERE_LESSER_THAN);
2745                                            }
2746                                    }
2747                            }
2748    
2749                            query.append(ORDER_BY_CLAUSE);
2750    
2751                            String[] orderByFields = orderByComparator.getOrderByFields();
2752    
2753                            for (int i = 0; i < orderByFields.length; i++) {
2754                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2755                                    query.append(orderByFields[i]);
2756    
2757                                    if ((i + 1) < orderByFields.length) {
2758                                            if (orderByComparator.isAscending() ^ previous) {
2759                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2760                                            }
2761                                            else {
2762                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2763                                            }
2764                                    }
2765                                    else {
2766                                            if (orderByComparator.isAscending() ^ previous) {
2767                                                    query.append(ORDER_BY_ASC);
2768                                            }
2769                                            else {
2770                                                    query.append(ORDER_BY_DESC);
2771                                            }
2772                                    }
2773                            }
2774                    }
2775                    else {
2776                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
2777                    }
2778    
2779                    String sql = query.toString();
2780    
2781                    Query q = session.createQuery(sql);
2782    
2783                    q.setFirstResult(0);
2784                    q.setMaxResults(2);
2785    
2786                    QueryPos qPos = QueryPos.getInstance(q);
2787    
2788                    qPos.add(groupId);
2789    
2790                    qPos.add(userId);
2791    
2792                    if (orderByComparator != null) {
2793                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
2794    
2795                            for (Object value : values) {
2796                                    qPos.add(value);
2797                            }
2798                    }
2799    
2800                    List<DLFileRank> list = q.list();
2801    
2802                    if (list.size() == 2) {
2803                            return list.get(1);
2804                    }
2805                    else {
2806                            return null;
2807                    }
2808            }
2809    
2810            /**
2811             * Removes all the document library file ranks where groupId = &#63; and userId = &#63; from the database.
2812             *
2813             * @param groupId the group ID
2814             * @param userId the user ID
2815             * @throws SystemException if a system exception occurred
2816             */
2817            public void removeByG_U(long groupId, long userId)
2818                    throws SystemException {
2819                    for (DLFileRank dlFileRank : findByG_U(groupId, userId,
2820                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2821                            remove(dlFileRank);
2822                    }
2823            }
2824    
2825            /**
2826             * Returns the number of document library file ranks where groupId = &#63; and userId = &#63;.
2827             *
2828             * @param groupId the group ID
2829             * @param userId the user ID
2830             * @return the number of matching document library file ranks
2831             * @throws SystemException if a system exception occurred
2832             */
2833            public int countByG_U(long groupId, long userId) throws SystemException {
2834                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
2835    
2836                    Object[] finderArgs = new Object[] { groupId, userId };
2837    
2838                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2839                                    this);
2840    
2841                    if (count == null) {
2842                            StringBundler query = new StringBundler(3);
2843    
2844                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2845    
2846                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2847    
2848                            query.append(_FINDER_COLUMN_G_U_USERID_2);
2849    
2850                            String sql = query.toString();
2851    
2852                            Session session = null;
2853    
2854                            try {
2855                                    session = openSession();
2856    
2857                                    Query q = session.createQuery(sql);
2858    
2859                                    QueryPos qPos = QueryPos.getInstance(q);
2860    
2861                                    qPos.add(groupId);
2862    
2863                                    qPos.add(userId);
2864    
2865                                    count = (Long)q.uniqueResult();
2866    
2867                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2868                            }
2869                            catch (Exception e) {
2870                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2871    
2872                                    throw processException(e);
2873                            }
2874                            finally {
2875                                    closeSession(session);
2876                            }
2877                    }
2878    
2879                    return count.intValue();
2880            }
2881    
2882            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "dlFileRank.groupId = ? AND ";
2883            private static final String _FINDER_COLUMN_G_U_USERID_2 = "dlFileRank.userId = ?";
2884            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_A = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2885                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
2886                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_A",
2887                            new String[] {
2888                                    Long.class.getName(), Long.class.getName(),
2889                                    Boolean.class.getName(),
2890                                    
2891                            Integer.class.getName(), Integer.class.getName(),
2892                                    OrderByComparator.class.getName()
2893                            });
2894            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2895                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
2896                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_A",
2897                            new String[] {
2898                                    Long.class.getName(), Long.class.getName(),
2899                                    Boolean.class.getName()
2900                            },
2901                            DLFileRankModelImpl.GROUPID_COLUMN_BITMASK |
2902                            DLFileRankModelImpl.USERID_COLUMN_BITMASK |
2903                            DLFileRankModelImpl.ACTIVE_COLUMN_BITMASK |
2904                            DLFileRankModelImpl.CREATEDATE_COLUMN_BITMASK);
2905            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_A = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
2906                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
2907                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_A",
2908                            new String[] {
2909                                    Long.class.getName(), Long.class.getName(),
2910                                    Boolean.class.getName()
2911                            });
2912    
2913            /**
2914             * Returns all the document library file ranks where groupId = &#63; and userId = &#63; and active = &#63;.
2915             *
2916             * @param groupId the group ID
2917             * @param userId the user ID
2918             * @param active the active
2919             * @return the matching document library file ranks
2920             * @throws SystemException if a system exception occurred
2921             */
2922            public List<DLFileRank> findByG_U_A(long groupId, long userId,
2923                    boolean active) throws SystemException {
2924                    return findByG_U_A(groupId, userId, active, QueryUtil.ALL_POS,
2925                            QueryUtil.ALL_POS, null);
2926            }
2927    
2928            /**
2929             * Returns a range of all the document library file ranks where groupId = &#63; and userId = &#63; and active = &#63;.
2930             *
2931             * <p>
2932             * 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.
2933             * </p>
2934             *
2935             * @param groupId the group ID
2936             * @param userId the user ID
2937             * @param active the active
2938             * @param start the lower bound of the range of document library file ranks
2939             * @param end the upper bound of the range of document library file ranks (not inclusive)
2940             * @return the range of matching document library file ranks
2941             * @throws SystemException if a system exception occurred
2942             */
2943            public List<DLFileRank> findByG_U_A(long groupId, long userId,
2944                    boolean active, int start, int end) throws SystemException {
2945                    return findByG_U_A(groupId, userId, active, start, end, null);
2946            }
2947    
2948            /**
2949             * Returns an ordered range of all the document library file ranks where groupId = &#63; and userId = &#63; and active = &#63;.
2950             *
2951             * <p>
2952             * 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.
2953             * </p>
2954             *
2955             * @param groupId the group ID
2956             * @param userId the user ID
2957             * @param active the active
2958             * @param start the lower bound of the range of document library file ranks
2959             * @param end the upper bound of the range of document library file ranks (not inclusive)
2960             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2961             * @return the ordered range of matching document library file ranks
2962             * @throws SystemException if a system exception occurred
2963             */
2964            public List<DLFileRank> findByG_U_A(long groupId, long userId,
2965                    boolean active, int start, int end, OrderByComparator orderByComparator)
2966                    throws SystemException {
2967                    boolean pagination = true;
2968                    FinderPath finderPath = null;
2969                    Object[] finderArgs = null;
2970    
2971                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2972                                    (orderByComparator == null)) {
2973                            pagination = false;
2974                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A;
2975                            finderArgs = new Object[] { groupId, userId, active };
2976                    }
2977                    else {
2978                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_A;
2979                            finderArgs = new Object[] {
2980                                            groupId, userId, active,
2981                                            
2982                                            start, end, orderByComparator
2983                                    };
2984                    }
2985    
2986                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
2987                                    finderArgs, this);
2988    
2989                    if ((list != null) && !list.isEmpty()) {
2990                            for (DLFileRank dlFileRank : list) {
2991                                    if ((groupId != dlFileRank.getGroupId()) ||
2992                                                    (userId != dlFileRank.getUserId()) ||
2993                                                    (active != dlFileRank.getActive())) {
2994                                            list = null;
2995    
2996                                            break;
2997                                    }
2998                            }
2999                    }
3000    
3001                    if (list == null) {
3002                            StringBundler query = null;
3003    
3004                            if (orderByComparator != null) {
3005                                    query = new StringBundler(5 +
3006                                                    (orderByComparator.getOrderByFields().length * 3));
3007                            }
3008                            else {
3009                                    query = new StringBundler(5);
3010                            }
3011    
3012                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
3013    
3014                            query.append(_FINDER_COLUMN_G_U_A_GROUPID_2);
3015    
3016                            query.append(_FINDER_COLUMN_G_U_A_USERID_2);
3017    
3018                            query.append(_FINDER_COLUMN_G_U_A_ACTIVE_2);
3019    
3020                            if (orderByComparator != null) {
3021                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3022                                            orderByComparator);
3023                            }
3024                            else
3025                             if (pagination) {
3026                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
3027                            }
3028    
3029                            String sql = query.toString();
3030    
3031                            Session session = null;
3032    
3033                            try {
3034                                    session = openSession();
3035    
3036                                    Query q = session.createQuery(sql);
3037    
3038                                    QueryPos qPos = QueryPos.getInstance(q);
3039    
3040                                    qPos.add(groupId);
3041    
3042                                    qPos.add(userId);
3043    
3044                                    qPos.add(active);
3045    
3046                                    if (!pagination) {
3047                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
3048                                                            start, end, false);
3049    
3050                                            Collections.sort(list);
3051    
3052                                            list = new UnmodifiableList<DLFileRank>(list);
3053                                    }
3054                                    else {
3055                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
3056                                                            start, end);
3057                                    }
3058    
3059                                    cacheResult(list);
3060    
3061                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3062                            }
3063                            catch (Exception e) {
3064                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3065    
3066                                    throw processException(e);
3067                            }
3068                            finally {
3069                                    closeSession(session);
3070                            }
3071                    }
3072    
3073                    return list;
3074            }
3075    
3076            /**
3077             * Returns the first document library file rank in the ordered set where groupId = &#63; and userId = &#63; and active = &#63;.
3078             *
3079             * @param groupId the group ID
3080             * @param userId the user ID
3081             * @param active the active
3082             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3083             * @return the first matching document library file rank
3084             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
3085             * @throws SystemException if a system exception occurred
3086             */
3087            public DLFileRank findByG_U_A_First(long groupId, long userId,
3088                    boolean active, OrderByComparator orderByComparator)
3089                    throws NoSuchFileRankException, SystemException {
3090                    DLFileRank dlFileRank = fetchByG_U_A_First(groupId, userId, active,
3091                                    orderByComparator);
3092    
3093                    if (dlFileRank != null) {
3094                            return dlFileRank;
3095                    }
3096    
3097                    StringBundler msg = new StringBundler(8);
3098    
3099                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3100    
3101                    msg.append("groupId=");
3102                    msg.append(groupId);
3103    
3104                    msg.append(", userId=");
3105                    msg.append(userId);
3106    
3107                    msg.append(", active=");
3108                    msg.append(active);
3109    
3110                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3111    
3112                    throw new NoSuchFileRankException(msg.toString());
3113            }
3114    
3115            /**
3116             * Returns the first document library file rank in the ordered set where groupId = &#63; and userId = &#63; and active = &#63;.
3117             *
3118             * @param groupId the group ID
3119             * @param userId the user ID
3120             * @param active the active
3121             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3122             * @return the first matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
3123             * @throws SystemException if a system exception occurred
3124             */
3125            public DLFileRank fetchByG_U_A_First(long groupId, long userId,
3126                    boolean active, OrderByComparator orderByComparator)
3127                    throws SystemException {
3128                    List<DLFileRank> list = findByG_U_A(groupId, userId, active, 0, 1,
3129                                    orderByComparator);
3130    
3131                    if (!list.isEmpty()) {
3132                            return list.get(0);
3133                    }
3134    
3135                    return null;
3136            }
3137    
3138            /**
3139             * Returns the last document library file rank in the ordered set where groupId = &#63; and userId = &#63; and active = &#63;.
3140             *
3141             * @param groupId the group ID
3142             * @param userId the user ID
3143             * @param active the active
3144             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3145             * @return the last matching document library file rank
3146             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
3147             * @throws SystemException if a system exception occurred
3148             */
3149            public DLFileRank findByG_U_A_Last(long groupId, long userId,
3150                    boolean active, OrderByComparator orderByComparator)
3151                    throws NoSuchFileRankException, SystemException {
3152                    DLFileRank dlFileRank = fetchByG_U_A_Last(groupId, userId, active,
3153                                    orderByComparator);
3154    
3155                    if (dlFileRank != null) {
3156                            return dlFileRank;
3157                    }
3158    
3159                    StringBundler msg = new StringBundler(8);
3160    
3161                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3162    
3163                    msg.append("groupId=");
3164                    msg.append(groupId);
3165    
3166                    msg.append(", userId=");
3167                    msg.append(userId);
3168    
3169                    msg.append(", active=");
3170                    msg.append(active);
3171    
3172                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3173    
3174                    throw new NoSuchFileRankException(msg.toString());
3175            }
3176    
3177            /**
3178             * Returns the last document library file rank in the ordered set where groupId = &#63; and userId = &#63; and active = &#63;.
3179             *
3180             * @param groupId the group ID
3181             * @param userId the user ID
3182             * @param active the active
3183             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3184             * @return the last matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
3185             * @throws SystemException if a system exception occurred
3186             */
3187            public DLFileRank fetchByG_U_A_Last(long groupId, long userId,
3188                    boolean active, OrderByComparator orderByComparator)
3189                    throws SystemException {
3190                    int count = countByG_U_A(groupId, userId, active);
3191    
3192                    List<DLFileRank> list = findByG_U_A(groupId, userId, active, count - 1,
3193                                    count, orderByComparator);
3194    
3195                    if (!list.isEmpty()) {
3196                            return list.get(0);
3197                    }
3198    
3199                    return null;
3200            }
3201    
3202            /**
3203             * 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;.
3204             *
3205             * @param fileRankId the primary key of the current document library file rank
3206             * @param groupId the group ID
3207             * @param userId the user ID
3208             * @param active the active
3209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3210             * @return the previous, current, and next document library file rank
3211             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
3212             * @throws SystemException if a system exception occurred
3213             */
3214            public DLFileRank[] findByG_U_A_PrevAndNext(long fileRankId, long groupId,
3215                    long userId, boolean active, OrderByComparator orderByComparator)
3216                    throws NoSuchFileRankException, SystemException {
3217                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
3218    
3219                    Session session = null;
3220    
3221                    try {
3222                            session = openSession();
3223    
3224                            DLFileRank[] array = new DLFileRankImpl[3];
3225    
3226                            array[0] = getByG_U_A_PrevAndNext(session, dlFileRank, groupId,
3227                                            userId, active, orderByComparator, true);
3228    
3229                            array[1] = dlFileRank;
3230    
3231                            array[2] = getByG_U_A_PrevAndNext(session, dlFileRank, groupId,
3232                                            userId, active, orderByComparator, false);
3233    
3234                            return array;
3235                    }
3236                    catch (Exception e) {
3237                            throw processException(e);
3238                    }
3239                    finally {
3240                            closeSession(session);
3241                    }
3242            }
3243    
3244            protected DLFileRank getByG_U_A_PrevAndNext(Session session,
3245                    DLFileRank dlFileRank, long groupId, long userId, boolean active,
3246                    OrderByComparator orderByComparator, boolean previous) {
3247                    StringBundler query = null;
3248    
3249                    if (orderByComparator != null) {
3250                            query = new StringBundler(6 +
3251                                            (orderByComparator.getOrderByFields().length * 6));
3252                    }
3253                    else {
3254                            query = new StringBundler(3);
3255                    }
3256    
3257                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
3258    
3259                    query.append(_FINDER_COLUMN_G_U_A_GROUPID_2);
3260    
3261                    query.append(_FINDER_COLUMN_G_U_A_USERID_2);
3262    
3263                    query.append(_FINDER_COLUMN_G_U_A_ACTIVE_2);
3264    
3265                    if (orderByComparator != null) {
3266                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3267    
3268                            if (orderByConditionFields.length > 0) {
3269                                    query.append(WHERE_AND);
3270                            }
3271    
3272                            for (int i = 0; i < orderByConditionFields.length; i++) {
3273                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3274                                    query.append(orderByConditionFields[i]);
3275    
3276                                    if ((i + 1) < orderByConditionFields.length) {
3277                                            if (orderByComparator.isAscending() ^ previous) {
3278                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3279                                            }
3280                                            else {
3281                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3282                                            }
3283                                    }
3284                                    else {
3285                                            if (orderByComparator.isAscending() ^ previous) {
3286                                                    query.append(WHERE_GREATER_THAN);
3287                                            }
3288                                            else {
3289                                                    query.append(WHERE_LESSER_THAN);
3290                                            }
3291                                    }
3292                            }
3293    
3294                            query.append(ORDER_BY_CLAUSE);
3295    
3296                            String[] orderByFields = orderByComparator.getOrderByFields();
3297    
3298                            for (int i = 0; i < orderByFields.length; i++) {
3299                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3300                                    query.append(orderByFields[i]);
3301    
3302                                    if ((i + 1) < orderByFields.length) {
3303                                            if (orderByComparator.isAscending() ^ previous) {
3304                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3305                                            }
3306                                            else {
3307                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3308                                            }
3309                                    }
3310                                    else {
3311                                            if (orderByComparator.isAscending() ^ previous) {
3312                                                    query.append(ORDER_BY_ASC);
3313                                            }
3314                                            else {
3315                                                    query.append(ORDER_BY_DESC);
3316                                            }
3317                                    }
3318                            }
3319                    }
3320                    else {
3321                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
3322                    }
3323    
3324                    String sql = query.toString();
3325    
3326                    Query q = session.createQuery(sql);
3327    
3328                    q.setFirstResult(0);
3329                    q.setMaxResults(2);
3330    
3331                    QueryPos qPos = QueryPos.getInstance(q);
3332    
3333                    qPos.add(groupId);
3334    
3335                    qPos.add(userId);
3336    
3337                    qPos.add(active);
3338    
3339                    if (orderByComparator != null) {
3340                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
3341    
3342                            for (Object value : values) {
3343                                    qPos.add(value);
3344                            }
3345                    }
3346    
3347                    List<DLFileRank> list = q.list();
3348    
3349                    if (list.size() == 2) {
3350                            return list.get(1);
3351                    }
3352                    else {
3353                            return null;
3354                    }
3355            }
3356    
3357            /**
3358             * Removes all the document library file ranks where groupId = &#63; and userId = &#63; and active = &#63; from the database.
3359             *
3360             * @param groupId the group ID
3361             * @param userId the user ID
3362             * @param active the active
3363             * @throws SystemException if a system exception occurred
3364             */
3365            public void removeByG_U_A(long groupId, long userId, boolean active)
3366                    throws SystemException {
3367                    for (DLFileRank dlFileRank : findByG_U_A(groupId, userId, active,
3368                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3369                            remove(dlFileRank);
3370                    }
3371            }
3372    
3373            /**
3374             * Returns the number of document library file ranks where groupId = &#63; and userId = &#63; and active = &#63;.
3375             *
3376             * @param groupId the group ID
3377             * @param userId the user ID
3378             * @param active the active
3379             * @return the number of matching document library file ranks
3380             * @throws SystemException if a system exception occurred
3381             */
3382            public int countByG_U_A(long groupId, long userId, boolean active)
3383                    throws SystemException {
3384                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_A;
3385    
3386                    Object[] finderArgs = new Object[] { groupId, userId, active };
3387    
3388                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3389                                    this);
3390    
3391                    if (count == null) {
3392                            StringBundler query = new StringBundler(4);
3393    
3394                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
3395    
3396                            query.append(_FINDER_COLUMN_G_U_A_GROUPID_2);
3397    
3398                            query.append(_FINDER_COLUMN_G_U_A_USERID_2);
3399    
3400                            query.append(_FINDER_COLUMN_G_U_A_ACTIVE_2);
3401    
3402                            String sql = query.toString();
3403    
3404                            Session session = null;
3405    
3406                            try {
3407                                    session = openSession();
3408    
3409                                    Query q = session.createQuery(sql);
3410    
3411                                    QueryPos qPos = QueryPos.getInstance(q);
3412    
3413                                    qPos.add(groupId);
3414    
3415                                    qPos.add(userId);
3416    
3417                                    qPos.add(active);
3418    
3419                                    count = (Long)q.uniqueResult();
3420    
3421                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3422                            }
3423                            catch (Exception e) {
3424                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3425    
3426                                    throw processException(e);
3427                            }
3428                            finally {
3429                                    closeSession(session);
3430                            }
3431                    }
3432    
3433                    return count.intValue();
3434            }
3435    
3436            private static final String _FINDER_COLUMN_G_U_A_GROUPID_2 = "dlFileRank.groupId = ? AND ";
3437            private static final String _FINDER_COLUMN_G_U_A_USERID_2 = "dlFileRank.userId = ? AND ";
3438            private static final String _FINDER_COLUMN_G_U_A_ACTIVE_2 = "dlFileRank.active = ?";
3439            public static final FinderPath FINDER_PATH_FETCH_BY_C_U_F = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
3440                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
3441                            FINDER_CLASS_NAME_ENTITY, "fetchByC_U_F",
3442                            new String[] {
3443                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
3444                            },
3445                            DLFileRankModelImpl.COMPANYID_COLUMN_BITMASK |
3446                            DLFileRankModelImpl.USERID_COLUMN_BITMASK |
3447                            DLFileRankModelImpl.FILEENTRYID_COLUMN_BITMASK);
3448            public static final FinderPath FINDER_PATH_COUNT_BY_C_U_F = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
3449                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
3450                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U_F",
3451                            new String[] {
3452                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
3453                            });
3454    
3455            /**
3456             * 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.
3457             *
3458             * @param companyId the company ID
3459             * @param userId the user ID
3460             * @param fileEntryId the file entry ID
3461             * @return the matching document library file rank
3462             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
3463             * @throws SystemException if a system exception occurred
3464             */
3465            public DLFileRank findByC_U_F(long companyId, long userId, long fileEntryId)
3466                    throws NoSuchFileRankException, SystemException {
3467                    DLFileRank dlFileRank = fetchByC_U_F(companyId, userId, fileEntryId);
3468    
3469                    if (dlFileRank == null) {
3470                            StringBundler msg = new StringBundler(8);
3471    
3472                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3473    
3474                            msg.append("companyId=");
3475                            msg.append(companyId);
3476    
3477                            msg.append(", userId=");
3478                            msg.append(userId);
3479    
3480                            msg.append(", fileEntryId=");
3481                            msg.append(fileEntryId);
3482    
3483                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3484    
3485                            if (_log.isWarnEnabled()) {
3486                                    _log.warn(msg.toString());
3487                            }
3488    
3489                            throw new NoSuchFileRankException(msg.toString());
3490                    }
3491    
3492                    return dlFileRank;
3493            }
3494    
3495            /**
3496             * 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.
3497             *
3498             * @param companyId the company ID
3499             * @param userId the user ID
3500             * @param fileEntryId the file entry ID
3501             * @return the matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
3502             * @throws SystemException if a system exception occurred
3503             */
3504            public DLFileRank fetchByC_U_F(long companyId, long userId, long fileEntryId)
3505                    throws SystemException {
3506                    return fetchByC_U_F(companyId, userId, fileEntryId, true);
3507            }
3508    
3509            /**
3510             * 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.
3511             *
3512             * @param companyId the company ID
3513             * @param userId the user ID
3514             * @param fileEntryId the file entry ID
3515             * @param retrieveFromCache whether to use the finder cache
3516             * @return the matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
3517             * @throws SystemException if a system exception occurred
3518             */
3519            public DLFileRank fetchByC_U_F(long companyId, long userId,
3520                    long fileEntryId, boolean retrieveFromCache) throws SystemException {
3521                    Object[] finderArgs = new Object[] { companyId, userId, fileEntryId };
3522    
3523                    Object result = null;
3524    
3525                    if (retrieveFromCache) {
3526                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_F,
3527                                            finderArgs, this);
3528                    }
3529    
3530                    if (result instanceof DLFileRank) {
3531                            DLFileRank dlFileRank = (DLFileRank)result;
3532    
3533                            if ((companyId != dlFileRank.getCompanyId()) ||
3534                                            (userId != dlFileRank.getUserId()) ||
3535                                            (fileEntryId != dlFileRank.getFileEntryId())) {
3536                                    result = null;
3537                            }
3538                    }
3539    
3540                    if (result == null) {
3541                            StringBundler query = new StringBundler(5);
3542    
3543                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
3544    
3545                            query.append(_FINDER_COLUMN_C_U_F_COMPANYID_2);
3546    
3547                            query.append(_FINDER_COLUMN_C_U_F_USERID_2);
3548    
3549                            query.append(_FINDER_COLUMN_C_U_F_FILEENTRYID_2);
3550    
3551                            String sql = query.toString();
3552    
3553                            Session session = null;
3554    
3555                            try {
3556                                    session = openSession();
3557    
3558                                    Query q = session.createQuery(sql);
3559    
3560                                    QueryPos qPos = QueryPos.getInstance(q);
3561    
3562                                    qPos.add(companyId);
3563    
3564                                    qPos.add(userId);
3565    
3566                                    qPos.add(fileEntryId);
3567    
3568                                    List<DLFileRank> list = q.list();
3569    
3570                                    if (list.isEmpty()) {
3571                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
3572                                                    finderArgs, list);
3573                                    }
3574                                    else {
3575                                            DLFileRank dlFileRank = list.get(0);
3576    
3577                                            result = dlFileRank;
3578    
3579                                            cacheResult(dlFileRank);
3580    
3581                                            if ((dlFileRank.getCompanyId() != companyId) ||
3582                                                            (dlFileRank.getUserId() != userId) ||
3583                                                            (dlFileRank.getFileEntryId() != fileEntryId)) {
3584                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
3585                                                            finderArgs, dlFileRank);
3586                                            }
3587                                    }
3588                            }
3589                            catch (Exception e) {
3590                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F,
3591                                            finderArgs);
3592    
3593                                    throw processException(e);
3594                            }
3595                            finally {
3596                                    closeSession(session);
3597                            }
3598                    }
3599    
3600                    if (result instanceof List<?>) {
3601                            return null;
3602                    }
3603                    else {
3604                            return (DLFileRank)result;
3605                    }
3606            }
3607    
3608            /**
3609             * Removes the document library file rank where companyId = &#63; and userId = &#63; and fileEntryId = &#63; from the database.
3610             *
3611             * @param companyId the company ID
3612             * @param userId the user ID
3613             * @param fileEntryId the file entry ID
3614             * @return the document library file rank that was removed
3615             * @throws SystemException if a system exception occurred
3616             */
3617            public DLFileRank removeByC_U_F(long companyId, long userId,
3618                    long fileEntryId) throws NoSuchFileRankException, SystemException {
3619                    DLFileRank dlFileRank = findByC_U_F(companyId, userId, fileEntryId);
3620    
3621                    return remove(dlFileRank);
3622            }
3623    
3624            /**
3625             * Returns the number of document library file ranks where companyId = &#63; and userId = &#63; and fileEntryId = &#63;.
3626             *
3627             * @param companyId the company ID
3628             * @param userId the user ID
3629             * @param fileEntryId the file entry ID
3630             * @return the number of matching document library file ranks
3631             * @throws SystemException if a system exception occurred
3632             */
3633            public int countByC_U_F(long companyId, long userId, long fileEntryId)
3634                    throws SystemException {
3635                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_U_F;
3636    
3637                    Object[] finderArgs = new Object[] { companyId, userId, fileEntryId };
3638    
3639                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3640                                    this);
3641    
3642                    if (count == null) {
3643                            StringBundler query = new StringBundler(4);
3644    
3645                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
3646    
3647                            query.append(_FINDER_COLUMN_C_U_F_COMPANYID_2);
3648    
3649                            query.append(_FINDER_COLUMN_C_U_F_USERID_2);
3650    
3651                            query.append(_FINDER_COLUMN_C_U_F_FILEENTRYID_2);
3652    
3653                            String sql = query.toString();
3654    
3655                            Session session = null;
3656    
3657                            try {
3658                                    session = openSession();
3659    
3660                                    Query q = session.createQuery(sql);
3661    
3662                                    QueryPos qPos = QueryPos.getInstance(q);
3663    
3664                                    qPos.add(companyId);
3665    
3666                                    qPos.add(userId);
3667    
3668                                    qPos.add(fileEntryId);
3669    
3670                                    count = (Long)q.uniqueResult();
3671    
3672                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3673                            }
3674                            catch (Exception e) {
3675                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3676    
3677                                    throw processException(e);
3678                            }
3679                            finally {
3680                                    closeSession(session);
3681                            }
3682                    }
3683    
3684                    return count.intValue();
3685            }
3686    
3687            private static final String _FINDER_COLUMN_C_U_F_COMPANYID_2 = "dlFileRank.companyId = ? AND ";
3688            private static final String _FINDER_COLUMN_C_U_F_USERID_2 = "dlFileRank.userId = ? AND ";
3689            private static final String _FINDER_COLUMN_C_U_F_FILEENTRYID_2 = "dlFileRank.fileEntryId = ?";
3690    
3691            /**
3692             * Caches the document library file rank in the entity cache if it is enabled.
3693             *
3694             * @param dlFileRank the document library file rank
3695             */
3696            public void cacheResult(DLFileRank dlFileRank) {
3697                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
3698                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
3699    
3700                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
3701                            new Object[] { dlFileRank.getUuid(), dlFileRank.getGroupId() },
3702                            dlFileRank);
3703    
3704                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
3705                            new Object[] {
3706                                    dlFileRank.getCompanyId(), dlFileRank.getUserId(),
3707                                    dlFileRank.getFileEntryId()
3708                            }, dlFileRank);
3709    
3710                    dlFileRank.resetOriginalValues();
3711            }
3712    
3713            /**
3714             * Caches the document library file ranks in the entity cache if it is enabled.
3715             *
3716             * @param dlFileRanks the document library file ranks
3717             */
3718            public void cacheResult(List<DLFileRank> dlFileRanks) {
3719                    for (DLFileRank dlFileRank : dlFileRanks) {
3720                            if (EntityCacheUtil.getResult(
3721                                                    DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
3722                                                    DLFileRankImpl.class, dlFileRank.getPrimaryKey()) == null) {
3723                                    cacheResult(dlFileRank);
3724                            }
3725                            else {
3726                                    dlFileRank.resetOriginalValues();
3727                            }
3728                    }
3729            }
3730    
3731            /**
3732             * Clears the cache for all document library file ranks.
3733             *
3734             * <p>
3735             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3736             * </p>
3737             */
3738            @Override
3739            public void clearCache() {
3740                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
3741                            CacheRegistryUtil.clear(DLFileRankImpl.class.getName());
3742                    }
3743    
3744                    EntityCacheUtil.clearCache(DLFileRankImpl.class.getName());
3745    
3746                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3747                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3748                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3749            }
3750    
3751            /**
3752             * Clears the cache for the document library file rank.
3753             *
3754             * <p>
3755             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3756             * </p>
3757             */
3758            @Override
3759            public void clearCache(DLFileRank dlFileRank) {
3760                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
3761                            DLFileRankImpl.class, dlFileRank.getPrimaryKey());
3762    
3763                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3764                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3765    
3766                    clearUniqueFindersCache(dlFileRank);
3767            }
3768    
3769            @Override
3770            public void clearCache(List<DLFileRank> dlFileRanks) {
3771                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3772                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3773    
3774                    for (DLFileRank dlFileRank : dlFileRanks) {
3775                            EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
3776                                    DLFileRankImpl.class, dlFileRank.getPrimaryKey());
3777    
3778                            clearUniqueFindersCache(dlFileRank);
3779                    }
3780            }
3781    
3782            protected void cacheUniqueFindersCache(DLFileRank dlFileRank) {
3783                    if (dlFileRank.isNew()) {
3784                            Object[] args = new Object[] {
3785                                            dlFileRank.getUuid(), dlFileRank.getGroupId()
3786                                    };
3787    
3788                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
3789                                    Long.valueOf(1));
3790                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
3791                                    dlFileRank);
3792    
3793                            args = new Object[] {
3794                                            dlFileRank.getCompanyId(), dlFileRank.getUserId(),
3795                                            dlFileRank.getFileEntryId()
3796                                    };
3797    
3798                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F, args,
3799                                    Long.valueOf(1));
3800                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F, args,
3801                                    dlFileRank);
3802                    }
3803                    else {
3804                            DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
3805    
3806                            if ((dlFileRankModelImpl.getColumnBitmask() &
3807                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
3808                                    Object[] args = new Object[] {
3809                                                    dlFileRank.getUuid(), dlFileRank.getGroupId()
3810                                            };
3811    
3812                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
3813                                            Long.valueOf(1));
3814                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
3815                                            dlFileRank);
3816                            }
3817    
3818                            if ((dlFileRankModelImpl.getColumnBitmask() &
3819                                            FINDER_PATH_FETCH_BY_C_U_F.getColumnBitmask()) != 0) {
3820                                    Object[] args = new Object[] {
3821                                                    dlFileRank.getCompanyId(), dlFileRank.getUserId(),
3822                                                    dlFileRank.getFileEntryId()
3823                                            };
3824    
3825                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F, args,
3826                                            Long.valueOf(1));
3827                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F, args,
3828                                            dlFileRank);
3829                            }
3830                    }
3831            }
3832    
3833            protected void clearUniqueFindersCache(DLFileRank dlFileRank) {
3834                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
3835    
3836                    Object[] args = new Object[] {
3837                                    dlFileRank.getUuid(), dlFileRank.getGroupId()
3838                            };
3839    
3840                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
3841                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
3842    
3843                    if ((dlFileRankModelImpl.getColumnBitmask() &
3844                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
3845                            args = new Object[] {
3846                                            dlFileRankModelImpl.getOriginalUuid(),
3847                                            dlFileRankModelImpl.getOriginalGroupId()
3848                                    };
3849    
3850                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
3851                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
3852                    }
3853    
3854                    args = new Object[] {
3855                                    dlFileRank.getCompanyId(), dlFileRank.getUserId(),
3856                                    dlFileRank.getFileEntryId()
3857                            };
3858    
3859                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_F, args);
3860                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F, args);
3861    
3862                    if ((dlFileRankModelImpl.getColumnBitmask() &
3863                                    FINDER_PATH_FETCH_BY_C_U_F.getColumnBitmask()) != 0) {
3864                            args = new Object[] {
3865                                            dlFileRankModelImpl.getOriginalCompanyId(),
3866                                            dlFileRankModelImpl.getOriginalUserId(),
3867                                            dlFileRankModelImpl.getOriginalFileEntryId()
3868                                    };
3869    
3870                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_F, args);
3871                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F, args);
3872                    }
3873            }
3874    
3875            /**
3876             * Creates a new document library file rank with the primary key. Does not add the document library file rank to the database.
3877             *
3878             * @param fileRankId the primary key for the new document library file rank
3879             * @return the new document library file rank
3880             */
3881            public DLFileRank create(long fileRankId) {
3882                    DLFileRank dlFileRank = new DLFileRankImpl();
3883    
3884                    dlFileRank.setNew(true);
3885                    dlFileRank.setPrimaryKey(fileRankId);
3886    
3887                    String uuid = PortalUUIDUtil.generate();
3888    
3889                    dlFileRank.setUuid(uuid);
3890    
3891                    return dlFileRank;
3892            }
3893    
3894            /**
3895             * Removes the document library file rank with the primary key from the database. Also notifies the appropriate model listeners.
3896             *
3897             * @param fileRankId the primary key of the document library file rank
3898             * @return the document library file rank that was removed
3899             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
3900             * @throws SystemException if a system exception occurred
3901             */
3902            public DLFileRank remove(long fileRankId)
3903                    throws NoSuchFileRankException, SystemException {
3904                    return remove((Serializable)fileRankId);
3905            }
3906    
3907            /**
3908             * Removes the document library file rank with the primary key from the database. Also notifies the appropriate model listeners.
3909             *
3910             * @param primaryKey the primary key of the document library file rank
3911             * @return the document library file rank that was removed
3912             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
3913             * @throws SystemException if a system exception occurred
3914             */
3915            @Override
3916            public DLFileRank remove(Serializable primaryKey)
3917                    throws NoSuchFileRankException, SystemException {
3918                    Session session = null;
3919    
3920                    try {
3921                            session = openSession();
3922    
3923                            DLFileRank dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
3924                                            primaryKey);
3925    
3926                            if (dlFileRank == null) {
3927                                    if (_log.isWarnEnabled()) {
3928                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3929                                    }
3930    
3931                                    throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3932                                            primaryKey);
3933                            }
3934    
3935                            return remove(dlFileRank);
3936                    }
3937                    catch (NoSuchFileRankException nsee) {
3938                            throw nsee;
3939                    }
3940                    catch (Exception e) {
3941                            throw processException(e);
3942                    }
3943                    finally {
3944                            closeSession(session);
3945                    }
3946            }
3947    
3948            @Override
3949            protected DLFileRank removeImpl(DLFileRank dlFileRank)
3950                    throws SystemException {
3951                    dlFileRank = toUnwrappedModel(dlFileRank);
3952    
3953                    Session session = null;
3954    
3955                    try {
3956                            session = openSession();
3957    
3958                            if (!session.contains(dlFileRank)) {
3959                                    dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
3960                                                    dlFileRank.getPrimaryKeyObj());
3961                            }
3962    
3963                            if (dlFileRank != null) {
3964                                    session.delete(dlFileRank);
3965                            }
3966                    }
3967                    catch (Exception e) {
3968                            throw processException(e);
3969                    }
3970                    finally {
3971                            closeSession(session);
3972                    }
3973    
3974                    if (dlFileRank != null) {
3975                            clearCache(dlFileRank);
3976                    }
3977    
3978                    return dlFileRank;
3979            }
3980    
3981            @Override
3982            public DLFileRank updateImpl(
3983                    com.liferay.portlet.documentlibrary.model.DLFileRank dlFileRank)
3984                    throws SystemException {
3985                    dlFileRank = toUnwrappedModel(dlFileRank);
3986    
3987                    boolean isNew = dlFileRank.isNew();
3988    
3989                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
3990    
3991                    if (Validator.isNull(dlFileRank.getUuid())) {
3992                            String uuid = PortalUUIDUtil.generate();
3993    
3994                            dlFileRank.setUuid(uuid);
3995                    }
3996    
3997                    Session session = null;
3998    
3999                    try {
4000                            session = openSession();
4001    
4002                            if (dlFileRank.isNew()) {
4003                                    session.save(dlFileRank);
4004    
4005                                    dlFileRank.setNew(false);
4006                            }
4007                            else {
4008                                    session.merge(dlFileRank);
4009                            }
4010                    }
4011                    catch (Exception e) {
4012                            throw processException(e);
4013                    }
4014                    finally {
4015                            closeSession(session);
4016                    }
4017    
4018                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4019    
4020                    if (isNew || !DLFileRankModelImpl.COLUMN_BITMASK_ENABLED) {
4021                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4022                    }
4023    
4024                    else {
4025                            if ((dlFileRankModelImpl.getColumnBitmask() &
4026                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4027                                    Object[] args = new Object[] {
4028                                                    dlFileRankModelImpl.getOriginalUuid()
4029                                            };
4030    
4031                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4032                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4033                                            args);
4034    
4035                                    args = new Object[] { dlFileRankModelImpl.getUuid() };
4036    
4037                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4038                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4039                                            args);
4040                            }
4041    
4042                            if ((dlFileRankModelImpl.getColumnBitmask() &
4043                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4044                                    Object[] args = new Object[] {
4045                                                    dlFileRankModelImpl.getOriginalUuid(),
4046                                                    dlFileRankModelImpl.getOriginalCompanyId()
4047                                            };
4048    
4049                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4050                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4051                                            args);
4052    
4053                                    args = new Object[] {
4054                                                    dlFileRankModelImpl.getUuid(),
4055                                                    dlFileRankModelImpl.getCompanyId()
4056                                            };
4057    
4058                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4059                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4060                                            args);
4061                            }
4062    
4063                            if ((dlFileRankModelImpl.getColumnBitmask() &
4064                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
4065                                    Object[] args = new Object[] {
4066                                                    dlFileRankModelImpl.getOriginalUserId()
4067                                            };
4068    
4069                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4070                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4071                                            args);
4072    
4073                                    args = new Object[] { dlFileRankModelImpl.getUserId() };
4074    
4075                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
4076                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
4077                                            args);
4078                            }
4079    
4080                            if ((dlFileRankModelImpl.getColumnBitmask() &
4081                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
4082                                    Object[] args = new Object[] {
4083                                                    dlFileRankModelImpl.getOriginalFileEntryId()
4084                                            };
4085    
4086                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
4087                                            args);
4088                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
4089                                            args);
4090    
4091                                    args = new Object[] { dlFileRankModelImpl.getFileEntryId() };
4092    
4093                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
4094                                            args);
4095                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
4096                                            args);
4097                            }
4098    
4099                            if ((dlFileRankModelImpl.getColumnBitmask() &
4100                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
4101                                    Object[] args = new Object[] {
4102                                                    dlFileRankModelImpl.getOriginalGroupId(),
4103                                                    dlFileRankModelImpl.getOriginalUserId()
4104                                            };
4105    
4106                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
4107                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
4108                                            args);
4109    
4110                                    args = new Object[] {
4111                                                    dlFileRankModelImpl.getGroupId(),
4112                                                    dlFileRankModelImpl.getUserId()
4113                                            };
4114    
4115                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
4116                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
4117                                            args);
4118                            }
4119    
4120                            if ((dlFileRankModelImpl.getColumnBitmask() &
4121                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A.getColumnBitmask()) != 0) {
4122                                    Object[] args = new Object[] {
4123                                                    dlFileRankModelImpl.getOriginalGroupId(),
4124                                                    dlFileRankModelImpl.getOriginalUserId(),
4125                                                    dlFileRankModelImpl.getOriginalActive()
4126                                            };
4127    
4128                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_A, args);
4129                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A,
4130                                            args);
4131    
4132                                    args = new Object[] {
4133                                                    dlFileRankModelImpl.getGroupId(),
4134                                                    dlFileRankModelImpl.getUserId(),
4135                                                    dlFileRankModelImpl.getActive()
4136                                            };
4137    
4138                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_A, args);
4139                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_A,
4140                                            args);
4141                            }
4142                    }
4143    
4144                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
4145                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
4146    
4147                    clearUniqueFindersCache(dlFileRank);
4148                    cacheUniqueFindersCache(dlFileRank);
4149    
4150                    return dlFileRank;
4151            }
4152    
4153            protected DLFileRank toUnwrappedModel(DLFileRank dlFileRank) {
4154                    if (dlFileRank instanceof DLFileRankImpl) {
4155                            return dlFileRank;
4156                    }
4157    
4158                    DLFileRankImpl dlFileRankImpl = new DLFileRankImpl();
4159    
4160                    dlFileRankImpl.setNew(dlFileRank.isNew());
4161                    dlFileRankImpl.setPrimaryKey(dlFileRank.getPrimaryKey());
4162    
4163                    dlFileRankImpl.setUuid(dlFileRank.getUuid());
4164                    dlFileRankImpl.setFileRankId(dlFileRank.getFileRankId());
4165                    dlFileRankImpl.setGroupId(dlFileRank.getGroupId());
4166                    dlFileRankImpl.setCompanyId(dlFileRank.getCompanyId());
4167                    dlFileRankImpl.setUserId(dlFileRank.getUserId());
4168                    dlFileRankImpl.setUserName(dlFileRank.getUserName());
4169                    dlFileRankImpl.setCreateDate(dlFileRank.getCreateDate());
4170                    dlFileRankImpl.setModifiedDate(dlFileRank.getModifiedDate());
4171                    dlFileRankImpl.setFileEntryId(dlFileRank.getFileEntryId());
4172                    dlFileRankImpl.setActive(dlFileRank.isActive());
4173    
4174                    return dlFileRankImpl;
4175            }
4176    
4177            /**
4178             * Returns the document library file rank with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4179             *
4180             * @param primaryKey the primary key of the document library file rank
4181             * @return the document library file rank
4182             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
4183             * @throws SystemException if a system exception occurred
4184             */
4185            @Override
4186            public DLFileRank findByPrimaryKey(Serializable primaryKey)
4187                    throws NoSuchFileRankException, SystemException {
4188                    DLFileRank dlFileRank = fetchByPrimaryKey(primaryKey);
4189    
4190                    if (dlFileRank == null) {
4191                            if (_log.isWarnEnabled()) {
4192                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4193                            }
4194    
4195                            throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4196                                    primaryKey);
4197                    }
4198    
4199                    return dlFileRank;
4200            }
4201    
4202            /**
4203             * 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.
4204             *
4205             * @param fileRankId the primary key of the document library file rank
4206             * @return the document library file rank
4207             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
4208             * @throws SystemException if a system exception occurred
4209             */
4210            public DLFileRank findByPrimaryKey(long fileRankId)
4211                    throws NoSuchFileRankException, SystemException {
4212                    return findByPrimaryKey((Serializable)fileRankId);
4213            }
4214    
4215            /**
4216             * Returns the document library file rank with the primary key or returns <code>null</code> if it could not be found.
4217             *
4218             * @param primaryKey the primary key of the document library file rank
4219             * @return the document library file rank, or <code>null</code> if a document library file rank with the primary key could not be found
4220             * @throws SystemException if a system exception occurred
4221             */
4222            @Override
4223            public DLFileRank fetchByPrimaryKey(Serializable primaryKey)
4224                    throws SystemException {
4225                    DLFileRank dlFileRank = (DLFileRank)EntityCacheUtil.getResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
4226                                    DLFileRankImpl.class, primaryKey);
4227    
4228                    if (dlFileRank == _nullDLFileRank) {
4229                            return null;
4230                    }
4231    
4232                    if (dlFileRank == null) {
4233                            Session session = null;
4234    
4235                            try {
4236                                    session = openSession();
4237    
4238                                    dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
4239                                                    primaryKey);
4240    
4241                                    if (dlFileRank != null) {
4242                                            cacheResult(dlFileRank);
4243                                    }
4244                                    else {
4245                                            EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
4246                                                    DLFileRankImpl.class, primaryKey, _nullDLFileRank);
4247                                    }
4248                            }
4249                            catch (Exception e) {
4250                                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
4251                                            DLFileRankImpl.class, primaryKey);
4252    
4253                                    throw processException(e);
4254                            }
4255                            finally {
4256                                    closeSession(session);
4257                            }
4258                    }
4259    
4260                    return dlFileRank;
4261            }
4262    
4263            /**
4264             * Returns the document library file rank with the primary key or returns <code>null</code> if it could not be found.
4265             *
4266             * @param fileRankId the primary key of the document library file rank
4267             * @return the document library file rank, or <code>null</code> if a document library file rank with the primary key could not be found
4268             * @throws SystemException if a system exception occurred
4269             */
4270            public DLFileRank fetchByPrimaryKey(long fileRankId)
4271                    throws SystemException {
4272                    return fetchByPrimaryKey((Serializable)fileRankId);
4273            }
4274    
4275            /**
4276             * Returns all the document library file ranks.
4277             *
4278             * @return the document library file ranks
4279             * @throws SystemException if a system exception occurred
4280             */
4281            public List<DLFileRank> findAll() throws SystemException {
4282                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4283            }
4284    
4285            /**
4286             * Returns a range of all the document library file ranks.
4287             *
4288             * <p>
4289             * 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.
4290             * </p>
4291             *
4292             * @param start the lower bound of the range of document library file ranks
4293             * @param end the upper bound of the range of document library file ranks (not inclusive)
4294             * @return the range of document library file ranks
4295             * @throws SystemException if a system exception occurred
4296             */
4297            public List<DLFileRank> findAll(int start, int end)
4298                    throws SystemException {
4299                    return findAll(start, end, null);
4300            }
4301    
4302            /**
4303             * Returns an ordered range of all the document library file ranks.
4304             *
4305             * <p>
4306             * 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.
4307             * </p>
4308             *
4309             * @param start the lower bound of the range of document library file ranks
4310             * @param end the upper bound of the range of document library file ranks (not inclusive)
4311             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4312             * @return the ordered range of document library file ranks
4313             * @throws SystemException if a system exception occurred
4314             */
4315            public List<DLFileRank> findAll(int start, int end,
4316                    OrderByComparator orderByComparator) throws SystemException {
4317                    boolean pagination = true;
4318                    FinderPath finderPath = null;
4319                    Object[] finderArgs = null;
4320    
4321                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4322                                    (orderByComparator == null)) {
4323                            pagination = false;
4324                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4325                            finderArgs = FINDER_ARGS_EMPTY;
4326                    }
4327                    else {
4328                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4329                            finderArgs = new Object[] { start, end, orderByComparator };
4330                    }
4331    
4332                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
4333                                    finderArgs, this);
4334    
4335                    if (list == null) {
4336                            StringBundler query = null;
4337                            String sql = null;
4338    
4339                            if (orderByComparator != null) {
4340                                    query = new StringBundler(2 +
4341                                                    (orderByComparator.getOrderByFields().length * 3));
4342    
4343                                    query.append(_SQL_SELECT_DLFILERANK);
4344    
4345                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4346                                            orderByComparator);
4347    
4348                                    sql = query.toString();
4349                            }
4350                            else {
4351                                    sql = _SQL_SELECT_DLFILERANK;
4352    
4353                                    if (pagination) {
4354                                            sql = sql.concat(DLFileRankModelImpl.ORDER_BY_JPQL);
4355                                    }
4356                            }
4357    
4358                            Session session = null;
4359    
4360                            try {
4361                                    session = openSession();
4362    
4363                                    Query q = session.createQuery(sql);
4364    
4365                                    if (!pagination) {
4366                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
4367                                                            start, end, false);
4368    
4369                                            Collections.sort(list);
4370    
4371                                            list = new UnmodifiableList<DLFileRank>(list);
4372                                    }
4373                                    else {
4374                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
4375                                                            start, end);
4376                                    }
4377    
4378                                    cacheResult(list);
4379    
4380                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4381                            }
4382                            catch (Exception e) {
4383                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4384    
4385                                    throw processException(e);
4386                            }
4387                            finally {
4388                                    closeSession(session);
4389                            }
4390                    }
4391    
4392                    return list;
4393            }
4394    
4395            /**
4396             * Removes all the document library file ranks from the database.
4397             *
4398             * @throws SystemException if a system exception occurred
4399             */
4400            public void removeAll() throws SystemException {
4401                    for (DLFileRank dlFileRank : findAll()) {
4402                            remove(dlFileRank);
4403                    }
4404            }
4405    
4406            /**
4407             * Returns the number of document library file ranks.
4408             *
4409             * @return the number of document library file ranks
4410             * @throws SystemException if a system exception occurred
4411             */
4412            public int countAll() throws SystemException {
4413                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4414                                    FINDER_ARGS_EMPTY, this);
4415    
4416                    if (count == null) {
4417                            Session session = null;
4418    
4419                            try {
4420                                    session = openSession();
4421    
4422                                    Query q = session.createQuery(_SQL_COUNT_DLFILERANK);
4423    
4424                                    count = (Long)q.uniqueResult();
4425    
4426                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4427                                            FINDER_ARGS_EMPTY, count);
4428                            }
4429                            catch (Exception e) {
4430                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
4431                                            FINDER_ARGS_EMPTY);
4432    
4433                                    throw processException(e);
4434                            }
4435                            finally {
4436                                    closeSession(session);
4437                            }
4438                    }
4439    
4440                    return count.intValue();
4441            }
4442    
4443            /**
4444             * Initializes the document library file rank persistence.
4445             */
4446            public void afterPropertiesSet() {
4447                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4448                                            com.liferay.portal.util.PropsUtil.get(
4449                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileRank")));
4450    
4451                    if (listenerClassNames.length > 0) {
4452                            try {
4453                                    List<ModelListener<DLFileRank>> listenersList = new ArrayList<ModelListener<DLFileRank>>();
4454    
4455                                    for (String listenerClassName : listenerClassNames) {
4456                                            listenersList.add((ModelListener<DLFileRank>)InstanceFactory.newInstance(
4457                                                            listenerClassName));
4458                                    }
4459    
4460                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4461                            }
4462                            catch (Exception e) {
4463                                    _log.error(e);
4464                            }
4465                    }
4466            }
4467    
4468            public void destroy() {
4469                    EntityCacheUtil.removeCache(DLFileRankImpl.class.getName());
4470                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4471                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4472                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4473            }
4474    
4475            private static final String _SQL_SELECT_DLFILERANK = "SELECT dlFileRank FROM DLFileRank dlFileRank";
4476            private static final String _SQL_SELECT_DLFILERANK_WHERE = "SELECT dlFileRank FROM DLFileRank dlFileRank WHERE ";
4477            private static final String _SQL_COUNT_DLFILERANK = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank";
4478            private static final String _SQL_COUNT_DLFILERANK_WHERE = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank WHERE ";
4479            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileRank.";
4480            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileRank exists with the primary key ";
4481            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileRank exists with the key {";
4482            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4483            private static Log _log = LogFactoryUtil.getLog(DLFileRankPersistenceImpl.class);
4484            private static DLFileRank _nullDLFileRank = new DLFileRankImpl() {
4485                            @Override
4486                            public Object clone() {
4487                                    return this;
4488                            }
4489    
4490                            @Override
4491                            public CacheModel<DLFileRank> toCacheModel() {
4492                                    return _nullDLFileRankCacheModel;
4493                            }
4494                    };
4495    
4496            private static CacheModel<DLFileRank> _nullDLFileRankCacheModel = new CacheModel<DLFileRank>() {
4497                            public DLFileRank toEntityModel() {
4498                                    return _nullDLFileRank;
4499                            }
4500                    };
4501    }