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