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