001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
039    import com.liferay.portal.service.persistence.LayoutPersistence;
040    import com.liferay.portal.service.persistence.ResourcePersistence;
041    import com.liferay.portal.service.persistence.UserPersistence;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.documentlibrary.NoSuchFileRankException;
045    import com.liferay.portlet.documentlibrary.model.DLFileRank;
046    import com.liferay.portlet.documentlibrary.model.impl.DLFileRankImpl;
047    import com.liferay.portlet.documentlibrary.model.impl.DLFileRankModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the document library file rank service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see DLFileRankPersistence
064     * @see DLFileRankUtil
065     * @generated
066     */
067    public class DLFileRankPersistenceImpl extends BasePersistenceImpl<DLFileRank>
068            implements DLFileRankPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * 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.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = DLFileRankImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
080                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
082                            new String[] {
083                                    Long.class.getName(),
084                                    
085                            "java.lang.Integer", "java.lang.Integer",
086                                    "com.liferay.portal.kernel.util.OrderByComparator"
087                            });
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
089                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
090                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
092                            new String[] { Long.class.getName() },
093                            DLFileRankModelImpl.USERID_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
095                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
097                            new String[] { Long.class.getName() });
098            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID =
099                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
100                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFileEntryId",
102                            new String[] {
103                                    Long.class.getName(),
104                                    
105                            "java.lang.Integer", "java.lang.Integer",
106                                    "com.liferay.portal.kernel.util.OrderByComparator"
107                            });
108            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID =
109                    new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
110                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFileEntryId",
112                            new String[] { Long.class.getName() },
113                            DLFileRankModelImpl.FILEENTRYID_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYID = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
115                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileEntryId",
117                            new String[] { Long.class.getName() });
118            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
119                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
120                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
121                            new String[] {
122                                    Long.class.getName(), Long.class.getName(),
123                                    
124                            "java.lang.Integer", "java.lang.Integer",
125                                    "com.liferay.portal.kernel.util.OrderByComparator"
126                            });
127            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
128                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
130                            new String[] { Long.class.getName(), Long.class.getName() },
131                            DLFileRankModelImpl.GROUPID_COLUMN_BITMASK |
132                            DLFileRankModelImpl.USERID_COLUMN_BITMASK);
133            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
134                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
135                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
136                            new String[] { Long.class.getName(), Long.class.getName() });
137            public static final FinderPath FINDER_PATH_FETCH_BY_C_U_F = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
138                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
139                            FINDER_CLASS_NAME_ENTITY, "fetchByC_U_F",
140                            new String[] {
141                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
142                            },
143                            DLFileRankModelImpl.COMPANYID_COLUMN_BITMASK |
144                            DLFileRankModelImpl.USERID_COLUMN_BITMASK |
145                            DLFileRankModelImpl.FILEENTRYID_COLUMN_BITMASK);
146            public static final FinderPath FINDER_PATH_COUNT_BY_C_U_F = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
147                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
148                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_U_F",
149                            new String[] {
150                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
151                            });
152            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
153                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
154                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
155            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
156                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, DLFileRankImpl.class,
157                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
158            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
159                            DLFileRankModelImpl.FINDER_CACHE_ENABLED, Long.class,
160                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
161    
162            /**
163             * Caches the document library file rank in the entity cache if it is enabled.
164             *
165             * @param dlFileRank the document library file rank
166             */
167            public void cacheResult(DLFileRank dlFileRank) {
168                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
169                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
170    
171                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
172                            new Object[] {
173                                    Long.valueOf(dlFileRank.getCompanyId()),
174                                    Long.valueOf(dlFileRank.getUserId()),
175                                    Long.valueOf(dlFileRank.getFileEntryId())
176                            }, dlFileRank);
177    
178                    dlFileRank.resetOriginalValues();
179            }
180    
181            /**
182             * Caches the document library file ranks in the entity cache if it is enabled.
183             *
184             * @param dlFileRanks the document library file ranks
185             */
186            public void cacheResult(List<DLFileRank> dlFileRanks) {
187                    for (DLFileRank dlFileRank : dlFileRanks) {
188                            if (EntityCacheUtil.getResult(
189                                                    DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
190                                                    DLFileRankImpl.class, dlFileRank.getPrimaryKey()) == null) {
191                                    cacheResult(dlFileRank);
192                            }
193                            else {
194                                    dlFileRank.resetOriginalValues();
195                            }
196                    }
197            }
198    
199            /**
200             * Clears the cache for all document library file ranks.
201             *
202             * <p>
203             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
204             * </p>
205             */
206            @Override
207            public void clearCache() {
208                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
209                            CacheRegistryUtil.clear(DLFileRankImpl.class.getName());
210                    }
211    
212                    EntityCacheUtil.clearCache(DLFileRankImpl.class.getName());
213    
214                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
215                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
216                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
217            }
218    
219            /**
220             * Clears the cache for the document library file rank.
221             *
222             * <p>
223             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
224             * </p>
225             */
226            @Override
227            public void clearCache(DLFileRank dlFileRank) {
228                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
229                            DLFileRankImpl.class, dlFileRank.getPrimaryKey());
230    
231                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
232                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
233    
234                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F,
235                            new Object[] {
236                                    Long.valueOf(dlFileRank.getCompanyId()),
237                                    Long.valueOf(dlFileRank.getUserId()),
238                                    Long.valueOf(dlFileRank.getFileEntryId())
239                            });
240            }
241    
242            /**
243             * Creates a new document library file rank with the primary key. Does not add the document library file rank to the database.
244             *
245             * @param fileRankId the primary key for the new document library file rank
246             * @return the new document library file rank
247             */
248            public DLFileRank create(long fileRankId) {
249                    DLFileRank dlFileRank = new DLFileRankImpl();
250    
251                    dlFileRank.setNew(true);
252                    dlFileRank.setPrimaryKey(fileRankId);
253    
254                    return dlFileRank;
255            }
256    
257            /**
258             * Removes the document library file rank with the primary key from the database. Also notifies the appropriate model listeners.
259             *
260             * @param primaryKey the primary key of the document library file rank
261             * @return the document library file rank that was removed
262             * @throws com.liferay.portal.NoSuchModelException if a document library file rank with the primary key could not be found
263             * @throws SystemException if a system exception occurred
264             */
265            @Override
266            public DLFileRank remove(Serializable primaryKey)
267                    throws NoSuchModelException, SystemException {
268                    return remove(((Long)primaryKey).longValue());
269            }
270    
271            /**
272             * Removes the document library file rank with the primary key from the database. Also notifies the appropriate model listeners.
273             *
274             * @param fileRankId the primary key of the document library file rank
275             * @return the document library file rank that was removed
276             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
277             * @throws SystemException if a system exception occurred
278             */
279            public DLFileRank remove(long fileRankId)
280                    throws NoSuchFileRankException, SystemException {
281                    Session session = null;
282    
283                    try {
284                            session = openSession();
285    
286                            DLFileRank dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
287                                            Long.valueOf(fileRankId));
288    
289                            if (dlFileRank == null) {
290                                    if (_log.isWarnEnabled()) {
291                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileRankId);
292                                    }
293    
294                                    throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
295                                            fileRankId);
296                            }
297    
298                            return dlFileRankPersistence.remove(dlFileRank);
299                    }
300                    catch (NoSuchFileRankException nsee) {
301                            throw nsee;
302                    }
303                    catch (Exception e) {
304                            throw processException(e);
305                    }
306                    finally {
307                            closeSession(session);
308                    }
309            }
310    
311            /**
312             * Removes the document library file rank from the database. Also notifies the appropriate model listeners.
313             *
314             * @param dlFileRank the document library file rank
315             * @return the document library file rank that was removed
316             * @throws SystemException if a system exception occurred
317             */
318            @Override
319            public DLFileRank remove(DLFileRank dlFileRank) throws SystemException {
320                    return super.remove(dlFileRank);
321            }
322    
323            @Override
324            protected DLFileRank removeImpl(DLFileRank dlFileRank)
325                    throws SystemException {
326                    dlFileRank = toUnwrappedModel(dlFileRank);
327    
328                    Session session = null;
329    
330                    try {
331                            session = openSession();
332    
333                            BatchSessionUtil.delete(session, dlFileRank);
334                    }
335                    catch (Exception e) {
336                            throw processException(e);
337                    }
338                    finally {
339                            closeSession(session);
340                    }
341    
342                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
343                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
344    
345                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
346    
347                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F,
348                            new Object[] {
349                                    Long.valueOf(dlFileRankModelImpl.getCompanyId()),
350                                    Long.valueOf(dlFileRankModelImpl.getUserId()),
351                                    Long.valueOf(dlFileRankModelImpl.getFileEntryId())
352                            });
353    
354                    EntityCacheUtil.removeResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
355                            DLFileRankImpl.class, dlFileRank.getPrimaryKey());
356    
357                    return dlFileRank;
358            }
359    
360            @Override
361            public DLFileRank updateImpl(
362                    com.liferay.portlet.documentlibrary.model.DLFileRank dlFileRank,
363                    boolean merge) throws SystemException {
364                    dlFileRank = toUnwrappedModel(dlFileRank);
365    
366                    boolean isNew = dlFileRank.isNew();
367    
368                    DLFileRankModelImpl dlFileRankModelImpl = (DLFileRankModelImpl)dlFileRank;
369    
370                    Session session = null;
371    
372                    try {
373                            session = openSession();
374    
375                            BatchSessionUtil.update(session, dlFileRank, merge);
376    
377                            dlFileRank.setNew(false);
378                    }
379                    catch (Exception e) {
380                            throw processException(e);
381                    }
382                    finally {
383                            closeSession(session);
384                    }
385    
386                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
387    
388                    if (isNew || !DLFileRankModelImpl.COLUMN_BITMASK_ENABLED) {
389                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
390                    }
391    
392                    else {
393                            if ((dlFileRankModelImpl.getColumnBitmask() &
394                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
395                                    Object[] args = new Object[] {
396                                                    Long.valueOf(dlFileRankModelImpl.getOriginalUserId())
397                                            };
398    
399                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
400                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
401                                            args);
402    
403                                    args = new Object[] {
404                                                    Long.valueOf(dlFileRankModelImpl.getUserId())
405                                            };
406    
407                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
408                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
409                                            args);
410                            }
411    
412                            if ((dlFileRankModelImpl.getColumnBitmask() &
413                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
414                                    Object[] args = new Object[] {
415                                                    Long.valueOf(dlFileRankModelImpl.getOriginalFileEntryId())
416                                            };
417    
418                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
419                                            args);
420                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
421                                            args);
422    
423                                    args = new Object[] {
424                                                    Long.valueOf(dlFileRankModelImpl.getFileEntryId())
425                                            };
426    
427                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
428                                            args);
429                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
430                                            args);
431                            }
432    
433                            if ((dlFileRankModelImpl.getColumnBitmask() &
434                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
435                                    Object[] args = new Object[] {
436                                                    Long.valueOf(dlFileRankModelImpl.getOriginalGroupId()),
437                                                    Long.valueOf(dlFileRankModelImpl.getOriginalUserId())
438                                            };
439    
440                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
441                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
442                                            args);
443    
444                                    args = new Object[] {
445                                                    Long.valueOf(dlFileRankModelImpl.getGroupId()),
446                                                    Long.valueOf(dlFileRankModelImpl.getUserId())
447                                            };
448    
449                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
450                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
451                                            args);
452                            }
453                    }
454    
455                    EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
456                            DLFileRankImpl.class, dlFileRank.getPrimaryKey(), dlFileRank);
457    
458                    if (isNew) {
459                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
460                                    new Object[] {
461                                            Long.valueOf(dlFileRank.getCompanyId()),
462                                            Long.valueOf(dlFileRank.getUserId()),
463                                            Long.valueOf(dlFileRank.getFileEntryId())
464                                    }, dlFileRank);
465                    }
466                    else {
467                            if ((dlFileRankModelImpl.getColumnBitmask() &
468                                            FINDER_PATH_FETCH_BY_C_U_F.getColumnBitmask()) != 0) {
469                                    Object[] args = new Object[] {
470                                                    Long.valueOf(dlFileRankModelImpl.getOriginalCompanyId()),
471                                                    Long.valueOf(dlFileRankModelImpl.getOriginalUserId()),
472                                                    Long.valueOf(dlFileRankModelImpl.getOriginalFileEntryId())
473                                            };
474    
475                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_U_F, args);
476                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F, args);
477    
478                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
479                                            new Object[] {
480                                                    Long.valueOf(dlFileRank.getCompanyId()),
481                                                    Long.valueOf(dlFileRank.getUserId()),
482                                                    Long.valueOf(dlFileRank.getFileEntryId())
483                                            }, dlFileRank);
484                            }
485                    }
486    
487                    return dlFileRank;
488            }
489    
490            protected DLFileRank toUnwrappedModel(DLFileRank dlFileRank) {
491                    if (dlFileRank instanceof DLFileRankImpl) {
492                            return dlFileRank;
493                    }
494    
495                    DLFileRankImpl dlFileRankImpl = new DLFileRankImpl();
496    
497                    dlFileRankImpl.setNew(dlFileRank.isNew());
498                    dlFileRankImpl.setPrimaryKey(dlFileRank.getPrimaryKey());
499    
500                    dlFileRankImpl.setFileRankId(dlFileRank.getFileRankId());
501                    dlFileRankImpl.setGroupId(dlFileRank.getGroupId());
502                    dlFileRankImpl.setCompanyId(dlFileRank.getCompanyId());
503                    dlFileRankImpl.setUserId(dlFileRank.getUserId());
504                    dlFileRankImpl.setCreateDate(dlFileRank.getCreateDate());
505                    dlFileRankImpl.setFileEntryId(dlFileRank.getFileEntryId());
506    
507                    return dlFileRankImpl;
508            }
509    
510            /**
511             * Returns the document library file rank with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
512             *
513             * @param primaryKey the primary key of the document library file rank
514             * @return the document library file rank
515             * @throws com.liferay.portal.NoSuchModelException if a document library file rank with the primary key could not be found
516             * @throws SystemException if a system exception occurred
517             */
518            @Override
519            public DLFileRank findByPrimaryKey(Serializable primaryKey)
520                    throws NoSuchModelException, SystemException {
521                    return findByPrimaryKey(((Long)primaryKey).longValue());
522            }
523    
524            /**
525             * 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.
526             *
527             * @param fileRankId the primary key of the document library file rank
528             * @return the document library file rank
529             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
530             * @throws SystemException if a system exception occurred
531             */
532            public DLFileRank findByPrimaryKey(long fileRankId)
533                    throws NoSuchFileRankException, SystemException {
534                    DLFileRank dlFileRank = fetchByPrimaryKey(fileRankId);
535    
536                    if (dlFileRank == null) {
537                            if (_log.isWarnEnabled()) {
538                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileRankId);
539                            }
540    
541                            throw new NoSuchFileRankException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
542                                    fileRankId);
543                    }
544    
545                    return dlFileRank;
546            }
547    
548            /**
549             * Returns the document library file rank with the primary key or returns <code>null</code> if it could not be found.
550             *
551             * @param primaryKey the primary key of the document library file rank
552             * @return the document library file rank, or <code>null</code> if a document library file rank with the primary key could not be found
553             * @throws SystemException if a system exception occurred
554             */
555            @Override
556            public DLFileRank fetchByPrimaryKey(Serializable primaryKey)
557                    throws SystemException {
558                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
559            }
560    
561            /**
562             * Returns the document library file rank with the primary key or returns <code>null</code> if it could not be found.
563             *
564             * @param fileRankId the primary key of the document library file rank
565             * @return the document library file rank, or <code>null</code> if a document library file rank with the primary key could not be found
566             * @throws SystemException if a system exception occurred
567             */
568            public DLFileRank fetchByPrimaryKey(long fileRankId)
569                    throws SystemException {
570                    DLFileRank dlFileRank = (DLFileRank)EntityCacheUtil.getResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
571                                    DLFileRankImpl.class, fileRankId);
572    
573                    if (dlFileRank == _nullDLFileRank) {
574                            return null;
575                    }
576    
577                    if (dlFileRank == null) {
578                            Session session = null;
579    
580                            boolean hasException = false;
581    
582                            try {
583                                    session = openSession();
584    
585                                    dlFileRank = (DLFileRank)session.get(DLFileRankImpl.class,
586                                                    Long.valueOf(fileRankId));
587                            }
588                            catch (Exception e) {
589                                    hasException = true;
590    
591                                    throw processException(e);
592                            }
593                            finally {
594                                    if (dlFileRank != null) {
595                                            cacheResult(dlFileRank);
596                                    }
597                                    else if (!hasException) {
598                                            EntityCacheUtil.putResult(DLFileRankModelImpl.ENTITY_CACHE_ENABLED,
599                                                    DLFileRankImpl.class, fileRankId, _nullDLFileRank);
600                                    }
601    
602                                    closeSession(session);
603                            }
604                    }
605    
606                    return dlFileRank;
607            }
608    
609            /**
610             * Returns all the document library file ranks where userId = &#63;.
611             *
612             * @param userId the user ID
613             * @return the matching document library file ranks
614             * @throws SystemException if a system exception occurred
615             */
616            public List<DLFileRank> findByUserId(long userId) throws SystemException {
617                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
618            }
619    
620            /**
621             * Returns a range of all the document library file ranks where userId = &#63;.
622             *
623             * <p>
624             * 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.
625             * </p>
626             *
627             * @param userId the user ID
628             * @param start the lower bound of the range of document library file ranks
629             * @param end the upper bound of the range of document library file ranks (not inclusive)
630             * @return the range of matching document library file ranks
631             * @throws SystemException if a system exception occurred
632             */
633            public List<DLFileRank> findByUserId(long userId, int start, int end)
634                    throws SystemException {
635                    return findByUserId(userId, start, end, null);
636            }
637    
638            /**
639             * Returns an ordered range of all the document library file ranks where userId = &#63;.
640             *
641             * <p>
642             * 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.
643             * </p>
644             *
645             * @param userId the user ID
646             * @param start the lower bound of the range of document library file ranks
647             * @param end the upper bound of the range of document library file ranks (not inclusive)
648             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
649             * @return the ordered range of matching document library file ranks
650             * @throws SystemException if a system exception occurred
651             */
652            public List<DLFileRank> findByUserId(long userId, int start, int end,
653                    OrderByComparator orderByComparator) throws SystemException {
654                    FinderPath finderPath = null;
655                    Object[] finderArgs = null;
656    
657                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
658                                    (orderByComparator == null)) {
659                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
660                            finderArgs = new Object[] { userId };
661                    }
662                    else {
663                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
664                            finderArgs = new Object[] { userId, start, end, orderByComparator };
665                    }
666    
667                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
668                                    finderArgs, this);
669    
670                    if (list == null) {
671                            StringBundler query = null;
672    
673                            if (orderByComparator != null) {
674                                    query = new StringBundler(3 +
675                                                    (orderByComparator.getOrderByFields().length * 3));
676                            }
677                            else {
678                                    query = new StringBundler(3);
679                            }
680    
681                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
682    
683                            query.append(_FINDER_COLUMN_USERID_USERID_2);
684    
685                            if (orderByComparator != null) {
686                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
687                                            orderByComparator);
688                            }
689    
690                            else {
691                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
692                            }
693    
694                            String sql = query.toString();
695    
696                            Session session = null;
697    
698                            try {
699                                    session = openSession();
700    
701                                    Query q = session.createQuery(sql);
702    
703                                    QueryPos qPos = QueryPos.getInstance(q);
704    
705                                    qPos.add(userId);
706    
707                                    list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
708                                                    end);
709                            }
710                            catch (Exception e) {
711                                    throw processException(e);
712                            }
713                            finally {
714                                    if (list == null) {
715                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
716                                    }
717                                    else {
718                                            cacheResult(list);
719    
720                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
721                                    }
722    
723                                    closeSession(session);
724                            }
725                    }
726    
727                    return list;
728            }
729    
730            /**
731             * Returns the first document library file rank in the ordered set where userId = &#63;.
732             *
733             * <p>
734             * 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.
735             * </p>
736             *
737             * @param userId the user ID
738             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
739             * @return the first matching document library file rank
740             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
741             * @throws SystemException if a system exception occurred
742             */
743            public DLFileRank findByUserId_First(long userId,
744                    OrderByComparator orderByComparator)
745                    throws NoSuchFileRankException, SystemException {
746                    List<DLFileRank> list = findByUserId(userId, 0, 1, orderByComparator);
747    
748                    if (list.isEmpty()) {
749                            StringBundler msg = new StringBundler(4);
750    
751                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
752    
753                            msg.append("userId=");
754                            msg.append(userId);
755    
756                            msg.append(StringPool.CLOSE_CURLY_BRACE);
757    
758                            throw new NoSuchFileRankException(msg.toString());
759                    }
760                    else {
761                            return list.get(0);
762                    }
763            }
764    
765            /**
766             * Returns the last document library file rank in the ordered set where userId = &#63;.
767             *
768             * <p>
769             * 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.
770             * </p>
771             *
772             * @param userId the user ID
773             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
774             * @return the last matching document library file rank
775             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
776             * @throws SystemException if a system exception occurred
777             */
778            public DLFileRank findByUserId_Last(long userId,
779                    OrderByComparator orderByComparator)
780                    throws NoSuchFileRankException, SystemException {
781                    int count = countByUserId(userId);
782    
783                    List<DLFileRank> list = findByUserId(userId, count - 1, count,
784                                    orderByComparator);
785    
786                    if (list.isEmpty()) {
787                            StringBundler msg = new StringBundler(4);
788    
789                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
790    
791                            msg.append("userId=");
792                            msg.append(userId);
793    
794                            msg.append(StringPool.CLOSE_CURLY_BRACE);
795    
796                            throw new NoSuchFileRankException(msg.toString());
797                    }
798                    else {
799                            return list.get(0);
800                    }
801            }
802    
803            /**
804             * Returns the document library file ranks before and after the current document library file rank in the ordered set where userId = &#63;.
805             *
806             * <p>
807             * 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.
808             * </p>
809             *
810             * @param fileRankId the primary key of the current document library file rank
811             * @param userId the user ID
812             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
813             * @return the previous, current, and next document library file rank
814             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
815             * @throws SystemException if a system exception occurred
816             */
817            public DLFileRank[] findByUserId_PrevAndNext(long fileRankId, long userId,
818                    OrderByComparator orderByComparator)
819                    throws NoSuchFileRankException, SystemException {
820                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
821    
822                    Session session = null;
823    
824                    try {
825                            session = openSession();
826    
827                            DLFileRank[] array = new DLFileRankImpl[3];
828    
829                            array[0] = getByUserId_PrevAndNext(session, dlFileRank, userId,
830                                            orderByComparator, true);
831    
832                            array[1] = dlFileRank;
833    
834                            array[2] = getByUserId_PrevAndNext(session, dlFileRank, userId,
835                                            orderByComparator, false);
836    
837                            return array;
838                    }
839                    catch (Exception e) {
840                            throw processException(e);
841                    }
842                    finally {
843                            closeSession(session);
844                    }
845            }
846    
847            protected DLFileRank getByUserId_PrevAndNext(Session session,
848                    DLFileRank dlFileRank, long userId,
849                    OrderByComparator orderByComparator, boolean previous) {
850                    StringBundler query = null;
851    
852                    if (orderByComparator != null) {
853                            query = new StringBundler(6 +
854                                            (orderByComparator.getOrderByFields().length * 6));
855                    }
856                    else {
857                            query = new StringBundler(3);
858                    }
859    
860                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
861    
862                    query.append(_FINDER_COLUMN_USERID_USERID_2);
863    
864                    if (orderByComparator != null) {
865                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
866    
867                            if (orderByConditionFields.length > 0) {
868                                    query.append(WHERE_AND);
869                            }
870    
871                            for (int i = 0; i < orderByConditionFields.length; i++) {
872                                    query.append(_ORDER_BY_ENTITY_ALIAS);
873                                    query.append(orderByConditionFields[i]);
874    
875                                    if ((i + 1) < orderByConditionFields.length) {
876                                            if (orderByComparator.isAscending() ^ previous) {
877                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
878                                            }
879                                            else {
880                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
881                                            }
882                                    }
883                                    else {
884                                            if (orderByComparator.isAscending() ^ previous) {
885                                                    query.append(WHERE_GREATER_THAN);
886                                            }
887                                            else {
888                                                    query.append(WHERE_LESSER_THAN);
889                                            }
890                                    }
891                            }
892    
893                            query.append(ORDER_BY_CLAUSE);
894    
895                            String[] orderByFields = orderByComparator.getOrderByFields();
896    
897                            for (int i = 0; i < orderByFields.length; i++) {
898                                    query.append(_ORDER_BY_ENTITY_ALIAS);
899                                    query.append(orderByFields[i]);
900    
901                                    if ((i + 1) < orderByFields.length) {
902                                            if (orderByComparator.isAscending() ^ previous) {
903                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
904                                            }
905                                            else {
906                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
907                                            }
908                                    }
909                                    else {
910                                            if (orderByComparator.isAscending() ^ previous) {
911                                                    query.append(ORDER_BY_ASC);
912                                            }
913                                            else {
914                                                    query.append(ORDER_BY_DESC);
915                                            }
916                                    }
917                            }
918                    }
919    
920                    else {
921                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
922                    }
923    
924                    String sql = query.toString();
925    
926                    Query q = session.createQuery(sql);
927    
928                    q.setFirstResult(0);
929                    q.setMaxResults(2);
930    
931                    QueryPos qPos = QueryPos.getInstance(q);
932    
933                    qPos.add(userId);
934    
935                    if (orderByComparator != null) {
936                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
937    
938                            for (Object value : values) {
939                                    qPos.add(value);
940                            }
941                    }
942    
943                    List<DLFileRank> list = q.list();
944    
945                    if (list.size() == 2) {
946                            return list.get(1);
947                    }
948                    else {
949                            return null;
950                    }
951            }
952    
953            /**
954             * Returns all the document library file ranks where fileEntryId = &#63;.
955             *
956             * @param fileEntryId the file entry ID
957             * @return the matching document library file ranks
958             * @throws SystemException if a system exception occurred
959             */
960            public List<DLFileRank> findByFileEntryId(long fileEntryId)
961                    throws SystemException {
962                    return findByFileEntryId(fileEntryId, QueryUtil.ALL_POS,
963                            QueryUtil.ALL_POS, null);
964            }
965    
966            /**
967             * Returns a range of all the document library file ranks where fileEntryId = &#63;.
968             *
969             * <p>
970             * 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.
971             * </p>
972             *
973             * @param fileEntryId the file entry ID
974             * @param start the lower bound of the range of document library file ranks
975             * @param end the upper bound of the range of document library file ranks (not inclusive)
976             * @return the range of matching document library file ranks
977             * @throws SystemException if a system exception occurred
978             */
979            public List<DLFileRank> findByFileEntryId(long fileEntryId, int start,
980                    int end) throws SystemException {
981                    return findByFileEntryId(fileEntryId, start, end, null);
982            }
983    
984            /**
985             * Returns an ordered range of all the document library file ranks where fileEntryId = &#63;.
986             *
987             * <p>
988             * 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.
989             * </p>
990             *
991             * @param fileEntryId the file entry ID
992             * @param start the lower bound of the range of document library file ranks
993             * @param end the upper bound of the range of document library file ranks (not inclusive)
994             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
995             * @return the ordered range of matching document library file ranks
996             * @throws SystemException if a system exception occurred
997             */
998            public List<DLFileRank> findByFileEntryId(long fileEntryId, int start,
999                    int end, OrderByComparator orderByComparator) throws SystemException {
1000                    FinderPath finderPath = null;
1001                    Object[] finderArgs = null;
1002    
1003                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1004                                    (orderByComparator == null)) {
1005                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID;
1006                            finderArgs = new Object[] { fileEntryId };
1007                    }
1008                    else {
1009                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID;
1010                            finderArgs = new Object[] { fileEntryId, start, end, orderByComparator };
1011                    }
1012    
1013                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
1014                                    finderArgs, this);
1015    
1016                    if (list == null) {
1017                            StringBundler query = null;
1018    
1019                            if (orderByComparator != null) {
1020                                    query = new StringBundler(3 +
1021                                                    (orderByComparator.getOrderByFields().length * 3));
1022                            }
1023                            else {
1024                                    query = new StringBundler(3);
1025                            }
1026    
1027                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
1028    
1029                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1030    
1031                            if (orderByComparator != null) {
1032                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1033                                            orderByComparator);
1034                            }
1035    
1036                            else {
1037                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1038                            }
1039    
1040                            String sql = query.toString();
1041    
1042                            Session session = null;
1043    
1044                            try {
1045                                    session = openSession();
1046    
1047                                    Query q = session.createQuery(sql);
1048    
1049                                    QueryPos qPos = QueryPos.getInstance(q);
1050    
1051                                    qPos.add(fileEntryId);
1052    
1053                                    list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
1054                                                    end);
1055                            }
1056                            catch (Exception e) {
1057                                    throw processException(e);
1058                            }
1059                            finally {
1060                                    if (list == null) {
1061                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1062                                    }
1063                                    else {
1064                                            cacheResult(list);
1065    
1066                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1067                                    }
1068    
1069                                    closeSession(session);
1070                            }
1071                    }
1072    
1073                    return list;
1074            }
1075    
1076            /**
1077             * Returns the first document library file rank in the ordered set where fileEntryId = &#63;.
1078             *
1079             * <p>
1080             * 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.
1081             * </p>
1082             *
1083             * @param fileEntryId the file entry ID
1084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1085             * @return the first matching document library file rank
1086             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
1087             * @throws SystemException if a system exception occurred
1088             */
1089            public DLFileRank findByFileEntryId_First(long fileEntryId,
1090                    OrderByComparator orderByComparator)
1091                    throws NoSuchFileRankException, SystemException {
1092                    List<DLFileRank> list = findByFileEntryId(fileEntryId, 0, 1,
1093                                    orderByComparator);
1094    
1095                    if (list.isEmpty()) {
1096                            StringBundler msg = new StringBundler(4);
1097    
1098                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1099    
1100                            msg.append("fileEntryId=");
1101                            msg.append(fileEntryId);
1102    
1103                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1104    
1105                            throw new NoSuchFileRankException(msg.toString());
1106                    }
1107                    else {
1108                            return list.get(0);
1109                    }
1110            }
1111    
1112            /**
1113             * Returns the last document library file rank in the ordered set where fileEntryId = &#63;.
1114             *
1115             * <p>
1116             * 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.
1117             * </p>
1118             *
1119             * @param fileEntryId the file entry ID
1120             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1121             * @return the last matching document library file rank
1122             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
1123             * @throws SystemException if a system exception occurred
1124             */
1125            public DLFileRank findByFileEntryId_Last(long fileEntryId,
1126                    OrderByComparator orderByComparator)
1127                    throws NoSuchFileRankException, SystemException {
1128                    int count = countByFileEntryId(fileEntryId);
1129    
1130                    List<DLFileRank> list = findByFileEntryId(fileEntryId, count - 1,
1131                                    count, orderByComparator);
1132    
1133                    if (list.isEmpty()) {
1134                            StringBundler msg = new StringBundler(4);
1135    
1136                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1137    
1138                            msg.append("fileEntryId=");
1139                            msg.append(fileEntryId);
1140    
1141                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1142    
1143                            throw new NoSuchFileRankException(msg.toString());
1144                    }
1145                    else {
1146                            return list.get(0);
1147                    }
1148            }
1149    
1150            /**
1151             * Returns the document library file ranks before and after the current document library file rank in the ordered set where fileEntryId = &#63;.
1152             *
1153             * <p>
1154             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1155             * </p>
1156             *
1157             * @param fileRankId the primary key of the current document library file rank
1158             * @param fileEntryId the file entry ID
1159             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1160             * @return the previous, current, and next document library file rank
1161             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
1162             * @throws SystemException if a system exception occurred
1163             */
1164            public DLFileRank[] findByFileEntryId_PrevAndNext(long fileRankId,
1165                    long fileEntryId, OrderByComparator orderByComparator)
1166                    throws NoSuchFileRankException, SystemException {
1167                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1168    
1169                    Session session = null;
1170    
1171                    try {
1172                            session = openSession();
1173    
1174                            DLFileRank[] array = new DLFileRankImpl[3];
1175    
1176                            array[0] = getByFileEntryId_PrevAndNext(session, dlFileRank,
1177                                            fileEntryId, orderByComparator, true);
1178    
1179                            array[1] = dlFileRank;
1180    
1181                            array[2] = getByFileEntryId_PrevAndNext(session, dlFileRank,
1182                                            fileEntryId, orderByComparator, false);
1183    
1184                            return array;
1185                    }
1186                    catch (Exception e) {
1187                            throw processException(e);
1188                    }
1189                    finally {
1190                            closeSession(session);
1191                    }
1192            }
1193    
1194            protected DLFileRank getByFileEntryId_PrevAndNext(Session session,
1195                    DLFileRank dlFileRank, long fileEntryId,
1196                    OrderByComparator orderByComparator, boolean previous) {
1197                    StringBundler query = null;
1198    
1199                    if (orderByComparator != null) {
1200                            query = new StringBundler(6 +
1201                                            (orderByComparator.getOrderByFields().length * 6));
1202                    }
1203                    else {
1204                            query = new StringBundler(3);
1205                    }
1206    
1207                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1208    
1209                    query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1210    
1211                    if (orderByComparator != null) {
1212                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1213    
1214                            if (orderByConditionFields.length > 0) {
1215                                    query.append(WHERE_AND);
1216                            }
1217    
1218                            for (int i = 0; i < orderByConditionFields.length; i++) {
1219                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1220                                    query.append(orderByConditionFields[i]);
1221    
1222                                    if ((i + 1) < orderByConditionFields.length) {
1223                                            if (orderByComparator.isAscending() ^ previous) {
1224                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1225                                            }
1226                                            else {
1227                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1228                                            }
1229                                    }
1230                                    else {
1231                                            if (orderByComparator.isAscending() ^ previous) {
1232                                                    query.append(WHERE_GREATER_THAN);
1233                                            }
1234                                            else {
1235                                                    query.append(WHERE_LESSER_THAN);
1236                                            }
1237                                    }
1238                            }
1239    
1240                            query.append(ORDER_BY_CLAUSE);
1241    
1242                            String[] orderByFields = orderByComparator.getOrderByFields();
1243    
1244                            for (int i = 0; i < orderByFields.length; i++) {
1245                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1246                                    query.append(orderByFields[i]);
1247    
1248                                    if ((i + 1) < orderByFields.length) {
1249                                            if (orderByComparator.isAscending() ^ previous) {
1250                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1251                                            }
1252                                            else {
1253                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1254                                            }
1255                                    }
1256                                    else {
1257                                            if (orderByComparator.isAscending() ^ previous) {
1258                                                    query.append(ORDER_BY_ASC);
1259                                            }
1260                                            else {
1261                                                    query.append(ORDER_BY_DESC);
1262                                            }
1263                                    }
1264                            }
1265                    }
1266    
1267                    else {
1268                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1269                    }
1270    
1271                    String sql = query.toString();
1272    
1273                    Query q = session.createQuery(sql);
1274    
1275                    q.setFirstResult(0);
1276                    q.setMaxResults(2);
1277    
1278                    QueryPos qPos = QueryPos.getInstance(q);
1279    
1280                    qPos.add(fileEntryId);
1281    
1282                    if (orderByComparator != null) {
1283                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
1284    
1285                            for (Object value : values) {
1286                                    qPos.add(value);
1287                            }
1288                    }
1289    
1290                    List<DLFileRank> list = q.list();
1291    
1292                    if (list.size() == 2) {
1293                            return list.get(1);
1294                    }
1295                    else {
1296                            return null;
1297                    }
1298            }
1299    
1300            /**
1301             * Returns all the document library file ranks where groupId = &#63; and userId = &#63;.
1302             *
1303             * @param groupId the group ID
1304             * @param userId the user ID
1305             * @return the matching document library file ranks
1306             * @throws SystemException if a system exception occurred
1307             */
1308            public List<DLFileRank> findByG_U(long groupId, long userId)
1309                    throws SystemException {
1310                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1311                            null);
1312            }
1313    
1314            /**
1315             * Returns a range of all the document library file ranks where groupId = &#63; and userId = &#63;.
1316             *
1317             * <p>
1318             * 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.
1319             * </p>
1320             *
1321             * @param groupId the group ID
1322             * @param userId the user ID
1323             * @param start the lower bound of the range of document library file ranks
1324             * @param end the upper bound of the range of document library file ranks (not inclusive)
1325             * @return the range of matching document library file ranks
1326             * @throws SystemException if a system exception occurred
1327             */
1328            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
1329                    int end) throws SystemException {
1330                    return findByG_U(groupId, userId, start, end, null);
1331            }
1332    
1333            /**
1334             * Returns an ordered range of all the document library file ranks where groupId = &#63; and userId = &#63;.
1335             *
1336             * <p>
1337             * 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.
1338             * </p>
1339             *
1340             * @param groupId the group ID
1341             * @param userId the user ID
1342             * @param start the lower bound of the range of document library file ranks
1343             * @param end the upper bound of the range of document library file ranks (not inclusive)
1344             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1345             * @return the ordered range of matching document library file ranks
1346             * @throws SystemException if a system exception occurred
1347             */
1348            public List<DLFileRank> findByG_U(long groupId, long userId, int start,
1349                    int end, OrderByComparator orderByComparator) throws SystemException {
1350                    FinderPath finderPath = null;
1351                    Object[] finderArgs = null;
1352    
1353                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1354                                    (orderByComparator == null)) {
1355                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
1356                            finderArgs = new Object[] { groupId, userId };
1357                    }
1358                    else {
1359                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
1360                            finderArgs = new Object[] {
1361                                            groupId, userId,
1362                                            
1363                                            start, end, orderByComparator
1364                                    };
1365                    }
1366    
1367                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
1368                                    finderArgs, this);
1369    
1370                    if (list == null) {
1371                            StringBundler query = null;
1372    
1373                            if (orderByComparator != null) {
1374                                    query = new StringBundler(4 +
1375                                                    (orderByComparator.getOrderByFields().length * 3));
1376                            }
1377                            else {
1378                                    query = new StringBundler(4);
1379                            }
1380    
1381                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
1382    
1383                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1384    
1385                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1386    
1387                            if (orderByComparator != null) {
1388                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1389                                            orderByComparator);
1390                            }
1391    
1392                            else {
1393                                    query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1394                            }
1395    
1396                            String sql = query.toString();
1397    
1398                            Session session = null;
1399    
1400                            try {
1401                                    session = openSession();
1402    
1403                                    Query q = session.createQuery(sql);
1404    
1405                                    QueryPos qPos = QueryPos.getInstance(q);
1406    
1407                                    qPos.add(groupId);
1408    
1409                                    qPos.add(userId);
1410    
1411                                    list = (List<DLFileRank>)QueryUtil.list(q, getDialect(), start,
1412                                                    end);
1413                            }
1414                            catch (Exception e) {
1415                                    throw processException(e);
1416                            }
1417                            finally {
1418                                    if (list == null) {
1419                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1420                                    }
1421                                    else {
1422                                            cacheResult(list);
1423    
1424                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1425                                    }
1426    
1427                                    closeSession(session);
1428                            }
1429                    }
1430    
1431                    return list;
1432            }
1433    
1434            /**
1435             * Returns the first document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
1436             *
1437             * <p>
1438             * 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.
1439             * </p>
1440             *
1441             * @param groupId the group ID
1442             * @param userId the user ID
1443             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1444             * @return the first matching document library file rank
1445             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
1446             * @throws SystemException if a system exception occurred
1447             */
1448            public DLFileRank findByG_U_First(long groupId, long userId,
1449                    OrderByComparator orderByComparator)
1450                    throws NoSuchFileRankException, SystemException {
1451                    List<DLFileRank> list = findByG_U(groupId, userId, 0, 1,
1452                                    orderByComparator);
1453    
1454                    if (list.isEmpty()) {
1455                            StringBundler msg = new StringBundler(6);
1456    
1457                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1458    
1459                            msg.append("groupId=");
1460                            msg.append(groupId);
1461    
1462                            msg.append(", userId=");
1463                            msg.append(userId);
1464    
1465                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1466    
1467                            throw new NoSuchFileRankException(msg.toString());
1468                    }
1469                    else {
1470                            return list.get(0);
1471                    }
1472            }
1473    
1474            /**
1475             * Returns the last document library file rank in the ordered set where groupId = &#63; and userId = &#63;.
1476             *
1477             * <p>
1478             * 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.
1479             * </p>
1480             *
1481             * @param groupId the group ID
1482             * @param userId the user ID
1483             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1484             * @return the last matching document library file rank
1485             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
1486             * @throws SystemException if a system exception occurred
1487             */
1488            public DLFileRank findByG_U_Last(long groupId, long userId,
1489                    OrderByComparator orderByComparator)
1490                    throws NoSuchFileRankException, SystemException {
1491                    int count = countByG_U(groupId, userId);
1492    
1493                    List<DLFileRank> list = findByG_U(groupId, userId, count - 1, count,
1494                                    orderByComparator);
1495    
1496                    if (list.isEmpty()) {
1497                            StringBundler msg = new StringBundler(6);
1498    
1499                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1500    
1501                            msg.append("groupId=");
1502                            msg.append(groupId);
1503    
1504                            msg.append(", userId=");
1505                            msg.append(userId);
1506    
1507                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1508    
1509                            throw new NoSuchFileRankException(msg.toString());
1510                    }
1511                    else {
1512                            return list.get(0);
1513                    }
1514            }
1515    
1516            /**
1517             * 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;.
1518             *
1519             * <p>
1520             * 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.
1521             * </p>
1522             *
1523             * @param fileRankId the primary key of the current document library file rank
1524             * @param groupId the group ID
1525             * @param userId the user ID
1526             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1527             * @return the previous, current, and next document library file rank
1528             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a document library file rank with the primary key could not be found
1529             * @throws SystemException if a system exception occurred
1530             */
1531            public DLFileRank[] findByG_U_PrevAndNext(long fileRankId, long groupId,
1532                    long userId, OrderByComparator orderByComparator)
1533                    throws NoSuchFileRankException, SystemException {
1534                    DLFileRank dlFileRank = findByPrimaryKey(fileRankId);
1535    
1536                    Session session = null;
1537    
1538                    try {
1539                            session = openSession();
1540    
1541                            DLFileRank[] array = new DLFileRankImpl[3];
1542    
1543                            array[0] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1544                                            userId, orderByComparator, true);
1545    
1546                            array[1] = dlFileRank;
1547    
1548                            array[2] = getByG_U_PrevAndNext(session, dlFileRank, groupId,
1549                                            userId, orderByComparator, false);
1550    
1551                            return array;
1552                    }
1553                    catch (Exception e) {
1554                            throw processException(e);
1555                    }
1556                    finally {
1557                            closeSession(session);
1558                    }
1559            }
1560    
1561            protected DLFileRank getByG_U_PrevAndNext(Session session,
1562                    DLFileRank dlFileRank, long groupId, long userId,
1563                    OrderByComparator orderByComparator, boolean previous) {
1564                    StringBundler query = null;
1565    
1566                    if (orderByComparator != null) {
1567                            query = new StringBundler(6 +
1568                                            (orderByComparator.getOrderByFields().length * 6));
1569                    }
1570                    else {
1571                            query = new StringBundler(3);
1572                    }
1573    
1574                    query.append(_SQL_SELECT_DLFILERANK_WHERE);
1575    
1576                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1577    
1578                    query.append(_FINDER_COLUMN_G_U_USERID_2);
1579    
1580                    if (orderByComparator != null) {
1581                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1582    
1583                            if (orderByConditionFields.length > 0) {
1584                                    query.append(WHERE_AND);
1585                            }
1586    
1587                            for (int i = 0; i < orderByConditionFields.length; i++) {
1588                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1589                                    query.append(orderByConditionFields[i]);
1590    
1591                                    if ((i + 1) < orderByConditionFields.length) {
1592                                            if (orderByComparator.isAscending() ^ previous) {
1593                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1594                                            }
1595                                            else {
1596                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1597                                            }
1598                                    }
1599                                    else {
1600                                            if (orderByComparator.isAscending() ^ previous) {
1601                                                    query.append(WHERE_GREATER_THAN);
1602                                            }
1603                                            else {
1604                                                    query.append(WHERE_LESSER_THAN);
1605                                            }
1606                                    }
1607                            }
1608    
1609                            query.append(ORDER_BY_CLAUSE);
1610    
1611                            String[] orderByFields = orderByComparator.getOrderByFields();
1612    
1613                            for (int i = 0; i < orderByFields.length; i++) {
1614                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1615                                    query.append(orderByFields[i]);
1616    
1617                                    if ((i + 1) < orderByFields.length) {
1618                                            if (orderByComparator.isAscending() ^ previous) {
1619                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1620                                            }
1621                                            else {
1622                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1623                                            }
1624                                    }
1625                                    else {
1626                                            if (orderByComparator.isAscending() ^ previous) {
1627                                                    query.append(ORDER_BY_ASC);
1628                                            }
1629                                            else {
1630                                                    query.append(ORDER_BY_DESC);
1631                                            }
1632                                    }
1633                            }
1634                    }
1635    
1636                    else {
1637                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1638                    }
1639    
1640                    String sql = query.toString();
1641    
1642                    Query q = session.createQuery(sql);
1643    
1644                    q.setFirstResult(0);
1645                    q.setMaxResults(2);
1646    
1647                    QueryPos qPos = QueryPos.getInstance(q);
1648    
1649                    qPos.add(groupId);
1650    
1651                    qPos.add(userId);
1652    
1653                    if (orderByComparator != null) {
1654                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileRank);
1655    
1656                            for (Object value : values) {
1657                                    qPos.add(value);
1658                            }
1659                    }
1660    
1661                    List<DLFileRank> list = q.list();
1662    
1663                    if (list.size() == 2) {
1664                            return list.get(1);
1665                    }
1666                    else {
1667                            return null;
1668                    }
1669            }
1670    
1671            /**
1672             * 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.
1673             *
1674             * @param companyId the company ID
1675             * @param userId the user ID
1676             * @param fileEntryId the file entry ID
1677             * @return the matching document library file rank
1678             * @throws com.liferay.portlet.documentlibrary.NoSuchFileRankException if a matching document library file rank could not be found
1679             * @throws SystemException if a system exception occurred
1680             */
1681            public DLFileRank findByC_U_F(long companyId, long userId, long fileEntryId)
1682                    throws NoSuchFileRankException, SystemException {
1683                    DLFileRank dlFileRank = fetchByC_U_F(companyId, userId, fileEntryId);
1684    
1685                    if (dlFileRank == null) {
1686                            StringBundler msg = new StringBundler(8);
1687    
1688                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1689    
1690                            msg.append("companyId=");
1691                            msg.append(companyId);
1692    
1693                            msg.append(", userId=");
1694                            msg.append(userId);
1695    
1696                            msg.append(", fileEntryId=");
1697                            msg.append(fileEntryId);
1698    
1699                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1700    
1701                            if (_log.isWarnEnabled()) {
1702                                    _log.warn(msg.toString());
1703                            }
1704    
1705                            throw new NoSuchFileRankException(msg.toString());
1706                    }
1707    
1708                    return dlFileRank;
1709            }
1710    
1711            /**
1712             * 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.
1713             *
1714             * @param companyId the company ID
1715             * @param userId the user ID
1716             * @param fileEntryId the file entry ID
1717             * @return the matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1718             * @throws SystemException if a system exception occurred
1719             */
1720            public DLFileRank fetchByC_U_F(long companyId, long userId, long fileEntryId)
1721                    throws SystemException {
1722                    return fetchByC_U_F(companyId, userId, fileEntryId, true);
1723            }
1724    
1725            /**
1726             * 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.
1727             *
1728             * @param companyId the company ID
1729             * @param userId the user ID
1730             * @param fileEntryId the file entry ID
1731             * @param retrieveFromCache whether to use the finder cache
1732             * @return the matching document library file rank, or <code>null</code> if a matching document library file rank could not be found
1733             * @throws SystemException if a system exception occurred
1734             */
1735            public DLFileRank fetchByC_U_F(long companyId, long userId,
1736                    long fileEntryId, boolean retrieveFromCache) throws SystemException {
1737                    Object[] finderArgs = new Object[] { companyId, userId, fileEntryId };
1738    
1739                    Object result = null;
1740    
1741                    if (retrieveFromCache) {
1742                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U_F,
1743                                            finderArgs, this);
1744                    }
1745    
1746                    if (result == null) {
1747                            StringBundler query = new StringBundler(5);
1748    
1749                            query.append(_SQL_SELECT_DLFILERANK_WHERE);
1750    
1751                            query.append(_FINDER_COLUMN_C_U_F_COMPANYID_2);
1752    
1753                            query.append(_FINDER_COLUMN_C_U_F_USERID_2);
1754    
1755                            query.append(_FINDER_COLUMN_C_U_F_FILEENTRYID_2);
1756    
1757                            query.append(DLFileRankModelImpl.ORDER_BY_JPQL);
1758    
1759                            String sql = query.toString();
1760    
1761                            Session session = null;
1762    
1763                            try {
1764                                    session = openSession();
1765    
1766                                    Query q = session.createQuery(sql);
1767    
1768                                    QueryPos qPos = QueryPos.getInstance(q);
1769    
1770                                    qPos.add(companyId);
1771    
1772                                    qPos.add(userId);
1773    
1774                                    qPos.add(fileEntryId);
1775    
1776                                    List<DLFileRank> list = q.list();
1777    
1778                                    result = list;
1779    
1780                                    DLFileRank dlFileRank = null;
1781    
1782                                    if (list.isEmpty()) {
1783                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
1784                                                    finderArgs, list);
1785                                    }
1786                                    else {
1787                                            dlFileRank = list.get(0);
1788    
1789                                            cacheResult(dlFileRank);
1790    
1791                                            if ((dlFileRank.getCompanyId() != companyId) ||
1792                                                            (dlFileRank.getUserId() != userId) ||
1793                                                            (dlFileRank.getFileEntryId() != fileEntryId)) {
1794                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U_F,
1795                                                            finderArgs, dlFileRank);
1796                                            }
1797                                    }
1798    
1799                                    return dlFileRank;
1800                            }
1801                            catch (Exception e) {
1802                                    throw processException(e);
1803                            }
1804                            finally {
1805                                    if (result == null) {
1806                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U_F,
1807                                                    finderArgs);
1808                                    }
1809    
1810                                    closeSession(session);
1811                            }
1812                    }
1813                    else {
1814                            if (result instanceof List<?>) {
1815                                    return null;
1816                            }
1817                            else {
1818                                    return (DLFileRank)result;
1819                            }
1820                    }
1821            }
1822    
1823            /**
1824             * Returns all the document library file ranks.
1825             *
1826             * @return the document library file ranks
1827             * @throws SystemException if a system exception occurred
1828             */
1829            public List<DLFileRank> findAll() throws SystemException {
1830                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1831            }
1832    
1833            /**
1834             * Returns a range of all the document library file ranks.
1835             *
1836             * <p>
1837             * 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.
1838             * </p>
1839             *
1840             * @param start the lower bound of the range of document library file ranks
1841             * @param end the upper bound of the range of document library file ranks (not inclusive)
1842             * @return the range of document library file ranks
1843             * @throws SystemException if a system exception occurred
1844             */
1845            public List<DLFileRank> findAll(int start, int end)
1846                    throws SystemException {
1847                    return findAll(start, end, null);
1848            }
1849    
1850            /**
1851             * Returns an ordered range of all the document library file ranks.
1852             *
1853             * <p>
1854             * 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.
1855             * </p>
1856             *
1857             * @param start the lower bound of the range of document library file ranks
1858             * @param end the upper bound of the range of document library file ranks (not inclusive)
1859             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1860             * @return the ordered range of document library file ranks
1861             * @throws SystemException if a system exception occurred
1862             */
1863            public List<DLFileRank> findAll(int start, int end,
1864                    OrderByComparator orderByComparator) throws SystemException {
1865                    FinderPath finderPath = null;
1866                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1867    
1868                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1869                                    (orderByComparator == null)) {
1870                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1871                            finderArgs = FINDER_ARGS_EMPTY;
1872                    }
1873                    else {
1874                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1875                            finderArgs = new Object[] { start, end, orderByComparator };
1876                    }
1877    
1878                    List<DLFileRank> list = (List<DLFileRank>)FinderCacheUtil.getResult(finderPath,
1879                                    finderArgs, this);
1880    
1881                    if (list == null) {
1882                            StringBundler query = null;
1883                            String sql = null;
1884    
1885                            if (orderByComparator != null) {
1886                                    query = new StringBundler(2 +
1887                                                    (orderByComparator.getOrderByFields().length * 3));
1888    
1889                                    query.append(_SQL_SELECT_DLFILERANK);
1890    
1891                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1892                                            orderByComparator);
1893    
1894                                    sql = query.toString();
1895                            }
1896                            else {
1897                                    sql = _SQL_SELECT_DLFILERANK.concat(DLFileRankModelImpl.ORDER_BY_JPQL);
1898                            }
1899    
1900                            Session session = null;
1901    
1902                            try {
1903                                    session = openSession();
1904    
1905                                    Query q = session.createQuery(sql);
1906    
1907                                    if (orderByComparator == null) {
1908                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1909                                                            start, end, false);
1910    
1911                                            Collections.sort(list);
1912                                    }
1913                                    else {
1914                                            list = (List<DLFileRank>)QueryUtil.list(q, getDialect(),
1915                                                            start, end);
1916                                    }
1917                            }
1918                            catch (Exception e) {
1919                                    throw processException(e);
1920                            }
1921                            finally {
1922                                    if (list == null) {
1923                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1924                                    }
1925                                    else {
1926                                            cacheResult(list);
1927    
1928                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1929                                    }
1930    
1931                                    closeSession(session);
1932                            }
1933                    }
1934    
1935                    return list;
1936            }
1937    
1938            /**
1939             * Removes all the document library file ranks where userId = &#63; from the database.
1940             *
1941             * @param userId the user ID
1942             * @throws SystemException if a system exception occurred
1943             */
1944            public void removeByUserId(long userId) throws SystemException {
1945                    for (DLFileRank dlFileRank : findByUserId(userId)) {
1946                            dlFileRankPersistence.remove(dlFileRank);
1947                    }
1948            }
1949    
1950            /**
1951             * Removes all the document library file ranks where fileEntryId = &#63; from the database.
1952             *
1953             * @param fileEntryId the file entry ID
1954             * @throws SystemException if a system exception occurred
1955             */
1956            public void removeByFileEntryId(long fileEntryId) throws SystemException {
1957                    for (DLFileRank dlFileRank : findByFileEntryId(fileEntryId)) {
1958                            dlFileRankPersistence.remove(dlFileRank);
1959                    }
1960            }
1961    
1962            /**
1963             * Removes all the document library file ranks where groupId = &#63; and userId = &#63; from the database.
1964             *
1965             * @param groupId the group ID
1966             * @param userId the user ID
1967             * @throws SystemException if a system exception occurred
1968             */
1969            public void removeByG_U(long groupId, long userId)
1970                    throws SystemException {
1971                    for (DLFileRank dlFileRank : findByG_U(groupId, userId)) {
1972                            dlFileRankPersistence.remove(dlFileRank);
1973                    }
1974            }
1975    
1976            /**
1977             * Removes the document library file rank where companyId = &#63; and userId = &#63; and fileEntryId = &#63; from the database.
1978             *
1979             * @param companyId the company ID
1980             * @param userId the user ID
1981             * @param fileEntryId the file entry ID
1982             * @throws SystemException if a system exception occurred
1983             */
1984            public void removeByC_U_F(long companyId, long userId, long fileEntryId)
1985                    throws NoSuchFileRankException, SystemException {
1986                    DLFileRank dlFileRank = findByC_U_F(companyId, userId, fileEntryId);
1987    
1988                    dlFileRankPersistence.remove(dlFileRank);
1989            }
1990    
1991            /**
1992             * Removes all the document library file ranks from the database.
1993             *
1994             * @throws SystemException if a system exception occurred
1995             */
1996            public void removeAll() throws SystemException {
1997                    for (DLFileRank dlFileRank : findAll()) {
1998                            dlFileRankPersistence.remove(dlFileRank);
1999                    }
2000            }
2001    
2002            /**
2003             * Returns the number of document library file ranks where userId = &#63;.
2004             *
2005             * @param userId the user ID
2006             * @return the number of matching document library file ranks
2007             * @throws SystemException if a system exception occurred
2008             */
2009            public int countByUserId(long userId) throws SystemException {
2010                    Object[] finderArgs = new Object[] { userId };
2011    
2012                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2013                                    finderArgs, this);
2014    
2015                    if (count == null) {
2016                            StringBundler query = new StringBundler(2);
2017    
2018                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2019    
2020                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2021    
2022                            String sql = query.toString();
2023    
2024                            Session session = null;
2025    
2026                            try {
2027                                    session = openSession();
2028    
2029                                    Query q = session.createQuery(sql);
2030    
2031                                    QueryPos qPos = QueryPos.getInstance(q);
2032    
2033                                    qPos.add(userId);
2034    
2035                                    count = (Long)q.uniqueResult();
2036                            }
2037                            catch (Exception e) {
2038                                    throw processException(e);
2039                            }
2040                            finally {
2041                                    if (count == null) {
2042                                            count = Long.valueOf(0);
2043                                    }
2044    
2045                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2046                                            finderArgs, count);
2047    
2048                                    closeSession(session);
2049                            }
2050                    }
2051    
2052                    return count.intValue();
2053            }
2054    
2055            /**
2056             * Returns the number of document library file ranks where fileEntryId = &#63;.
2057             *
2058             * @param fileEntryId the file entry ID
2059             * @return the number of matching document library file ranks
2060             * @throws SystemException if a system exception occurred
2061             */
2062            public int countByFileEntryId(long fileEntryId) throws SystemException {
2063                    Object[] finderArgs = new Object[] { fileEntryId };
2064    
2065                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
2066                                    finderArgs, this);
2067    
2068                    if (count == null) {
2069                            StringBundler query = new StringBundler(2);
2070    
2071                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2072    
2073                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2074    
2075                            String sql = query.toString();
2076    
2077                            Session session = null;
2078    
2079                            try {
2080                                    session = openSession();
2081    
2082                                    Query q = session.createQuery(sql);
2083    
2084                                    QueryPos qPos = QueryPos.getInstance(q);
2085    
2086                                    qPos.add(fileEntryId);
2087    
2088                                    count = (Long)q.uniqueResult();
2089                            }
2090                            catch (Exception e) {
2091                                    throw processException(e);
2092                            }
2093                            finally {
2094                                    if (count == null) {
2095                                            count = Long.valueOf(0);
2096                                    }
2097    
2098                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
2099                                            finderArgs, count);
2100    
2101                                    closeSession(session);
2102                            }
2103                    }
2104    
2105                    return count.intValue();
2106            }
2107    
2108            /**
2109             * Returns the number of document library file ranks where groupId = &#63; and userId = &#63;.
2110             *
2111             * @param groupId the group ID
2112             * @param userId the user ID
2113             * @return the number of matching document library file ranks
2114             * @throws SystemException if a system exception occurred
2115             */
2116            public int countByG_U(long groupId, long userId) throws SystemException {
2117                    Object[] finderArgs = new Object[] { groupId, userId };
2118    
2119                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
2120                                    finderArgs, this);
2121    
2122                    if (count == null) {
2123                            StringBundler query = new StringBundler(3);
2124    
2125                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2126    
2127                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2128    
2129                            query.append(_FINDER_COLUMN_G_U_USERID_2);
2130    
2131                            String sql = query.toString();
2132    
2133                            Session session = null;
2134    
2135                            try {
2136                                    session = openSession();
2137    
2138                                    Query q = session.createQuery(sql);
2139    
2140                                    QueryPos qPos = QueryPos.getInstance(q);
2141    
2142                                    qPos.add(groupId);
2143    
2144                                    qPos.add(userId);
2145    
2146                                    count = (Long)q.uniqueResult();
2147                            }
2148                            catch (Exception e) {
2149                                    throw processException(e);
2150                            }
2151                            finally {
2152                                    if (count == null) {
2153                                            count = Long.valueOf(0);
2154                                    }
2155    
2156                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2157                                            count);
2158    
2159                                    closeSession(session);
2160                            }
2161                    }
2162    
2163                    return count.intValue();
2164            }
2165    
2166            /**
2167             * Returns the number of document library file ranks where companyId = &#63; and userId = &#63; and fileEntryId = &#63;.
2168             *
2169             * @param companyId the company ID
2170             * @param userId the user ID
2171             * @param fileEntryId the file entry ID
2172             * @return the number of matching document library file ranks
2173             * @throws SystemException if a system exception occurred
2174             */
2175            public int countByC_U_F(long companyId, long userId, long fileEntryId)
2176                    throws SystemException {
2177                    Object[] finderArgs = new Object[] { companyId, userId, fileEntryId };
2178    
2179                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_U_F,
2180                                    finderArgs, this);
2181    
2182                    if (count == null) {
2183                            StringBundler query = new StringBundler(4);
2184    
2185                            query.append(_SQL_COUNT_DLFILERANK_WHERE);
2186    
2187                            query.append(_FINDER_COLUMN_C_U_F_COMPANYID_2);
2188    
2189                            query.append(_FINDER_COLUMN_C_U_F_USERID_2);
2190    
2191                            query.append(_FINDER_COLUMN_C_U_F_FILEENTRYID_2);
2192    
2193                            String sql = query.toString();
2194    
2195                            Session session = null;
2196    
2197                            try {
2198                                    session = openSession();
2199    
2200                                    Query q = session.createQuery(sql);
2201    
2202                                    QueryPos qPos = QueryPos.getInstance(q);
2203    
2204                                    qPos.add(companyId);
2205    
2206                                    qPos.add(userId);
2207    
2208                                    qPos.add(fileEntryId);
2209    
2210                                    count = (Long)q.uniqueResult();
2211                            }
2212                            catch (Exception e) {
2213                                    throw processException(e);
2214                            }
2215                            finally {
2216                                    if (count == null) {
2217                                            count = Long.valueOf(0);
2218                                    }
2219    
2220                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U_F,
2221                                            finderArgs, count);
2222    
2223                                    closeSession(session);
2224                            }
2225                    }
2226    
2227                    return count.intValue();
2228            }
2229    
2230            /**
2231             * Returns the number of document library file ranks.
2232             *
2233             * @return the number of document library file ranks
2234             * @throws SystemException if a system exception occurred
2235             */
2236            public int countAll() throws SystemException {
2237                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2238                                    FINDER_ARGS_EMPTY, this);
2239    
2240                    if (count == null) {
2241                            Session session = null;
2242    
2243                            try {
2244                                    session = openSession();
2245    
2246                                    Query q = session.createQuery(_SQL_COUNT_DLFILERANK);
2247    
2248                                    count = (Long)q.uniqueResult();
2249                            }
2250                            catch (Exception e) {
2251                                    throw processException(e);
2252                            }
2253                            finally {
2254                                    if (count == null) {
2255                                            count = Long.valueOf(0);
2256                                    }
2257    
2258                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2259                                            FINDER_ARGS_EMPTY, count);
2260    
2261                                    closeSession(session);
2262                            }
2263                    }
2264    
2265                    return count.intValue();
2266            }
2267    
2268            /**
2269             * Initializes the document library file rank persistence.
2270             */
2271            public void afterPropertiesSet() {
2272                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2273                                            com.liferay.portal.util.PropsUtil.get(
2274                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileRank")));
2275    
2276                    if (listenerClassNames.length > 0) {
2277                            try {
2278                                    List<ModelListener<DLFileRank>> listenersList = new ArrayList<ModelListener<DLFileRank>>();
2279    
2280                                    for (String listenerClassName : listenerClassNames) {
2281                                            listenersList.add((ModelListener<DLFileRank>)InstanceFactory.newInstance(
2282                                                            listenerClassName));
2283                                    }
2284    
2285                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2286                            }
2287                            catch (Exception e) {
2288                                    _log.error(e);
2289                            }
2290                    }
2291            }
2292    
2293            public void destroy() {
2294                    EntityCacheUtil.removeCache(DLFileRankImpl.class.getName());
2295                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2296                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2297            }
2298    
2299            @BeanReference(type = DLContentPersistence.class)
2300            protected DLContentPersistence dlContentPersistence;
2301            @BeanReference(type = DLFileEntryPersistence.class)
2302            protected DLFileEntryPersistence dlFileEntryPersistence;
2303            @BeanReference(type = DLFileEntryMetadataPersistence.class)
2304            protected DLFileEntryMetadataPersistence dlFileEntryMetadataPersistence;
2305            @BeanReference(type = DLFileEntryTypePersistence.class)
2306            protected DLFileEntryTypePersistence dlFileEntryTypePersistence;
2307            @BeanReference(type = DLFileRankPersistence.class)
2308            protected DLFileRankPersistence dlFileRankPersistence;
2309            @BeanReference(type = DLFileShortcutPersistence.class)
2310            protected DLFileShortcutPersistence dlFileShortcutPersistence;
2311            @BeanReference(type = DLFileVersionPersistence.class)
2312            protected DLFileVersionPersistence dlFileVersionPersistence;
2313            @BeanReference(type = DLFolderPersistence.class)
2314            protected DLFolderPersistence dlFolderPersistence;
2315            @BeanReference(type = DLSyncPersistence.class)
2316            protected DLSyncPersistence dlSyncPersistence;
2317            @BeanReference(type = LayoutPersistence.class)
2318            protected LayoutPersistence layoutPersistence;
2319            @BeanReference(type = ResourcePersistence.class)
2320            protected ResourcePersistence resourcePersistence;
2321            @BeanReference(type = UserPersistence.class)
2322            protected UserPersistence userPersistence;
2323            private static final String _SQL_SELECT_DLFILERANK = "SELECT dlFileRank FROM DLFileRank dlFileRank";
2324            private static final String _SQL_SELECT_DLFILERANK_WHERE = "SELECT dlFileRank FROM DLFileRank dlFileRank WHERE ";
2325            private static final String _SQL_COUNT_DLFILERANK = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank";
2326            private static final String _SQL_COUNT_DLFILERANK_WHERE = "SELECT COUNT(dlFileRank) FROM DLFileRank dlFileRank WHERE ";
2327            private static final String _FINDER_COLUMN_USERID_USERID_2 = "dlFileRank.userId = ?";
2328            private static final String _FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2 = "dlFileRank.fileEntryId = ?";
2329            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "dlFileRank.groupId = ? AND ";
2330            private static final String _FINDER_COLUMN_G_U_USERID_2 = "dlFileRank.userId = ?";
2331            private static final String _FINDER_COLUMN_C_U_F_COMPANYID_2 = "dlFileRank.companyId = ? AND ";
2332            private static final String _FINDER_COLUMN_C_U_F_USERID_2 = "dlFileRank.userId = ? AND ";
2333            private static final String _FINDER_COLUMN_C_U_F_FILEENTRYID_2 = "dlFileRank.fileEntryId = ?";
2334            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileRank.";
2335            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileRank exists with the primary key ";
2336            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileRank exists with the key {";
2337            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2338            private static Log _log = LogFactoryUtil.getLog(DLFileRankPersistenceImpl.class);
2339            private static DLFileRank _nullDLFileRank = new DLFileRankImpl() {
2340                            @Override
2341                            public Object clone() {
2342                                    return this;
2343                            }
2344    
2345                            @Override
2346                            public CacheModel<DLFileRank> toCacheModel() {
2347                                    return _nullDLFileRankCacheModel;
2348                            }
2349                    };
2350    
2351            private static CacheModel<DLFileRank> _nullDLFileRankCacheModel = new CacheModel<DLFileRank>() {
2352                            public DLFileRank toEntityModel() {
2353                                    return _nullDLFileRank;
2354                            }
2355                    };
2356    }