001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.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.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
039    import com.liferay.portal.service.persistence.ResourcePersistence;
040    import com.liferay.portal.service.persistence.UserPersistence;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
044    import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
045    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
046    import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
047    import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * The persistence implementation for the d l file version service.
057     *
058     * <p>
059     * Never modify or reference this class directly. Always use {@link DLFileVersionUtil} to access the d l file version persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
060     * </p>
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see DLFileVersionPersistence
068     * @see DLFileVersionUtil
069     * @generated
070     */
071    public class DLFileVersionPersistenceImpl extends BasePersistenceImpl<DLFileVersion>
072            implements DLFileVersionPersistence {
073            public static final String FINDER_CLASS_NAME_ENTITY = DLFileVersionImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
075                    ".List";
076            public static final FinderPath FINDER_PATH_FIND_BY_G_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
077                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
078                            FINDER_CLASS_NAME_LIST, "findByG_F_N",
079                            new String[] {
080                                    Long.class.getName(), Long.class.getName(),
081                                    String.class.getName(),
082                                    
083                            "java.lang.Integer", "java.lang.Integer",
084                                    "com.liferay.portal.kernel.util.OrderByComparator"
085                            });
086            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
087                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
088                            FINDER_CLASS_NAME_LIST, "countByG_F_N",
089                            new String[] {
090                                    Long.class.getName(), Long.class.getName(),
091                                    String.class.getName()
092                            });
093            public static final FinderPath FINDER_PATH_FETCH_BY_G_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
094                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
095                            FINDER_CLASS_NAME_ENTITY, "fetchByG_F_N_V",
096                            new String[] {
097                                    Long.class.getName(), Long.class.getName(),
098                                    String.class.getName(), String.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
101                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
102                            FINDER_CLASS_NAME_LIST, "countByG_F_N_V",
103                            new String[] {
104                                    Long.class.getName(), Long.class.getName(),
105                                    String.class.getName(), String.class.getName()
106                            });
107            public static final FinderPath FINDER_PATH_FIND_BY_G_F_N_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
108                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
109                            FINDER_CLASS_NAME_LIST, "findByG_F_N_S",
110                            new String[] {
111                                    Long.class.getName(), Long.class.getName(),
112                                    String.class.getName(), Integer.class.getName(),
113                                    
114                            "java.lang.Integer", "java.lang.Integer",
115                                    "com.liferay.portal.kernel.util.OrderByComparator"
116                            });
117            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
118                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
119                            FINDER_CLASS_NAME_LIST, "countByG_F_N_S",
120                            new String[] {
121                                    Long.class.getName(), Long.class.getName(),
122                                    String.class.getName(), Integer.class.getName()
123                            });
124            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
125                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
126                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
127            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
128                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
129                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
130    
131            /**
132             * Caches the d l file version in the entity cache if it is enabled.
133             *
134             * @param dlFileVersion the d l file version to cache
135             */
136            public void cacheResult(DLFileVersion dlFileVersion) {
137                    EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
138                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
139                            dlFileVersion);
140    
141                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
142                            new Object[] {
143                                    new Long(dlFileVersion.getGroupId()),
144                                    new Long(dlFileVersion.getFolderId()),
145                                    
146                            dlFileVersion.getName(),
147                                    
148                            dlFileVersion.getVersion()
149                            }, dlFileVersion);
150            }
151    
152            /**
153             * Caches the d l file versions in the entity cache if it is enabled.
154             *
155             * @param dlFileVersions the d l file versions to cache
156             */
157            public void cacheResult(List<DLFileVersion> dlFileVersions) {
158                    for (DLFileVersion dlFileVersion : dlFileVersions) {
159                            if (EntityCacheUtil.getResult(
160                                                    DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
161                                                    DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
162                                                    this) == null) {
163                                    cacheResult(dlFileVersion);
164                            }
165                    }
166            }
167    
168            /**
169             * Clears the cache for all d l file versions.
170             *
171             * <p>
172             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
173             * </p>
174             */
175            public void clearCache() {
176                    CacheRegistryUtil.clear(DLFileVersionImpl.class.getName());
177                    EntityCacheUtil.clearCache(DLFileVersionImpl.class.getName());
178                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
179                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
180            }
181    
182            /**
183             * Clears the cache for the d l file version.
184             *
185             * <p>
186             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
187             * </p>
188             */
189            public void clearCache(DLFileVersion dlFileVersion) {
190                    EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
191                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
192    
193                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
194                            new Object[] {
195                                    new Long(dlFileVersion.getGroupId()),
196                                    new Long(dlFileVersion.getFolderId()),
197                                    
198                            dlFileVersion.getName(),
199                                    
200                            dlFileVersion.getVersion()
201                            });
202            }
203    
204            /**
205             * Creates a new d l file version with the primary key. Does not add the d l file version to the database.
206             *
207             * @param fileVersionId the primary key for the new d l file version
208             * @return the new d l file version
209             */
210            public DLFileVersion create(long fileVersionId) {
211                    DLFileVersion dlFileVersion = new DLFileVersionImpl();
212    
213                    dlFileVersion.setNew(true);
214                    dlFileVersion.setPrimaryKey(fileVersionId);
215    
216                    return dlFileVersion;
217            }
218    
219            /**
220             * Removes the d l file version with the primary key from the database. Also notifies the appropriate model listeners.
221             *
222             * @param primaryKey the primary key of the d l file version to remove
223             * @return the d l file version that was removed
224             * @throws com.liferay.portal.NoSuchModelException if a d l file version with the primary key could not be found
225             * @throws SystemException if a system exception occurred
226             */
227            public DLFileVersion remove(Serializable primaryKey)
228                    throws NoSuchModelException, SystemException {
229                    return remove(((Long)primaryKey).longValue());
230            }
231    
232            /**
233             * Removes the d l file version with the primary key from the database. Also notifies the appropriate model listeners.
234             *
235             * @param fileVersionId the primary key of the d l file version to remove
236             * @return the d l file version that was removed
237             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a d l file version with the primary key could not be found
238             * @throws SystemException if a system exception occurred
239             */
240            public DLFileVersion remove(long fileVersionId)
241                    throws NoSuchFileVersionException, SystemException {
242                    Session session = null;
243    
244                    try {
245                            session = openSession();
246    
247                            DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
248                                            new Long(fileVersionId));
249    
250                            if (dlFileVersion == null) {
251                                    if (_log.isWarnEnabled()) {
252                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileVersionId);
253                                    }
254    
255                                    throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
256                                            fileVersionId);
257                            }
258    
259                            return remove(dlFileVersion);
260                    }
261                    catch (NoSuchFileVersionException nsee) {
262                            throw nsee;
263                    }
264                    catch (Exception e) {
265                            throw processException(e);
266                    }
267                    finally {
268                            closeSession(session);
269                    }
270            }
271    
272            protected DLFileVersion removeImpl(DLFileVersion dlFileVersion)
273                    throws SystemException {
274                    dlFileVersion = toUnwrappedModel(dlFileVersion);
275    
276                    Session session = null;
277    
278                    try {
279                            session = openSession();
280    
281                            BatchSessionUtil.delete(session, dlFileVersion);
282                    }
283                    catch (Exception e) {
284                            throw processException(e);
285                    }
286                    finally {
287                            closeSession(session);
288                    }
289    
290                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
291    
292                    DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
293    
294                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
295                            new Object[] {
296                                    new Long(dlFileVersionModelImpl.getGroupId()),
297                                    new Long(dlFileVersionModelImpl.getFolderId()),
298                                    
299                            dlFileVersionModelImpl.getName(),
300                                    
301                            dlFileVersionModelImpl.getVersion()
302                            });
303    
304                    EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
305                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
306    
307                    return dlFileVersion;
308            }
309    
310            public DLFileVersion updateImpl(
311                    com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion,
312                    boolean merge) throws SystemException {
313                    dlFileVersion = toUnwrappedModel(dlFileVersion);
314    
315                    boolean isNew = dlFileVersion.isNew();
316    
317                    DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
318    
319                    Session session = null;
320    
321                    try {
322                            session = openSession();
323    
324                            BatchSessionUtil.update(session, dlFileVersion, merge);
325    
326                            dlFileVersion.setNew(false);
327                    }
328                    catch (Exception e) {
329                            throw processException(e);
330                    }
331                    finally {
332                            closeSession(session);
333                    }
334    
335                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
336    
337                    EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
338                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
339                            dlFileVersion);
340    
341                    if (!isNew &&
342                                    ((dlFileVersion.getGroupId() != dlFileVersionModelImpl.getOriginalGroupId()) ||
343                                    (dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
344                                    !Validator.equals(dlFileVersion.getName(),
345                                            dlFileVersionModelImpl.getOriginalName()) ||
346                                    !Validator.equals(dlFileVersion.getVersion(),
347                                            dlFileVersionModelImpl.getOriginalVersion()))) {
348                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
349                                    new Object[] {
350                                            new Long(dlFileVersionModelImpl.getOriginalGroupId()),
351                                            new Long(dlFileVersionModelImpl.getOriginalFolderId()),
352                                            
353                                    dlFileVersionModelImpl.getOriginalName(),
354                                            
355                                    dlFileVersionModelImpl.getOriginalVersion()
356                                    });
357                    }
358    
359                    if (isNew ||
360                                    ((dlFileVersion.getGroupId() != dlFileVersionModelImpl.getOriginalGroupId()) ||
361                                    (dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
362                                    !Validator.equals(dlFileVersion.getName(),
363                                            dlFileVersionModelImpl.getOriginalName()) ||
364                                    !Validator.equals(dlFileVersion.getVersion(),
365                                            dlFileVersionModelImpl.getOriginalVersion()))) {
366                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
367                                    new Object[] {
368                                            new Long(dlFileVersion.getGroupId()),
369                                            new Long(dlFileVersion.getFolderId()),
370                                            
371                                    dlFileVersion.getName(),
372                                            
373                                    dlFileVersion.getVersion()
374                                    }, dlFileVersion);
375                    }
376    
377                    return dlFileVersion;
378            }
379    
380            protected DLFileVersion toUnwrappedModel(DLFileVersion dlFileVersion) {
381                    if (dlFileVersion instanceof DLFileVersionImpl) {
382                            return dlFileVersion;
383                    }
384    
385                    DLFileVersionImpl dlFileVersionImpl = new DLFileVersionImpl();
386    
387                    dlFileVersionImpl.setNew(dlFileVersion.isNew());
388                    dlFileVersionImpl.setPrimaryKey(dlFileVersion.getPrimaryKey());
389    
390                    dlFileVersionImpl.setFileVersionId(dlFileVersion.getFileVersionId());
391                    dlFileVersionImpl.setGroupId(dlFileVersion.getGroupId());
392                    dlFileVersionImpl.setCompanyId(dlFileVersion.getCompanyId());
393                    dlFileVersionImpl.setUserId(dlFileVersion.getUserId());
394                    dlFileVersionImpl.setUserName(dlFileVersion.getUserName());
395                    dlFileVersionImpl.setCreateDate(dlFileVersion.getCreateDate());
396                    dlFileVersionImpl.setFolderId(dlFileVersion.getFolderId());
397                    dlFileVersionImpl.setName(dlFileVersion.getName());
398                    dlFileVersionImpl.setExtension(dlFileVersion.getExtension());
399                    dlFileVersionImpl.setTitle(dlFileVersion.getTitle());
400                    dlFileVersionImpl.setDescription(dlFileVersion.getDescription());
401                    dlFileVersionImpl.setChangeLog(dlFileVersion.getChangeLog());
402                    dlFileVersionImpl.setExtraSettings(dlFileVersion.getExtraSettings());
403                    dlFileVersionImpl.setVersion(dlFileVersion.getVersion());
404                    dlFileVersionImpl.setSize(dlFileVersion.getSize());
405                    dlFileVersionImpl.setStatus(dlFileVersion.getStatus());
406                    dlFileVersionImpl.setStatusByUserId(dlFileVersion.getStatusByUserId());
407                    dlFileVersionImpl.setStatusByUserName(dlFileVersion.getStatusByUserName());
408                    dlFileVersionImpl.setStatusDate(dlFileVersion.getStatusDate());
409    
410                    return dlFileVersionImpl;
411            }
412    
413            /**
414             * Finds the d l file version with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
415             *
416             * @param primaryKey the primary key of the d l file version to find
417             * @return the d l file version
418             * @throws com.liferay.portal.NoSuchModelException if a d l file version with the primary key could not be found
419             * @throws SystemException if a system exception occurred
420             */
421            public DLFileVersion findByPrimaryKey(Serializable primaryKey)
422                    throws NoSuchModelException, SystemException {
423                    return findByPrimaryKey(((Long)primaryKey).longValue());
424            }
425    
426            /**
427             * Finds the d l file version with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFileVersionException} if it could not be found.
428             *
429             * @param fileVersionId the primary key of the d l file version to find
430             * @return the d l file version
431             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a d l file version with the primary key could not be found
432             * @throws SystemException if a system exception occurred
433             */
434            public DLFileVersion findByPrimaryKey(long fileVersionId)
435                    throws NoSuchFileVersionException, SystemException {
436                    DLFileVersion dlFileVersion = fetchByPrimaryKey(fileVersionId);
437    
438                    if (dlFileVersion == null) {
439                            if (_log.isWarnEnabled()) {
440                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileVersionId);
441                            }
442    
443                            throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
444                                    fileVersionId);
445                    }
446    
447                    return dlFileVersion;
448            }
449    
450            /**
451             * Finds the d l file version with the primary key or returns <code>null</code> if it could not be found.
452             *
453             * @param primaryKey the primary key of the d l file version to find
454             * @return the d l file version, or <code>null</code> if a d l file version with the primary key could not be found
455             * @throws SystemException if a system exception occurred
456             */
457            public DLFileVersion fetchByPrimaryKey(Serializable primaryKey)
458                    throws SystemException {
459                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
460            }
461    
462            /**
463             * Finds the d l file version with the primary key or returns <code>null</code> if it could not be found.
464             *
465             * @param fileVersionId the primary key of the d l file version to find
466             * @return the d l file version, or <code>null</code> if a d l file version with the primary key could not be found
467             * @throws SystemException if a system exception occurred
468             */
469            public DLFileVersion fetchByPrimaryKey(long fileVersionId)
470                    throws SystemException {
471                    DLFileVersion dlFileVersion = (DLFileVersion)EntityCacheUtil.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
472                                    DLFileVersionImpl.class, fileVersionId, this);
473    
474                    if (dlFileVersion == null) {
475                            Session session = null;
476    
477                            try {
478                                    session = openSession();
479    
480                                    dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
481                                                    new Long(fileVersionId));
482                            }
483                            catch (Exception e) {
484                                    throw processException(e);
485                            }
486                            finally {
487                                    if (dlFileVersion != null) {
488                                            cacheResult(dlFileVersion);
489                                    }
490    
491                                    closeSession(session);
492                            }
493                    }
494    
495                    return dlFileVersion;
496            }
497    
498            /**
499             * Finds all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63;.
500             *
501             * @param groupId the group id to search with
502             * @param folderId the folder id to search with
503             * @param name the name to search with
504             * @return the matching d l file versions
505             * @throws SystemException if a system exception occurred
506             */
507            public List<DLFileVersion> findByG_F_N(long groupId, long folderId,
508                    String name) throws SystemException {
509                    return findByG_F_N(groupId, folderId, name, QueryUtil.ALL_POS,
510                            QueryUtil.ALL_POS, null);
511            }
512    
513            /**
514             * Finds a range of all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63;.
515             *
516             * <p>
517             * 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.
518             * </p>
519             *
520             * @param groupId the group id to search with
521             * @param folderId the folder id to search with
522             * @param name the name to search with
523             * @param start the lower bound of the range of d l file versions to return
524             * @param end the upper bound of the range of d l file versions to return (not inclusive)
525             * @return the range of matching d l file versions
526             * @throws SystemException if a system exception occurred
527             */
528            public List<DLFileVersion> findByG_F_N(long groupId, long folderId,
529                    String name, int start, int end) throws SystemException {
530                    return findByG_F_N(groupId, folderId, name, start, end, null);
531            }
532    
533            /**
534             * Finds an ordered range of all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63;.
535             *
536             * <p>
537             * 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.
538             * </p>
539             *
540             * @param groupId the group id to search with
541             * @param folderId the folder id to search with
542             * @param name the name to search with
543             * @param start the lower bound of the range of d l file versions to return
544             * @param end the upper bound of the range of d l file versions to return (not inclusive)
545             * @param orderByComparator the comparator to order the results by
546             * @return the ordered range of matching d l file versions
547             * @throws SystemException if a system exception occurred
548             */
549            public List<DLFileVersion> findByG_F_N(long groupId, long folderId,
550                    String name, int start, int end, OrderByComparator orderByComparator)
551                    throws SystemException {
552                    Object[] finderArgs = new Object[] {
553                                    groupId, folderId, name,
554                                    
555                                    String.valueOf(start), String.valueOf(end),
556                                    String.valueOf(orderByComparator)
557                            };
558    
559                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F_N,
560                                    finderArgs, this);
561    
562                    if (list == null) {
563                            StringBundler query = null;
564    
565                            if (orderByComparator != null) {
566                                    query = new StringBundler(5 +
567                                                    (orderByComparator.getOrderByFields().length * 3));
568                            }
569                            else {
570                                    query = new StringBundler(5);
571                            }
572    
573                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
574    
575                            query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
576    
577                            query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
578    
579                            if (name == null) {
580                                    query.append(_FINDER_COLUMN_G_F_N_NAME_1);
581                            }
582                            else {
583                                    if (name.equals(StringPool.BLANK)) {
584                                            query.append(_FINDER_COLUMN_G_F_N_NAME_3);
585                                    }
586                                    else {
587                                            query.append(_FINDER_COLUMN_G_F_N_NAME_2);
588                                    }
589                            }
590    
591                            if (orderByComparator != null) {
592                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
593                                            orderByComparator);
594                            }
595    
596                            else {
597                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
598                            }
599    
600                            String sql = query.toString();
601    
602                            Session session = null;
603    
604                            try {
605                                    session = openSession();
606    
607                                    Query q = session.createQuery(sql);
608    
609                                    QueryPos qPos = QueryPos.getInstance(q);
610    
611                                    qPos.add(groupId);
612    
613                                    qPos.add(folderId);
614    
615                                    if (name != null) {
616                                            qPos.add(name);
617                                    }
618    
619                                    list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
620                                                    start, end);
621                            }
622                            catch (Exception e) {
623                                    throw processException(e);
624                            }
625                            finally {
626                                    if (list == null) {
627                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_F_N,
628                                                    finderArgs);
629                                    }
630                                    else {
631                                            cacheResult(list);
632    
633                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N,
634                                                    finderArgs, list);
635                                    }
636    
637                                    closeSession(session);
638                            }
639                    }
640    
641                    return list;
642            }
643    
644            /**
645             * Finds the first d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63;.
646             *
647             * <p>
648             * 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.
649             * </p>
650             *
651             * @param groupId the group id to search with
652             * @param folderId the folder id to search with
653             * @param name the name to search with
654             * @param orderByComparator the comparator to order the set by
655             * @return the first matching d l file version
656             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
657             * @throws SystemException if a system exception occurred
658             */
659            public DLFileVersion findByG_F_N_First(long groupId, long folderId,
660                    String name, OrderByComparator orderByComparator)
661                    throws NoSuchFileVersionException, SystemException {
662                    List<DLFileVersion> list = findByG_F_N(groupId, folderId, name, 0, 1,
663                                    orderByComparator);
664    
665                    if (list.isEmpty()) {
666                            StringBundler msg = new StringBundler(8);
667    
668                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
669    
670                            msg.append("groupId=");
671                            msg.append(groupId);
672    
673                            msg.append(", folderId=");
674                            msg.append(folderId);
675    
676                            msg.append(", name=");
677                            msg.append(name);
678    
679                            msg.append(StringPool.CLOSE_CURLY_BRACE);
680    
681                            throw new NoSuchFileVersionException(msg.toString());
682                    }
683                    else {
684                            return list.get(0);
685                    }
686            }
687    
688            /**
689             * Finds the last d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63;.
690             *
691             * <p>
692             * 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.
693             * </p>
694             *
695             * @param groupId the group id to search with
696             * @param folderId the folder id to search with
697             * @param name the name to search with
698             * @param orderByComparator the comparator to order the set by
699             * @return the last matching d l file version
700             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
701             * @throws SystemException if a system exception occurred
702             */
703            public DLFileVersion findByG_F_N_Last(long groupId, long folderId,
704                    String name, OrderByComparator orderByComparator)
705                    throws NoSuchFileVersionException, SystemException {
706                    int count = countByG_F_N(groupId, folderId, name);
707    
708                    List<DLFileVersion> list = findByG_F_N(groupId, folderId, name,
709                                    count - 1, count, orderByComparator);
710    
711                    if (list.isEmpty()) {
712                            StringBundler msg = new StringBundler(8);
713    
714                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
715    
716                            msg.append("groupId=");
717                            msg.append(groupId);
718    
719                            msg.append(", folderId=");
720                            msg.append(folderId);
721    
722                            msg.append(", name=");
723                            msg.append(name);
724    
725                            msg.append(StringPool.CLOSE_CURLY_BRACE);
726    
727                            throw new NoSuchFileVersionException(msg.toString());
728                    }
729                    else {
730                            return list.get(0);
731                    }
732            }
733    
734            /**
735             * Finds the d l file versions before and after the current d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63;.
736             *
737             * <p>
738             * 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.
739             * </p>
740             *
741             * @param fileVersionId the primary key of the current d l file version
742             * @param groupId the group id to search with
743             * @param folderId the folder id to search with
744             * @param name the name to search with
745             * @param orderByComparator the comparator to order the set by
746             * @return the previous, current, and next d l file version
747             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a d l file version with the primary key could not be found
748             * @throws SystemException if a system exception occurred
749             */
750            public DLFileVersion[] findByG_F_N_PrevAndNext(long fileVersionId,
751                    long groupId, long folderId, String name,
752                    OrderByComparator orderByComparator)
753                    throws NoSuchFileVersionException, SystemException {
754                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
755    
756                    Session session = null;
757    
758                    try {
759                            session = openSession();
760    
761                            DLFileVersion[] array = new DLFileVersionImpl[3];
762    
763                            array[0] = getByG_F_N_PrevAndNext(session, dlFileVersion, groupId,
764                                            folderId, name, orderByComparator, true);
765    
766                            array[1] = dlFileVersion;
767    
768                            array[2] = getByG_F_N_PrevAndNext(session, dlFileVersion, groupId,
769                                            folderId, name, orderByComparator, false);
770    
771                            return array;
772                    }
773                    catch (Exception e) {
774                            throw processException(e);
775                    }
776                    finally {
777                            closeSession(session);
778                    }
779            }
780    
781            protected DLFileVersion getByG_F_N_PrevAndNext(Session session,
782                    DLFileVersion dlFileVersion, long groupId, long folderId, String name,
783                    OrderByComparator orderByComparator, boolean previous) {
784                    StringBundler query = null;
785    
786                    if (orderByComparator != null) {
787                            query = new StringBundler(6 +
788                                            (orderByComparator.getOrderByFields().length * 6));
789                    }
790                    else {
791                            query = new StringBundler(3);
792                    }
793    
794                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
795    
796                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
797    
798                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
799    
800                    if (name == null) {
801                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
802                    }
803                    else {
804                            if (name.equals(StringPool.BLANK)) {
805                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
806                            }
807                            else {
808                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
809                            }
810                    }
811    
812                    if (orderByComparator != null) {
813                            String[] orderByFields = orderByComparator.getOrderByFields();
814    
815                            if (orderByFields.length > 0) {
816                                    query.append(WHERE_AND);
817                            }
818    
819                            for (int i = 0; i < orderByFields.length; i++) {
820                                    query.append(_ORDER_BY_ENTITY_ALIAS);
821                                    query.append(orderByFields[i]);
822    
823                                    if ((i + 1) < orderByFields.length) {
824                                            if (orderByComparator.isAscending() ^ previous) {
825                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
826                                            }
827                                            else {
828                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
829                                            }
830                                    }
831                                    else {
832                                            if (orderByComparator.isAscending() ^ previous) {
833                                                    query.append(WHERE_GREATER_THAN);
834                                            }
835                                            else {
836                                                    query.append(WHERE_LESSER_THAN);
837                                            }
838                                    }
839                            }
840    
841                            query.append(ORDER_BY_CLAUSE);
842    
843                            for (int i = 0; i < orderByFields.length; i++) {
844                                    query.append(_ORDER_BY_ENTITY_ALIAS);
845                                    query.append(orderByFields[i]);
846    
847                                    if ((i + 1) < orderByFields.length) {
848                                            if (orderByComparator.isAscending() ^ previous) {
849                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
850                                            }
851                                            else {
852                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
853                                            }
854                                    }
855                                    else {
856                                            if (orderByComparator.isAscending() ^ previous) {
857                                                    query.append(ORDER_BY_ASC);
858                                            }
859                                            else {
860                                                    query.append(ORDER_BY_DESC);
861                                            }
862                                    }
863                            }
864                    }
865    
866                    else {
867                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
868                    }
869    
870                    String sql = query.toString();
871    
872                    Query q = session.createQuery(sql);
873    
874                    q.setFirstResult(0);
875                    q.setMaxResults(2);
876    
877                    QueryPos qPos = QueryPos.getInstance(q);
878    
879                    qPos.add(groupId);
880    
881                    qPos.add(folderId);
882    
883                    if (name != null) {
884                            qPos.add(name);
885                    }
886    
887                    if (orderByComparator != null) {
888                            Object[] values = orderByComparator.getOrderByValues(dlFileVersion);
889    
890                            for (Object value : values) {
891                                    qPos.add(value);
892                            }
893                    }
894    
895                    List<DLFileVersion> list = q.list();
896    
897                    if (list.size() == 2) {
898                            return list.get(1);
899                    }
900                    else {
901                            return null;
902                    }
903            }
904    
905            /**
906             * Finds the d l file version where groupId = &#63; and folderId = &#63; and name = &#63; and version = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFileVersionException} if it could not be found.
907             *
908             * @param groupId the group id to search with
909             * @param folderId the folder id to search with
910             * @param name the name to search with
911             * @param version the version to search with
912             * @return the matching d l file version
913             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
914             * @throws SystemException if a system exception occurred
915             */
916            public DLFileVersion findByG_F_N_V(long groupId, long folderId,
917                    String name, String version)
918                    throws NoSuchFileVersionException, SystemException {
919                    DLFileVersion dlFileVersion = fetchByG_F_N_V(groupId, folderId, name,
920                                    version);
921    
922                    if (dlFileVersion == null) {
923                            StringBundler msg = new StringBundler(10);
924    
925                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
926    
927                            msg.append("groupId=");
928                            msg.append(groupId);
929    
930                            msg.append(", folderId=");
931                            msg.append(folderId);
932    
933                            msg.append(", name=");
934                            msg.append(name);
935    
936                            msg.append(", version=");
937                            msg.append(version);
938    
939                            msg.append(StringPool.CLOSE_CURLY_BRACE);
940    
941                            if (_log.isWarnEnabled()) {
942                                    _log.warn(msg.toString());
943                            }
944    
945                            throw new NoSuchFileVersionException(msg.toString());
946                    }
947    
948                    return dlFileVersion;
949            }
950    
951            /**
952             * Finds the d l file version where groupId = &#63; and folderId = &#63; and name = &#63; and version = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
953             *
954             * @param groupId the group id to search with
955             * @param folderId the folder id to search with
956             * @param name the name to search with
957             * @param version the version to search with
958             * @return the matching d l file version, or <code>null</code> if a matching d l file version could not be found
959             * @throws SystemException if a system exception occurred
960             */
961            public DLFileVersion fetchByG_F_N_V(long groupId, long folderId,
962                    String name, String version) throws SystemException {
963                    return fetchByG_F_N_V(groupId, folderId, name, version, true);
964            }
965    
966            /**
967             * Finds the d l file version where groupId = &#63; and folderId = &#63; and name = &#63; and version = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
968             *
969             * @param groupId the group id to search with
970             * @param folderId the folder id to search with
971             * @param name the name to search with
972             * @param version the version to search with
973             * @return the matching d l file version, or <code>null</code> if a matching d l file version could not be found
974             * @throws SystemException if a system exception occurred
975             */
976            public DLFileVersion fetchByG_F_N_V(long groupId, long folderId,
977                    String name, String version, boolean retrieveFromCache)
978                    throws SystemException {
979                    Object[] finderArgs = new Object[] { groupId, folderId, name, version };
980    
981                    Object result = null;
982    
983                    if (retrieveFromCache) {
984                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_F_N_V,
985                                            finderArgs, this);
986                    }
987    
988                    if (result == null) {
989                            StringBundler query = new StringBundler(6);
990    
991                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
992    
993                            query.append(_FINDER_COLUMN_G_F_N_V_GROUPID_2);
994    
995                            query.append(_FINDER_COLUMN_G_F_N_V_FOLDERID_2);
996    
997                            if (name == null) {
998                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_1);
999                            }
1000                            else {
1001                                    if (name.equals(StringPool.BLANK)) {
1002                                            query.append(_FINDER_COLUMN_G_F_N_V_NAME_3);
1003                                    }
1004                                    else {
1005                                            query.append(_FINDER_COLUMN_G_F_N_V_NAME_2);
1006                                    }
1007                            }
1008    
1009                            if (version == null) {
1010                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_1);
1011                            }
1012                            else {
1013                                    if (version.equals(StringPool.BLANK)) {
1014                                            query.append(_FINDER_COLUMN_G_F_N_V_VERSION_3);
1015                                    }
1016                                    else {
1017                                            query.append(_FINDER_COLUMN_G_F_N_V_VERSION_2);
1018                                    }
1019                            }
1020    
1021                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1022    
1023                            String sql = query.toString();
1024    
1025                            Session session = null;
1026    
1027                            try {
1028                                    session = openSession();
1029    
1030                                    Query q = session.createQuery(sql);
1031    
1032                                    QueryPos qPos = QueryPos.getInstance(q);
1033    
1034                                    qPos.add(groupId);
1035    
1036                                    qPos.add(folderId);
1037    
1038                                    if (name != null) {
1039                                            qPos.add(name);
1040                                    }
1041    
1042                                    if (version != null) {
1043                                            qPos.add(version);
1044                                    }
1045    
1046                                    List<DLFileVersion> list = q.list();
1047    
1048                                    result = list;
1049    
1050                                    DLFileVersion dlFileVersion = null;
1051    
1052                                    if (list.isEmpty()) {
1053                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
1054                                                    finderArgs, list);
1055                                    }
1056                                    else {
1057                                            dlFileVersion = list.get(0);
1058    
1059                                            cacheResult(dlFileVersion);
1060    
1061                                            if ((dlFileVersion.getGroupId() != groupId) ||
1062                                                            (dlFileVersion.getFolderId() != folderId) ||
1063                                                            (dlFileVersion.getName() == null) ||
1064                                                            !dlFileVersion.getName().equals(name) ||
1065                                                            (dlFileVersion.getVersion() == null) ||
1066                                                            !dlFileVersion.getVersion().equals(version)) {
1067                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
1068                                                            finderArgs, dlFileVersion);
1069                                            }
1070                                    }
1071    
1072                                    return dlFileVersion;
1073                            }
1074                            catch (Exception e) {
1075                                    throw processException(e);
1076                            }
1077                            finally {
1078                                    if (result == null) {
1079                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
1080                                                    finderArgs);
1081                                    }
1082    
1083                                    closeSession(session);
1084                            }
1085                    }
1086                    else {
1087                            if (result instanceof List<?>) {
1088                                    return null;
1089                            }
1090                            else {
1091                                    return (DLFileVersion)result;
1092                            }
1093                    }
1094            }
1095    
1096            /**
1097             * Finds all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1098             *
1099             * @param groupId the group id to search with
1100             * @param folderId the folder id to search with
1101             * @param name the name to search with
1102             * @param status the status to search with
1103             * @return the matching d l file versions
1104             * @throws SystemException if a system exception occurred
1105             */
1106            public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
1107                    String name, int status) throws SystemException {
1108                    return findByG_F_N_S(groupId, folderId, name, status,
1109                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1110            }
1111    
1112            /**
1113             * Finds a range of all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1114             *
1115             * <p>
1116             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1117             * </p>
1118             *
1119             * @param groupId the group id to search with
1120             * @param folderId the folder id to search with
1121             * @param name the name to search with
1122             * @param status the status to search with
1123             * @param start the lower bound of the range of d l file versions to return
1124             * @param end the upper bound of the range of d l file versions to return (not inclusive)
1125             * @return the range of matching d l file versions
1126             * @throws SystemException if a system exception occurred
1127             */
1128            public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
1129                    String name, int status, int start, int end) throws SystemException {
1130                    return findByG_F_N_S(groupId, folderId, name, status, start, end, null);
1131            }
1132    
1133            /**
1134             * Finds an ordered range of all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1135             *
1136             * <p>
1137             * 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.
1138             * </p>
1139             *
1140             * @param groupId the group id to search with
1141             * @param folderId the folder id to search with
1142             * @param name the name to search with
1143             * @param status the status to search with
1144             * @param start the lower bound of the range of d l file versions to return
1145             * @param end the upper bound of the range of d l file versions to return (not inclusive)
1146             * @param orderByComparator the comparator to order the results by
1147             * @return the ordered range of matching d l file versions
1148             * @throws SystemException if a system exception occurred
1149             */
1150            public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
1151                    String name, int status, int start, int end,
1152                    OrderByComparator orderByComparator) throws SystemException {
1153                    Object[] finderArgs = new Object[] {
1154                                    groupId, folderId, name, status,
1155                                    
1156                                    String.valueOf(start), String.valueOf(end),
1157                                    String.valueOf(orderByComparator)
1158                            };
1159    
1160                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F_N_S,
1161                                    finderArgs, this);
1162    
1163                    if (list == null) {
1164                            StringBundler query = null;
1165    
1166                            if (orderByComparator != null) {
1167                                    query = new StringBundler(6 +
1168                                                    (orderByComparator.getOrderByFields().length * 3));
1169                            }
1170                            else {
1171                                    query = new StringBundler(6);
1172                            }
1173    
1174                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1175    
1176                            query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1177    
1178                            query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1179    
1180                            if (name == null) {
1181                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1182                            }
1183                            else {
1184                                    if (name.equals(StringPool.BLANK)) {
1185                                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1186                                    }
1187                                    else {
1188                                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1189                                    }
1190                            }
1191    
1192                            query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1193    
1194                            if (orderByComparator != null) {
1195                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1196                                            orderByComparator);
1197                            }
1198    
1199                            else {
1200                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1201                            }
1202    
1203                            String sql = query.toString();
1204    
1205                            Session session = null;
1206    
1207                            try {
1208                                    session = openSession();
1209    
1210                                    Query q = session.createQuery(sql);
1211    
1212                                    QueryPos qPos = QueryPos.getInstance(q);
1213    
1214                                    qPos.add(groupId);
1215    
1216                                    qPos.add(folderId);
1217    
1218                                    if (name != null) {
1219                                            qPos.add(name);
1220                                    }
1221    
1222                                    qPos.add(status);
1223    
1224                                    list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1225                                                    start, end);
1226                            }
1227                            catch (Exception e) {
1228                                    throw processException(e);
1229                            }
1230                            finally {
1231                                    if (list == null) {
1232                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_F_N_S,
1233                                                    finderArgs);
1234                                    }
1235                                    else {
1236                                            cacheResult(list);
1237    
1238                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N_S,
1239                                                    finderArgs, list);
1240                                    }
1241    
1242                                    closeSession(session);
1243                            }
1244                    }
1245    
1246                    return list;
1247            }
1248    
1249            /**
1250             * Finds the first d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1251             *
1252             * <p>
1253             * 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.
1254             * </p>
1255             *
1256             * @param groupId the group id to search with
1257             * @param folderId the folder id to search with
1258             * @param name the name to search with
1259             * @param status the status to search with
1260             * @param orderByComparator the comparator to order the set by
1261             * @return the first matching d l file version
1262             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
1263             * @throws SystemException if a system exception occurred
1264             */
1265            public DLFileVersion findByG_F_N_S_First(long groupId, long folderId,
1266                    String name, int status, OrderByComparator orderByComparator)
1267                    throws NoSuchFileVersionException, SystemException {
1268                    List<DLFileVersion> list = findByG_F_N_S(groupId, folderId, name,
1269                                    status, 0, 1, orderByComparator);
1270    
1271                    if (list.isEmpty()) {
1272                            StringBundler msg = new StringBundler(10);
1273    
1274                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1275    
1276                            msg.append("groupId=");
1277                            msg.append(groupId);
1278    
1279                            msg.append(", folderId=");
1280                            msg.append(folderId);
1281    
1282                            msg.append(", name=");
1283                            msg.append(name);
1284    
1285                            msg.append(", status=");
1286                            msg.append(status);
1287    
1288                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1289    
1290                            throw new NoSuchFileVersionException(msg.toString());
1291                    }
1292                    else {
1293                            return list.get(0);
1294                    }
1295            }
1296    
1297            /**
1298             * Finds the last d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1299             *
1300             * <p>
1301             * 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.
1302             * </p>
1303             *
1304             * @param groupId the group id to search with
1305             * @param folderId the folder id to search with
1306             * @param name the name to search with
1307             * @param status the status to search with
1308             * @param orderByComparator the comparator to order the set by
1309             * @return the last matching d l file version
1310             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
1311             * @throws SystemException if a system exception occurred
1312             */
1313            public DLFileVersion findByG_F_N_S_Last(long groupId, long folderId,
1314                    String name, int status, OrderByComparator orderByComparator)
1315                    throws NoSuchFileVersionException, SystemException {
1316                    int count = countByG_F_N_S(groupId, folderId, name, status);
1317    
1318                    List<DLFileVersion> list = findByG_F_N_S(groupId, folderId, name,
1319                                    status, count - 1, count, orderByComparator);
1320    
1321                    if (list.isEmpty()) {
1322                            StringBundler msg = new StringBundler(10);
1323    
1324                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1325    
1326                            msg.append("groupId=");
1327                            msg.append(groupId);
1328    
1329                            msg.append(", folderId=");
1330                            msg.append(folderId);
1331    
1332                            msg.append(", name=");
1333                            msg.append(name);
1334    
1335                            msg.append(", status=");
1336                            msg.append(status);
1337    
1338                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1339    
1340                            throw new NoSuchFileVersionException(msg.toString());
1341                    }
1342                    else {
1343                            return list.get(0);
1344                    }
1345            }
1346    
1347            /**
1348             * Finds the d l file versions before and after the current d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1349             *
1350             * <p>
1351             * 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.
1352             * </p>
1353             *
1354             * @param fileVersionId the primary key of the current d l file version
1355             * @param groupId the group id to search with
1356             * @param folderId the folder id to search with
1357             * @param name the name to search with
1358             * @param status the status to search with
1359             * @param orderByComparator the comparator to order the set by
1360             * @return the previous, current, and next d l file version
1361             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a d l file version with the primary key could not be found
1362             * @throws SystemException if a system exception occurred
1363             */
1364            public DLFileVersion[] findByG_F_N_S_PrevAndNext(long fileVersionId,
1365                    long groupId, long folderId, String name, int status,
1366                    OrderByComparator orderByComparator)
1367                    throws NoSuchFileVersionException, SystemException {
1368                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1369    
1370                    Session session = null;
1371    
1372                    try {
1373                            session = openSession();
1374    
1375                            DLFileVersion[] array = new DLFileVersionImpl[3];
1376    
1377                            array[0] = getByG_F_N_S_PrevAndNext(session, dlFileVersion,
1378                                            groupId, folderId, name, status, orderByComparator, true);
1379    
1380                            array[1] = dlFileVersion;
1381    
1382                            array[2] = getByG_F_N_S_PrevAndNext(session, dlFileVersion,
1383                                            groupId, folderId, name, status, orderByComparator, false);
1384    
1385                            return array;
1386                    }
1387                    catch (Exception e) {
1388                            throw processException(e);
1389                    }
1390                    finally {
1391                            closeSession(session);
1392                    }
1393            }
1394    
1395            protected DLFileVersion getByG_F_N_S_PrevAndNext(Session session,
1396                    DLFileVersion dlFileVersion, long groupId, long folderId, String name,
1397                    int status, OrderByComparator orderByComparator, boolean previous) {
1398                    StringBundler query = null;
1399    
1400                    if (orderByComparator != null) {
1401                            query = new StringBundler(6 +
1402                                            (orderByComparator.getOrderByFields().length * 6));
1403                    }
1404                    else {
1405                            query = new StringBundler(3);
1406                    }
1407    
1408                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1409    
1410                    query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1411    
1412                    query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1413    
1414                    if (name == null) {
1415                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1416                    }
1417                    else {
1418                            if (name.equals(StringPool.BLANK)) {
1419                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1420                            }
1421                            else {
1422                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1423                            }
1424                    }
1425    
1426                    query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1427    
1428                    if (orderByComparator != null) {
1429                            String[] orderByFields = orderByComparator.getOrderByFields();
1430    
1431                            if (orderByFields.length > 0) {
1432                                    query.append(WHERE_AND);
1433                            }
1434    
1435                            for (int i = 0; i < orderByFields.length; i++) {
1436                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1437                                    query.append(orderByFields[i]);
1438    
1439                                    if ((i + 1) < orderByFields.length) {
1440                                            if (orderByComparator.isAscending() ^ previous) {
1441                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1442                                            }
1443                                            else {
1444                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1445                                            }
1446                                    }
1447                                    else {
1448                                            if (orderByComparator.isAscending() ^ previous) {
1449                                                    query.append(WHERE_GREATER_THAN);
1450                                            }
1451                                            else {
1452                                                    query.append(WHERE_LESSER_THAN);
1453                                            }
1454                                    }
1455                            }
1456    
1457                            query.append(ORDER_BY_CLAUSE);
1458    
1459                            for (int i = 0; i < orderByFields.length; i++) {
1460                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1461                                    query.append(orderByFields[i]);
1462    
1463                                    if ((i + 1) < orderByFields.length) {
1464                                            if (orderByComparator.isAscending() ^ previous) {
1465                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1466                                            }
1467                                            else {
1468                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1469                                            }
1470                                    }
1471                                    else {
1472                                            if (orderByComparator.isAscending() ^ previous) {
1473                                                    query.append(ORDER_BY_ASC);
1474                                            }
1475                                            else {
1476                                                    query.append(ORDER_BY_DESC);
1477                                            }
1478                                    }
1479                            }
1480                    }
1481    
1482                    else {
1483                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1484                    }
1485    
1486                    String sql = query.toString();
1487    
1488                    Query q = session.createQuery(sql);
1489    
1490                    q.setFirstResult(0);
1491                    q.setMaxResults(2);
1492    
1493                    QueryPos qPos = QueryPos.getInstance(q);
1494    
1495                    qPos.add(groupId);
1496    
1497                    qPos.add(folderId);
1498    
1499                    if (name != null) {
1500                            qPos.add(name);
1501                    }
1502    
1503                    qPos.add(status);
1504    
1505                    if (orderByComparator != null) {
1506                            Object[] values = orderByComparator.getOrderByValues(dlFileVersion);
1507    
1508                            for (Object value : values) {
1509                                    qPos.add(value);
1510                            }
1511                    }
1512    
1513                    List<DLFileVersion> list = q.list();
1514    
1515                    if (list.size() == 2) {
1516                            return list.get(1);
1517                    }
1518                    else {
1519                            return null;
1520                    }
1521            }
1522    
1523            /**
1524             * Finds all the d l file versions.
1525             *
1526             * @return the d l file versions
1527             * @throws SystemException if a system exception occurred
1528             */
1529            public List<DLFileVersion> findAll() throws SystemException {
1530                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1531            }
1532    
1533            /**
1534             * Finds a range of all the d l file versions.
1535             *
1536             * <p>
1537             * 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.
1538             * </p>
1539             *
1540             * @param start the lower bound of the range of d l file versions to return
1541             * @param end the upper bound of the range of d l file versions to return (not inclusive)
1542             * @return the range of d l file versions
1543             * @throws SystemException if a system exception occurred
1544             */
1545            public List<DLFileVersion> findAll(int start, int end)
1546                    throws SystemException {
1547                    return findAll(start, end, null);
1548            }
1549    
1550            /**
1551             * Finds an ordered range of all the d l file versions.
1552             *
1553             * <p>
1554             * 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.
1555             * </p>
1556             *
1557             * @param start the lower bound of the range of d l file versions to return
1558             * @param end the upper bound of the range of d l file versions to return (not inclusive)
1559             * @param orderByComparator the comparator to order the results by
1560             * @return the ordered range of d l file versions
1561             * @throws SystemException if a system exception occurred
1562             */
1563            public List<DLFileVersion> findAll(int start, int end,
1564                    OrderByComparator orderByComparator) throws SystemException {
1565                    Object[] finderArgs = new Object[] {
1566                                    String.valueOf(start), String.valueOf(end),
1567                                    String.valueOf(orderByComparator)
1568                            };
1569    
1570                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1571                                    finderArgs, this);
1572    
1573                    if (list == null) {
1574                            StringBundler query = null;
1575                            String sql = null;
1576    
1577                            if (orderByComparator != null) {
1578                                    query = new StringBundler(2 +
1579                                                    (orderByComparator.getOrderByFields().length * 3));
1580    
1581                                    query.append(_SQL_SELECT_DLFILEVERSION);
1582    
1583                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1584                                            orderByComparator);
1585    
1586                                    sql = query.toString();
1587                            }
1588                            else {
1589                                    sql = _SQL_SELECT_DLFILEVERSION.concat(DLFileVersionModelImpl.ORDER_BY_JPQL);
1590                            }
1591    
1592                            Session session = null;
1593    
1594                            try {
1595                                    session = openSession();
1596    
1597                                    Query q = session.createQuery(sql);
1598    
1599                                    if (orderByComparator == null) {
1600                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1601                                                            start, end, false);
1602    
1603                                            Collections.sort(list);
1604                                    }
1605                                    else {
1606                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1607                                                            start, end);
1608                                    }
1609                            }
1610                            catch (Exception e) {
1611                                    throw processException(e);
1612                            }
1613                            finally {
1614                                    if (list == null) {
1615                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1616                                                    finderArgs);
1617                                    }
1618                                    else {
1619                                            cacheResult(list);
1620    
1621                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1622                                                    list);
1623                                    }
1624    
1625                                    closeSession(session);
1626                            }
1627                    }
1628    
1629                    return list;
1630            }
1631    
1632            /**
1633             * Removes all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; from the database.
1634             *
1635             * @param groupId the group id to search with
1636             * @param folderId the folder id to search with
1637             * @param name the name to search with
1638             * @throws SystemException if a system exception occurred
1639             */
1640            public void removeByG_F_N(long groupId, long folderId, String name)
1641                    throws SystemException {
1642                    for (DLFileVersion dlFileVersion : findByG_F_N(groupId, folderId, name)) {
1643                            remove(dlFileVersion);
1644                    }
1645            }
1646    
1647            /**
1648             * Removes the d l file version where groupId = &#63; and folderId = &#63; and name = &#63; and version = &#63; from the database.
1649             *
1650             * @param groupId the group id to search with
1651             * @param folderId the folder id to search with
1652             * @param name the name to search with
1653             * @param version the version to search with
1654             * @throws SystemException if a system exception occurred
1655             */
1656            public void removeByG_F_N_V(long groupId, long folderId, String name,
1657                    String version) throws NoSuchFileVersionException, SystemException {
1658                    DLFileVersion dlFileVersion = findByG_F_N_V(groupId, folderId, name,
1659                                    version);
1660    
1661                    remove(dlFileVersion);
1662            }
1663    
1664            /**
1665             * Removes all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63; from the database.
1666             *
1667             * @param groupId the group id to search with
1668             * @param folderId the folder id to search with
1669             * @param name the name to search with
1670             * @param status the status to search with
1671             * @throws SystemException if a system exception occurred
1672             */
1673            public void removeByG_F_N_S(long groupId, long folderId, String name,
1674                    int status) throws SystemException {
1675                    for (DLFileVersion dlFileVersion : findByG_F_N_S(groupId, folderId,
1676                                    name, status)) {
1677                            remove(dlFileVersion);
1678                    }
1679            }
1680    
1681            /**
1682             * Removes all the d l file versions from the database.
1683             *
1684             * @throws SystemException if a system exception occurred
1685             */
1686            public void removeAll() throws SystemException {
1687                    for (DLFileVersion dlFileVersion : findAll()) {
1688                            remove(dlFileVersion);
1689                    }
1690            }
1691    
1692            /**
1693             * Counts all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63;.
1694             *
1695             * @param groupId the group id to search with
1696             * @param folderId the folder id to search with
1697             * @param name the name to search with
1698             * @return the number of matching d l file versions
1699             * @throws SystemException if a system exception occurred
1700             */
1701            public int countByG_F_N(long groupId, long folderId, String name)
1702                    throws SystemException {
1703                    Object[] finderArgs = new Object[] { groupId, folderId, name };
1704    
1705                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N,
1706                                    finderArgs, this);
1707    
1708                    if (count == null) {
1709                            StringBundler query = new StringBundler(4);
1710    
1711                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1712    
1713                            query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
1714    
1715                            query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
1716    
1717                            if (name == null) {
1718                                    query.append(_FINDER_COLUMN_G_F_N_NAME_1);
1719                            }
1720                            else {
1721                                    if (name.equals(StringPool.BLANK)) {
1722                                            query.append(_FINDER_COLUMN_G_F_N_NAME_3);
1723                                    }
1724                                    else {
1725                                            query.append(_FINDER_COLUMN_G_F_N_NAME_2);
1726                                    }
1727                            }
1728    
1729                            String sql = query.toString();
1730    
1731                            Session session = null;
1732    
1733                            try {
1734                                    session = openSession();
1735    
1736                                    Query q = session.createQuery(sql);
1737    
1738                                    QueryPos qPos = QueryPos.getInstance(q);
1739    
1740                                    qPos.add(groupId);
1741    
1742                                    qPos.add(folderId);
1743    
1744                                    if (name != null) {
1745                                            qPos.add(name);
1746                                    }
1747    
1748                                    count = (Long)q.uniqueResult();
1749                            }
1750                            catch (Exception e) {
1751                                    throw processException(e);
1752                            }
1753                            finally {
1754                                    if (count == null) {
1755                                            count = Long.valueOf(0);
1756                                    }
1757    
1758                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N,
1759                                            finderArgs, count);
1760    
1761                                    closeSession(session);
1762                            }
1763                    }
1764    
1765                    return count.intValue();
1766            }
1767    
1768            /**
1769             * Counts all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and version = &#63;.
1770             *
1771             * @param groupId the group id to search with
1772             * @param folderId the folder id to search with
1773             * @param name the name to search with
1774             * @param version the version to search with
1775             * @return the number of matching d l file versions
1776             * @throws SystemException if a system exception occurred
1777             */
1778            public int countByG_F_N_V(long groupId, long folderId, String name,
1779                    String version) throws SystemException {
1780                    Object[] finderArgs = new Object[] { groupId, folderId, name, version };
1781    
1782                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N_V,
1783                                    finderArgs, this);
1784    
1785                    if (count == null) {
1786                            StringBundler query = new StringBundler(5);
1787    
1788                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1789    
1790                            query.append(_FINDER_COLUMN_G_F_N_V_GROUPID_2);
1791    
1792                            query.append(_FINDER_COLUMN_G_F_N_V_FOLDERID_2);
1793    
1794                            if (name == null) {
1795                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_1);
1796                            }
1797                            else {
1798                                    if (name.equals(StringPool.BLANK)) {
1799                                            query.append(_FINDER_COLUMN_G_F_N_V_NAME_3);
1800                                    }
1801                                    else {
1802                                            query.append(_FINDER_COLUMN_G_F_N_V_NAME_2);
1803                                    }
1804                            }
1805    
1806                            if (version == null) {
1807                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_1);
1808                            }
1809                            else {
1810                                    if (version.equals(StringPool.BLANK)) {
1811                                            query.append(_FINDER_COLUMN_G_F_N_V_VERSION_3);
1812                                    }
1813                                    else {
1814                                            query.append(_FINDER_COLUMN_G_F_N_V_VERSION_2);
1815                                    }
1816                            }
1817    
1818                            String sql = query.toString();
1819    
1820                            Session session = null;
1821    
1822                            try {
1823                                    session = openSession();
1824    
1825                                    Query q = session.createQuery(sql);
1826    
1827                                    QueryPos qPos = QueryPos.getInstance(q);
1828    
1829                                    qPos.add(groupId);
1830    
1831                                    qPos.add(folderId);
1832    
1833                                    if (name != null) {
1834                                            qPos.add(name);
1835                                    }
1836    
1837                                    if (version != null) {
1838                                            qPos.add(version);
1839                                    }
1840    
1841                                    count = (Long)q.uniqueResult();
1842                            }
1843                            catch (Exception e) {
1844                                    throw processException(e);
1845                            }
1846                            finally {
1847                                    if (count == null) {
1848                                            count = Long.valueOf(0);
1849                                    }
1850    
1851                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N_V,
1852                                            finderArgs, count);
1853    
1854                                    closeSession(session);
1855                            }
1856                    }
1857    
1858                    return count.intValue();
1859            }
1860    
1861            /**
1862             * Counts all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1863             *
1864             * @param groupId the group id to search with
1865             * @param folderId the folder id to search with
1866             * @param name the name to search with
1867             * @param status the status to search with
1868             * @return the number of matching d l file versions
1869             * @throws SystemException if a system exception occurred
1870             */
1871            public int countByG_F_N_S(long groupId, long folderId, String name,
1872                    int status) throws SystemException {
1873                    Object[] finderArgs = new Object[] { groupId, folderId, name, status };
1874    
1875                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N_S,
1876                                    finderArgs, this);
1877    
1878                    if (count == null) {
1879                            StringBundler query = new StringBundler(5);
1880    
1881                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1882    
1883                            query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1884    
1885                            query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1886    
1887                            if (name == null) {
1888                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1889                            }
1890                            else {
1891                                    if (name.equals(StringPool.BLANK)) {
1892                                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1893                                    }
1894                                    else {
1895                                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1896                                    }
1897                            }
1898    
1899                            query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1900    
1901                            String sql = query.toString();
1902    
1903                            Session session = null;
1904    
1905                            try {
1906                                    session = openSession();
1907    
1908                                    Query q = session.createQuery(sql);
1909    
1910                                    QueryPos qPos = QueryPos.getInstance(q);
1911    
1912                                    qPos.add(groupId);
1913    
1914                                    qPos.add(folderId);
1915    
1916                                    if (name != null) {
1917                                            qPos.add(name);
1918                                    }
1919    
1920                                    qPos.add(status);
1921    
1922                                    count = (Long)q.uniqueResult();
1923                            }
1924                            catch (Exception e) {
1925                                    throw processException(e);
1926                            }
1927                            finally {
1928                                    if (count == null) {
1929                                            count = Long.valueOf(0);
1930                                    }
1931    
1932                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N_S,
1933                                            finderArgs, count);
1934    
1935                                    closeSession(session);
1936                            }
1937                    }
1938    
1939                    return count.intValue();
1940            }
1941    
1942            /**
1943             * Counts all the d l file versions.
1944             *
1945             * @return the number of d l file versions
1946             * @throws SystemException if a system exception occurred
1947             */
1948            public int countAll() throws SystemException {
1949                    Object[] finderArgs = new Object[0];
1950    
1951                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1952                                    finderArgs, this);
1953    
1954                    if (count == null) {
1955                            Session session = null;
1956    
1957                            try {
1958                                    session = openSession();
1959    
1960                                    Query q = session.createQuery(_SQL_COUNT_DLFILEVERSION);
1961    
1962                                    count = (Long)q.uniqueResult();
1963                            }
1964                            catch (Exception e) {
1965                                    throw processException(e);
1966                            }
1967                            finally {
1968                                    if (count == null) {
1969                                            count = Long.valueOf(0);
1970                                    }
1971    
1972                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1973                                            count);
1974    
1975                                    closeSession(session);
1976                            }
1977                    }
1978    
1979                    return count.intValue();
1980            }
1981    
1982            /**
1983             * Initializes the d l file version persistence.
1984             */
1985            public void afterPropertiesSet() {
1986                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1987                                            com.liferay.portal.util.PropsUtil.get(
1988                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileVersion")));
1989    
1990                    if (listenerClassNames.length > 0) {
1991                            try {
1992                                    List<ModelListener<DLFileVersion>> listenersList = new ArrayList<ModelListener<DLFileVersion>>();
1993    
1994                                    for (String listenerClassName : listenerClassNames) {
1995                                            listenersList.add((ModelListener<DLFileVersion>)InstanceFactory.newInstance(
1996                                                            listenerClassName));
1997                                    }
1998    
1999                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2000                            }
2001                            catch (Exception e) {
2002                                    _log.error(e);
2003                            }
2004                    }
2005            }
2006    
2007            public void destroy() {
2008                    EntityCacheUtil.removeCache(DLFileVersionImpl.class.getName());
2009                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2010                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2011            }
2012    
2013            @BeanReference(type = DLFileEntryPersistence.class)
2014            protected DLFileEntryPersistence dlFileEntryPersistence;
2015            @BeanReference(type = DLFileRankPersistence.class)
2016            protected DLFileRankPersistence dlFileRankPersistence;
2017            @BeanReference(type = DLFileShortcutPersistence.class)
2018            protected DLFileShortcutPersistence dlFileShortcutPersistence;
2019            @BeanReference(type = DLFileVersionPersistence.class)
2020            protected DLFileVersionPersistence dlFileVersionPersistence;
2021            @BeanReference(type = DLFolderPersistence.class)
2022            protected DLFolderPersistence dlFolderPersistence;
2023            @BeanReference(type = ResourcePersistence.class)
2024            protected ResourcePersistence resourcePersistence;
2025            @BeanReference(type = UserPersistence.class)
2026            protected UserPersistence userPersistence;
2027            @BeanReference(type = AssetEntryPersistence.class)
2028            protected AssetEntryPersistence assetEntryPersistence;
2029            private static final String _SQL_SELECT_DLFILEVERSION = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion";
2030            private static final String _SQL_SELECT_DLFILEVERSION_WHERE = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ";
2031            private static final String _SQL_COUNT_DLFILEVERSION = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion";
2032            private static final String _SQL_COUNT_DLFILEVERSION_WHERE = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion WHERE ";
2033            private static final String _FINDER_COLUMN_G_F_N_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
2034            private static final String _FINDER_COLUMN_G_F_N_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
2035            private static final String _FINDER_COLUMN_G_F_N_NAME_1 = "dlFileVersion.name IS NULL";
2036            private static final String _FINDER_COLUMN_G_F_N_NAME_2 = "dlFileVersion.name = ?";
2037            private static final String _FINDER_COLUMN_G_F_N_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?)";
2038            private static final String _FINDER_COLUMN_G_F_N_V_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
2039            private static final String _FINDER_COLUMN_G_F_N_V_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
2040            private static final String _FINDER_COLUMN_G_F_N_V_NAME_1 = "dlFileVersion.name IS NULL AND ";
2041            private static final String _FINDER_COLUMN_G_F_N_V_NAME_2 = "dlFileVersion.name = ? AND ";
2042            private static final String _FINDER_COLUMN_G_F_N_V_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?) AND ";
2043            private static final String _FINDER_COLUMN_G_F_N_V_VERSION_1 = "dlFileVersion.version IS NULL";
2044            private static final String _FINDER_COLUMN_G_F_N_V_VERSION_2 = "dlFileVersion.version = ?";
2045            private static final String _FINDER_COLUMN_G_F_N_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = ?)";
2046            private static final String _FINDER_COLUMN_G_F_N_S_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
2047            private static final String _FINDER_COLUMN_G_F_N_S_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
2048            private static final String _FINDER_COLUMN_G_F_N_S_NAME_1 = "dlFileVersion.name IS NULL AND ";
2049            private static final String _FINDER_COLUMN_G_F_N_S_NAME_2 = "dlFileVersion.name = ? AND ";
2050            private static final String _FINDER_COLUMN_G_F_N_S_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?) AND ";
2051            private static final String _FINDER_COLUMN_G_F_N_S_STATUS_2 = "dlFileVersion.status = ?";
2052            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileVersion.";
2053            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileVersion exists with the primary key ";
2054            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileVersion exists with the key {";
2055            private static Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
2056    }