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