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