001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.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.getOriginalGroupId()),
297                                    new Long(dlFileVersionModelImpl.getOriginalFolderId()),
298                                    
299                            dlFileVersionModelImpl.getOriginalName(),
300                                    
301                            dlFileVersionModelImpl.getOriginalVersion()
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                            Session session = null;
564    
565                            try {
566                                    session = openSession();
567    
568                                    StringBundler query = null;
569    
570                                    if (orderByComparator != null) {
571                                            query = new StringBundler(5 +
572                                                            (orderByComparator.getOrderByFields().length * 3));
573                                    }
574                                    else {
575                                            query = new StringBundler(5);
576                                    }
577    
578                                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
579    
580                                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
581    
582                                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
583    
584                                    if (name == null) {
585                                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
586                                    }
587                                    else {
588                                            if (name.equals(StringPool.BLANK)) {
589                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
590                                            }
591                                            else {
592                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
593                                            }
594                                    }
595    
596                                    if (orderByComparator != null) {
597                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
598                                                    orderByComparator);
599                                    }
600    
601                                    else {
602                                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
603                                    }
604    
605                                    String sql = query.toString();
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                                            list = new ArrayList<DLFileVersion>();
628                                    }
629    
630                                    cacheResult(list);
631    
632                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N,
633                                            finderArgs, list);
634    
635                                    closeSession(session);
636                            }
637                    }
638    
639                    return list;
640            }
641    
642            /**
643             * Finds the first d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63;.
644             *
645             * <p>
646             * 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.
647             * </p>
648             *
649             * @param groupId the group id to search with
650             * @param folderId the folder id to search with
651             * @param name the name to search with
652             * @param orderByComparator the comparator to order the set by
653             * @return the first matching d l file version
654             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
655             * @throws SystemException if a system exception occurred
656             */
657            public DLFileVersion findByG_F_N_First(long groupId, long folderId,
658                    String name, OrderByComparator orderByComparator)
659                    throws NoSuchFileVersionException, SystemException {
660                    List<DLFileVersion> list = findByG_F_N(groupId, folderId, name, 0, 1,
661                                    orderByComparator);
662    
663                    if (list.isEmpty()) {
664                            StringBundler msg = new StringBundler(8);
665    
666                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
667    
668                            msg.append("groupId=");
669                            msg.append(groupId);
670    
671                            msg.append(", folderId=");
672                            msg.append(folderId);
673    
674                            msg.append(", name=");
675                            msg.append(name);
676    
677                            msg.append(StringPool.CLOSE_CURLY_BRACE);
678    
679                            throw new NoSuchFileVersionException(msg.toString());
680                    }
681                    else {
682                            return list.get(0);
683                    }
684            }
685    
686            /**
687             * Finds the last d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63;.
688             *
689             * <p>
690             * 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.
691             * </p>
692             *
693             * @param groupId the group id to search with
694             * @param folderId the folder id to search with
695             * @param name the name to search with
696             * @param orderByComparator the comparator to order the set by
697             * @return the last matching d l file version
698             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
699             * @throws SystemException if a system exception occurred
700             */
701            public DLFileVersion findByG_F_N_Last(long groupId, long folderId,
702                    String name, OrderByComparator orderByComparator)
703                    throws NoSuchFileVersionException, SystemException {
704                    int count = countByG_F_N(groupId, folderId, name);
705    
706                    List<DLFileVersion> list = findByG_F_N(groupId, folderId, name,
707                                    count - 1, count, orderByComparator);
708    
709                    if (list.isEmpty()) {
710                            StringBundler msg = new StringBundler(8);
711    
712                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
713    
714                            msg.append("groupId=");
715                            msg.append(groupId);
716    
717                            msg.append(", folderId=");
718                            msg.append(folderId);
719    
720                            msg.append(", name=");
721                            msg.append(name);
722    
723                            msg.append(StringPool.CLOSE_CURLY_BRACE);
724    
725                            throw new NoSuchFileVersionException(msg.toString());
726                    }
727                    else {
728                            return list.get(0);
729                    }
730            }
731    
732            /**
733             * 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;.
734             *
735             * <p>
736             * 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.
737             * </p>
738             *
739             * @param fileVersionId the primary key of the current d l file version
740             * @param groupId the group id to search with
741             * @param folderId the folder id to search with
742             * @param name the name to search with
743             * @param orderByComparator the comparator to order the set by
744             * @return the previous, current, and next d l file version
745             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a d l file version with the primary key could not be found
746             * @throws SystemException if a system exception occurred
747             */
748            public DLFileVersion[] findByG_F_N_PrevAndNext(long fileVersionId,
749                    long groupId, long folderId, String name,
750                    OrderByComparator orderByComparator)
751                    throws NoSuchFileVersionException, SystemException {
752                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
753    
754                    Session session = null;
755    
756                    try {
757                            session = openSession();
758    
759                            DLFileVersion[] array = new DLFileVersionImpl[3];
760    
761                            array[0] = getByG_F_N_PrevAndNext(session, dlFileVersion, groupId,
762                                            folderId, name, orderByComparator, true);
763    
764                            array[1] = dlFileVersion;
765    
766                            array[2] = getByG_F_N_PrevAndNext(session, dlFileVersion, groupId,
767                                            folderId, name, orderByComparator, false);
768    
769                            return array;
770                    }
771                    catch (Exception e) {
772                            throw processException(e);
773                    }
774                    finally {
775                            closeSession(session);
776                    }
777            }
778    
779            protected DLFileVersion getByG_F_N_PrevAndNext(Session session,
780                    DLFileVersion dlFileVersion, long groupId, long folderId, String name,
781                    OrderByComparator orderByComparator, boolean previous) {
782                    StringBundler query = null;
783    
784                    if (orderByComparator != null) {
785                            query = new StringBundler(6 +
786                                            (orderByComparator.getOrderByFields().length * 6));
787                    }
788                    else {
789                            query = new StringBundler(3);
790                    }
791    
792                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
793    
794                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
795    
796                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
797    
798                    if (name == null) {
799                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
800                    }
801                    else {
802                            if (name.equals(StringPool.BLANK)) {
803                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
804                            }
805                            else {
806                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
807                            }
808                    }
809    
810                    if (orderByComparator != null) {
811                            String[] orderByFields = orderByComparator.getOrderByFields();
812    
813                            if (orderByFields.length > 0) {
814                                    query.append(WHERE_AND);
815                            }
816    
817                            for (int i = 0; i < orderByFields.length; i++) {
818                                    query.append(_ORDER_BY_ENTITY_ALIAS);
819                                    query.append(orderByFields[i]);
820    
821                                    if ((i + 1) < orderByFields.length) {
822                                            if (orderByComparator.isAscending() ^ previous) {
823                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
824                                            }
825                                            else {
826                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
827                                            }
828                                    }
829                                    else {
830                                            if (orderByComparator.isAscending() ^ previous) {
831                                                    query.append(WHERE_GREATER_THAN);
832                                            }
833                                            else {
834                                                    query.append(WHERE_LESSER_THAN);
835                                            }
836                                    }
837                            }
838    
839                            query.append(ORDER_BY_CLAUSE);
840    
841                            for (int i = 0; i < orderByFields.length; i++) {
842                                    query.append(_ORDER_BY_ENTITY_ALIAS);
843                                    query.append(orderByFields[i]);
844    
845                                    if ((i + 1) < orderByFields.length) {
846                                            if (orderByComparator.isAscending() ^ previous) {
847                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
848                                            }
849                                            else {
850                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
851                                            }
852                                    }
853                                    else {
854                                            if (orderByComparator.isAscending() ^ previous) {
855                                                    query.append(ORDER_BY_ASC);
856                                            }
857                                            else {
858                                                    query.append(ORDER_BY_DESC);
859                                            }
860                                    }
861                            }
862                    }
863    
864                    else {
865                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
866                    }
867    
868                    String sql = query.toString();
869    
870                    Query q = session.createQuery(sql);
871    
872                    q.setFirstResult(0);
873                    q.setMaxResults(2);
874    
875                    QueryPos qPos = QueryPos.getInstance(q);
876    
877                    qPos.add(groupId);
878    
879                    qPos.add(folderId);
880    
881                    if (name != null) {
882                            qPos.add(name);
883                    }
884    
885                    if (orderByComparator != null) {
886                            Object[] values = orderByComparator.getOrderByValues(dlFileVersion);
887    
888                            for (Object value : values) {
889                                    qPos.add(value);
890                            }
891                    }
892    
893                    List<DLFileVersion> list = q.list();
894    
895                    if (list.size() == 2) {
896                            return list.get(1);
897                    }
898                    else {
899                            return null;
900                    }
901            }
902    
903            /**
904             * 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.
905             *
906             * @param groupId the group id to search with
907             * @param folderId the folder id to search with
908             * @param name the name to search with
909             * @param version the version to search with
910             * @return the matching d l file version
911             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
912             * @throws SystemException if a system exception occurred
913             */
914            public DLFileVersion findByG_F_N_V(long groupId, long folderId,
915                    String name, String version)
916                    throws NoSuchFileVersionException, SystemException {
917                    DLFileVersion dlFileVersion = fetchByG_F_N_V(groupId, folderId, name,
918                                    version);
919    
920                    if (dlFileVersion == null) {
921                            StringBundler msg = new StringBundler(10);
922    
923                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
924    
925                            msg.append("groupId=");
926                            msg.append(groupId);
927    
928                            msg.append(", folderId=");
929                            msg.append(folderId);
930    
931                            msg.append(", name=");
932                            msg.append(name);
933    
934                            msg.append(", version=");
935                            msg.append(version);
936    
937                            msg.append(StringPool.CLOSE_CURLY_BRACE);
938    
939                            if (_log.isWarnEnabled()) {
940                                    _log.warn(msg.toString());
941                            }
942    
943                            throw new NoSuchFileVersionException(msg.toString());
944                    }
945    
946                    return dlFileVersion;
947            }
948    
949            /**
950             * 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.
951             *
952             * @param groupId the group id to search with
953             * @param folderId the folder id to search with
954             * @param name the name to search with
955             * @param version the version to search with
956             * @return the matching d l file version, or <code>null</code> if a matching d l file version could not be found
957             * @throws SystemException if a system exception occurred
958             */
959            public DLFileVersion fetchByG_F_N_V(long groupId, long folderId,
960                    String name, String version) throws SystemException {
961                    return fetchByG_F_N_V(groupId, folderId, name, version, true);
962            }
963    
964            /**
965             * 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.
966             *
967             * @param groupId the group id to search with
968             * @param folderId the folder id to search with
969             * @param name the name to search with
970             * @param version the version to search with
971             * @return the matching d l file version, or <code>null</code> if a matching d l file version could not be found
972             * @throws SystemException if a system exception occurred
973             */
974            public DLFileVersion fetchByG_F_N_V(long groupId, long folderId,
975                    String name, String version, boolean retrieveFromCache)
976                    throws SystemException {
977                    Object[] finderArgs = new Object[] { groupId, folderId, name, version };
978    
979                    Object result = null;
980    
981                    if (retrieveFromCache) {
982                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_F_N_V,
983                                            finderArgs, this);
984                    }
985    
986                    if (result == null) {
987                            Session session = null;
988    
989                            try {
990                                    session = openSession();
991    
992                                    StringBundler query = new StringBundler(6);
993    
994                                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
995    
996                                    query.append(_FINDER_COLUMN_G_F_N_V_GROUPID_2);
997    
998                                    query.append(_FINDER_COLUMN_G_F_N_V_FOLDERID_2);
999    
1000                                    if (name == null) {
1001                                            query.append(_FINDER_COLUMN_G_F_N_V_NAME_1);
1002                                    }
1003                                    else {
1004                                            if (name.equals(StringPool.BLANK)) {
1005                                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_3);
1006                                            }
1007                                            else {
1008                                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_2);
1009                                            }
1010                                    }
1011    
1012                                    if (version == null) {
1013                                            query.append(_FINDER_COLUMN_G_F_N_V_VERSION_1);
1014                                    }
1015                                    else {
1016                                            if (version.equals(StringPool.BLANK)) {
1017                                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_3);
1018                                            }
1019                                            else {
1020                                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_2);
1021                                            }
1022                                    }
1023    
1024                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1025    
1026                                    String sql = query.toString();
1027    
1028                                    Query q = session.createQuery(sql);
1029    
1030                                    QueryPos qPos = QueryPos.getInstance(q);
1031    
1032                                    qPos.add(groupId);
1033    
1034                                    qPos.add(folderId);
1035    
1036                                    if (name != null) {
1037                                            qPos.add(name);
1038                                    }
1039    
1040                                    if (version != null) {
1041                                            qPos.add(version);
1042                                    }
1043    
1044                                    List<DLFileVersion> list = q.list();
1045    
1046                                    result = list;
1047    
1048                                    DLFileVersion dlFileVersion = null;
1049    
1050                                    if (list.isEmpty()) {
1051                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
1052                                                    finderArgs, list);
1053                                    }
1054                                    else {
1055                                            dlFileVersion = list.get(0);
1056    
1057                                            cacheResult(dlFileVersion);
1058    
1059                                            if ((dlFileVersion.getGroupId() != groupId) ||
1060                                                            (dlFileVersion.getFolderId() != folderId) ||
1061                                                            (dlFileVersion.getName() == null) ||
1062                                                            !dlFileVersion.getName().equals(name) ||
1063                                                            (dlFileVersion.getVersion() == null) ||
1064                                                            !dlFileVersion.getVersion().equals(version)) {
1065                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
1066                                                            finderArgs, dlFileVersion);
1067                                            }
1068                                    }
1069    
1070                                    return dlFileVersion;
1071                            }
1072                            catch (Exception e) {
1073                                    throw processException(e);
1074                            }
1075                            finally {
1076                                    if (result == null) {
1077                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
1078                                                    finderArgs, new ArrayList<DLFileVersion>());
1079                                    }
1080    
1081                                    closeSession(session);
1082                            }
1083                    }
1084                    else {
1085                            if (result instanceof List<?>) {
1086                                    return null;
1087                            }
1088                            else {
1089                                    return (DLFileVersion)result;
1090                            }
1091                    }
1092            }
1093    
1094            /**
1095             * Finds all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1096             *
1097             * @param groupId the group id to search with
1098             * @param folderId the folder id to search with
1099             * @param name the name to search with
1100             * @param status the status to search with
1101             * @return the matching d l file versions
1102             * @throws SystemException if a system exception occurred
1103             */
1104            public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
1105                    String name, int status) throws SystemException {
1106                    return findByG_F_N_S(groupId, folderId, name, status,
1107                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1108            }
1109    
1110            /**
1111             * Finds a range of all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1112             *
1113             * <p>
1114             * 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.
1115             * </p>
1116             *
1117             * @param groupId the group id to search with
1118             * @param folderId the folder id to search with
1119             * @param name the name to search with
1120             * @param status the status to search with
1121             * @param start the lower bound of the range of d l file versions to return
1122             * @param end the upper bound of the range of d l file versions to return (not inclusive)
1123             * @return the range of matching d l file versions
1124             * @throws SystemException if a system exception occurred
1125             */
1126            public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
1127                    String name, int status, int start, int end) throws SystemException {
1128                    return findByG_F_N_S(groupId, folderId, name, status, start, end, null);
1129            }
1130    
1131            /**
1132             * Finds an ordered range of all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1133             *
1134             * <p>
1135             * 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.
1136             * </p>
1137             *
1138             * @param groupId the group id to search with
1139             * @param folderId the folder id to search with
1140             * @param name the name to search with
1141             * @param status the status to search with
1142             * @param start the lower bound of the range of d l file versions to return
1143             * @param end the upper bound of the range of d l file versions to return (not inclusive)
1144             * @param orderByComparator the comparator to order the results by
1145             * @return the ordered range of matching d l file versions
1146             * @throws SystemException if a system exception occurred
1147             */
1148            public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
1149                    String name, int status, int start, int end,
1150                    OrderByComparator orderByComparator) throws SystemException {
1151                    Object[] finderArgs = new Object[] {
1152                                    groupId, folderId, name, status,
1153                                    
1154                                    String.valueOf(start), String.valueOf(end),
1155                                    String.valueOf(orderByComparator)
1156                            };
1157    
1158                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F_N_S,
1159                                    finderArgs, this);
1160    
1161                    if (list == null) {
1162                            Session session = null;
1163    
1164                            try {
1165                                    session = openSession();
1166    
1167                                    StringBundler query = null;
1168    
1169                                    if (orderByComparator != null) {
1170                                            query = new StringBundler(6 +
1171                                                            (orderByComparator.getOrderByFields().length * 3));
1172                                    }
1173                                    else {
1174                                            query = new StringBundler(6);
1175                                    }
1176    
1177                                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1178    
1179                                    query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1180    
1181                                    query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1182    
1183                                    if (name == null) {
1184                                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1185                                    }
1186                                    else {
1187                                            if (name.equals(StringPool.BLANK)) {
1188                                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1189                                            }
1190                                            else {
1191                                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1192                                            }
1193                                    }
1194    
1195                                    query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1196    
1197                                    if (orderByComparator != null) {
1198                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1199                                                    orderByComparator);
1200                                    }
1201    
1202                                    else {
1203                                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1204                                    }
1205    
1206                                    String sql = query.toString();
1207    
1208                                    Query q = session.createQuery(sql);
1209    
1210                                    QueryPos qPos = QueryPos.getInstance(q);
1211    
1212                                    qPos.add(groupId);
1213    
1214                                    qPos.add(folderId);
1215    
1216                                    if (name != null) {
1217                                            qPos.add(name);
1218                                    }
1219    
1220                                    qPos.add(status);
1221    
1222                                    list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1223                                                    start, end);
1224                            }
1225                            catch (Exception e) {
1226                                    throw processException(e);
1227                            }
1228                            finally {
1229                                    if (list == null) {
1230                                            list = new ArrayList<DLFileVersion>();
1231                                    }
1232    
1233                                    cacheResult(list);
1234    
1235                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N_S,
1236                                            finderArgs, list);
1237    
1238                                    closeSession(session);
1239                            }
1240                    }
1241    
1242                    return list;
1243            }
1244    
1245            /**
1246             * Finds the first d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1247             *
1248             * <p>
1249             * 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.
1250             * </p>
1251             *
1252             * @param groupId the group id to search with
1253             * @param folderId the folder id to search with
1254             * @param name the name to search with
1255             * @param status the status to search with
1256             * @param orderByComparator the comparator to order the set by
1257             * @return the first matching d l file version
1258             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
1259             * @throws SystemException if a system exception occurred
1260             */
1261            public DLFileVersion findByG_F_N_S_First(long groupId, long folderId,
1262                    String name, int status, OrderByComparator orderByComparator)
1263                    throws NoSuchFileVersionException, SystemException {
1264                    List<DLFileVersion> list = findByG_F_N_S(groupId, folderId, name,
1265                                    status, 0, 1, orderByComparator);
1266    
1267                    if (list.isEmpty()) {
1268                            StringBundler msg = new StringBundler(10);
1269    
1270                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1271    
1272                            msg.append("groupId=");
1273                            msg.append(groupId);
1274    
1275                            msg.append(", folderId=");
1276                            msg.append(folderId);
1277    
1278                            msg.append(", name=");
1279                            msg.append(name);
1280    
1281                            msg.append(", status=");
1282                            msg.append(status);
1283    
1284                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1285    
1286                            throw new NoSuchFileVersionException(msg.toString());
1287                    }
1288                    else {
1289                            return list.get(0);
1290                    }
1291            }
1292    
1293            /**
1294             * Finds the last d l file version in the ordered set where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1295             *
1296             * <p>
1297             * 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.
1298             * </p>
1299             *
1300             * @param groupId the group id to search with
1301             * @param folderId the folder id to search with
1302             * @param name the name to search with
1303             * @param status the status to search with
1304             * @param orderByComparator the comparator to order the set by
1305             * @return the last matching d l file version
1306             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching d l file version could not be found
1307             * @throws SystemException if a system exception occurred
1308             */
1309            public DLFileVersion findByG_F_N_S_Last(long groupId, long folderId,
1310                    String name, int status, OrderByComparator orderByComparator)
1311                    throws NoSuchFileVersionException, SystemException {
1312                    int count = countByG_F_N_S(groupId, folderId, name, status);
1313    
1314                    List<DLFileVersion> list = findByG_F_N_S(groupId, folderId, name,
1315                                    status, count - 1, count, orderByComparator);
1316    
1317                    if (list.isEmpty()) {
1318                            StringBundler msg = new StringBundler(10);
1319    
1320                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1321    
1322                            msg.append("groupId=");
1323                            msg.append(groupId);
1324    
1325                            msg.append(", folderId=");
1326                            msg.append(folderId);
1327    
1328                            msg.append(", name=");
1329                            msg.append(name);
1330    
1331                            msg.append(", status=");
1332                            msg.append(status);
1333    
1334                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1335    
1336                            throw new NoSuchFileVersionException(msg.toString());
1337                    }
1338                    else {
1339                            return list.get(0);
1340                    }
1341            }
1342    
1343            /**
1344             * 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;.
1345             *
1346             * <p>
1347             * 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.
1348             * </p>
1349             *
1350             * @param fileVersionId the primary key of the current d l file version
1351             * @param groupId the group id to search with
1352             * @param folderId the folder id to search with
1353             * @param name the name to search with
1354             * @param status the status to search with
1355             * @param orderByComparator the comparator to order the set by
1356             * @return the previous, current, and next d l file version
1357             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a d l file version with the primary key could not be found
1358             * @throws SystemException if a system exception occurred
1359             */
1360            public DLFileVersion[] findByG_F_N_S_PrevAndNext(long fileVersionId,
1361                    long groupId, long folderId, String name, int status,
1362                    OrderByComparator orderByComparator)
1363                    throws NoSuchFileVersionException, SystemException {
1364                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1365    
1366                    Session session = null;
1367    
1368                    try {
1369                            session = openSession();
1370    
1371                            DLFileVersion[] array = new DLFileVersionImpl[3];
1372    
1373                            array[0] = getByG_F_N_S_PrevAndNext(session, dlFileVersion,
1374                                            groupId, folderId, name, status, orderByComparator, true);
1375    
1376                            array[1] = dlFileVersion;
1377    
1378                            array[2] = getByG_F_N_S_PrevAndNext(session, dlFileVersion,
1379                                            groupId, folderId, name, status, orderByComparator, false);
1380    
1381                            return array;
1382                    }
1383                    catch (Exception e) {
1384                            throw processException(e);
1385                    }
1386                    finally {
1387                            closeSession(session);
1388                    }
1389            }
1390    
1391            protected DLFileVersion getByG_F_N_S_PrevAndNext(Session session,
1392                    DLFileVersion dlFileVersion, long groupId, long folderId, String name,
1393                    int status, OrderByComparator orderByComparator, boolean previous) {
1394                    StringBundler query = null;
1395    
1396                    if (orderByComparator != null) {
1397                            query = new StringBundler(6 +
1398                                            (orderByComparator.getOrderByFields().length * 6));
1399                    }
1400                    else {
1401                            query = new StringBundler(3);
1402                    }
1403    
1404                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1405    
1406                    query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1407    
1408                    query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1409    
1410                    if (name == null) {
1411                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1412                    }
1413                    else {
1414                            if (name.equals(StringPool.BLANK)) {
1415                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1416                            }
1417                            else {
1418                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1419                            }
1420                    }
1421    
1422                    query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1423    
1424                    if (orderByComparator != null) {
1425                            String[] orderByFields = orderByComparator.getOrderByFields();
1426    
1427                            if (orderByFields.length > 0) {
1428                                    query.append(WHERE_AND);
1429                            }
1430    
1431                            for (int i = 0; i < orderByFields.length; i++) {
1432                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1433                                    query.append(orderByFields[i]);
1434    
1435                                    if ((i + 1) < orderByFields.length) {
1436                                            if (orderByComparator.isAscending() ^ previous) {
1437                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1438                                            }
1439                                            else {
1440                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1441                                            }
1442                                    }
1443                                    else {
1444                                            if (orderByComparator.isAscending() ^ previous) {
1445                                                    query.append(WHERE_GREATER_THAN);
1446                                            }
1447                                            else {
1448                                                    query.append(WHERE_LESSER_THAN);
1449                                            }
1450                                    }
1451                            }
1452    
1453                            query.append(ORDER_BY_CLAUSE);
1454    
1455                            for (int i = 0; i < orderByFields.length; i++) {
1456                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1457                                    query.append(orderByFields[i]);
1458    
1459                                    if ((i + 1) < orderByFields.length) {
1460                                            if (orderByComparator.isAscending() ^ previous) {
1461                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1462                                            }
1463                                            else {
1464                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1465                                            }
1466                                    }
1467                                    else {
1468                                            if (orderByComparator.isAscending() ^ previous) {
1469                                                    query.append(ORDER_BY_ASC);
1470                                            }
1471                                            else {
1472                                                    query.append(ORDER_BY_DESC);
1473                                            }
1474                                    }
1475                            }
1476                    }
1477    
1478                    else {
1479                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1480                    }
1481    
1482                    String sql = query.toString();
1483    
1484                    Query q = session.createQuery(sql);
1485    
1486                    q.setFirstResult(0);
1487                    q.setMaxResults(2);
1488    
1489                    QueryPos qPos = QueryPos.getInstance(q);
1490    
1491                    qPos.add(groupId);
1492    
1493                    qPos.add(folderId);
1494    
1495                    if (name != null) {
1496                            qPos.add(name);
1497                    }
1498    
1499                    qPos.add(status);
1500    
1501                    if (orderByComparator != null) {
1502                            Object[] values = orderByComparator.getOrderByValues(dlFileVersion);
1503    
1504                            for (Object value : values) {
1505                                    qPos.add(value);
1506                            }
1507                    }
1508    
1509                    List<DLFileVersion> list = q.list();
1510    
1511                    if (list.size() == 2) {
1512                            return list.get(1);
1513                    }
1514                    else {
1515                            return null;
1516                    }
1517            }
1518    
1519            /**
1520             * Finds all the d l file versions.
1521             *
1522             * @return the d l file versions
1523             * @throws SystemException if a system exception occurred
1524             */
1525            public List<DLFileVersion> findAll() throws SystemException {
1526                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1527            }
1528    
1529            /**
1530             * Finds a range of all the d l file versions.
1531             *
1532             * <p>
1533             * 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.
1534             * </p>
1535             *
1536             * @param start the lower bound of the range of d l file versions to return
1537             * @param end the upper bound of the range of d l file versions to return (not inclusive)
1538             * @return the range of d l file versions
1539             * @throws SystemException if a system exception occurred
1540             */
1541            public List<DLFileVersion> findAll(int start, int end)
1542                    throws SystemException {
1543                    return findAll(start, end, null);
1544            }
1545    
1546            /**
1547             * Finds an ordered range of all the d l file versions.
1548             *
1549             * <p>
1550             * 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.
1551             * </p>
1552             *
1553             * @param start the lower bound of the range of d l file versions to return
1554             * @param end the upper bound of the range of d l file versions to return (not inclusive)
1555             * @param orderByComparator the comparator to order the results by
1556             * @return the ordered range of d l file versions
1557             * @throws SystemException if a system exception occurred
1558             */
1559            public List<DLFileVersion> findAll(int start, int end,
1560                    OrderByComparator orderByComparator) throws SystemException {
1561                    Object[] finderArgs = new Object[] {
1562                                    String.valueOf(start), String.valueOf(end),
1563                                    String.valueOf(orderByComparator)
1564                            };
1565    
1566                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1567                                    finderArgs, this);
1568    
1569                    if (list == null) {
1570                            Session session = null;
1571    
1572                            try {
1573                                    session = openSession();
1574    
1575                                    StringBundler query = null;
1576                                    String sql = null;
1577    
1578                                    if (orderByComparator != null) {
1579                                            query = new StringBundler(2 +
1580                                                            (orderByComparator.getOrderByFields().length * 3));
1581    
1582                                            query.append(_SQL_SELECT_DLFILEVERSION);
1583    
1584                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1585                                                    orderByComparator);
1586    
1587                                            sql = query.toString();
1588                                    }
1589                                    else {
1590                                            sql = _SQL_SELECT_DLFILEVERSION.concat(DLFileVersionModelImpl.ORDER_BY_JPQL);
1591                                    }
1592    
1593                                    Query q = session.createQuery(sql);
1594    
1595                                    if (orderByComparator == null) {
1596                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1597                                                            start, end, false);
1598    
1599                                            Collections.sort(list);
1600                                    }
1601                                    else {
1602                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1603                                                            start, end);
1604                                    }
1605                            }
1606                            catch (Exception e) {
1607                                    throw processException(e);
1608                            }
1609                            finally {
1610                                    if (list == null) {
1611                                            list = new ArrayList<DLFileVersion>();
1612                                    }
1613    
1614                                    cacheResult(list);
1615    
1616                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1617    
1618                                    closeSession(session);
1619                            }
1620                    }
1621    
1622                    return list;
1623            }
1624    
1625            /**
1626             * Removes all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; from the database.
1627             *
1628             * @param groupId the group id to search with
1629             * @param folderId the folder id to search with
1630             * @param name the name to search with
1631             * @throws SystemException if a system exception occurred
1632             */
1633            public void removeByG_F_N(long groupId, long folderId, String name)
1634                    throws SystemException {
1635                    for (DLFileVersion dlFileVersion : findByG_F_N(groupId, folderId, name)) {
1636                            remove(dlFileVersion);
1637                    }
1638            }
1639    
1640            /**
1641             * Removes the d l file version where groupId = &#63; and folderId = &#63; and name = &#63; and version = &#63; from the database.
1642             *
1643             * @param groupId the group id to search with
1644             * @param folderId the folder id to search with
1645             * @param name the name to search with
1646             * @param version the version to search with
1647             * @throws SystemException if a system exception occurred
1648             */
1649            public void removeByG_F_N_V(long groupId, long folderId, String name,
1650                    String version) throws NoSuchFileVersionException, SystemException {
1651                    DLFileVersion dlFileVersion = findByG_F_N_V(groupId, folderId, name,
1652                                    version);
1653    
1654                    remove(dlFileVersion);
1655            }
1656    
1657            /**
1658             * Removes all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63; from the database.
1659             *
1660             * @param groupId the group id to search with
1661             * @param folderId the folder id to search with
1662             * @param name the name to search with
1663             * @param status the status to search with
1664             * @throws SystemException if a system exception occurred
1665             */
1666            public void removeByG_F_N_S(long groupId, long folderId, String name,
1667                    int status) throws SystemException {
1668                    for (DLFileVersion dlFileVersion : findByG_F_N_S(groupId, folderId,
1669                                    name, status)) {
1670                            remove(dlFileVersion);
1671                    }
1672            }
1673    
1674            /**
1675             * Removes all the d l file versions from the database.
1676             *
1677             * @throws SystemException if a system exception occurred
1678             */
1679            public void removeAll() throws SystemException {
1680                    for (DLFileVersion dlFileVersion : findAll()) {
1681                            remove(dlFileVersion);
1682                    }
1683            }
1684    
1685            /**
1686             * Counts all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63;.
1687             *
1688             * @param groupId the group id to search with
1689             * @param folderId the folder id to search with
1690             * @param name the name to search with
1691             * @return the number of matching d l file versions
1692             * @throws SystemException if a system exception occurred
1693             */
1694            public int countByG_F_N(long groupId, long folderId, String name)
1695                    throws SystemException {
1696                    Object[] finderArgs = new Object[] { groupId, folderId, name };
1697    
1698                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N,
1699                                    finderArgs, this);
1700    
1701                    if (count == null) {
1702                            Session session = null;
1703    
1704                            try {
1705                                    session = openSession();
1706    
1707                                    StringBundler query = new StringBundler(4);
1708    
1709                                    query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1710    
1711                                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
1712    
1713                                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
1714    
1715                                    if (name == null) {
1716                                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
1717                                    }
1718                                    else {
1719                                            if (name.equals(StringPool.BLANK)) {
1720                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
1721                                            }
1722                                            else {
1723                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
1724                                            }
1725                                    }
1726    
1727                                    String sql = query.toString();
1728    
1729                                    Query q = session.createQuery(sql);
1730    
1731                                    QueryPos qPos = QueryPos.getInstance(q);
1732    
1733                                    qPos.add(groupId);
1734    
1735                                    qPos.add(folderId);
1736    
1737                                    if (name != null) {
1738                                            qPos.add(name);
1739                                    }
1740    
1741                                    count = (Long)q.uniqueResult();
1742                            }
1743                            catch (Exception e) {
1744                                    throw processException(e);
1745                            }
1746                            finally {
1747                                    if (count == null) {
1748                                            count = Long.valueOf(0);
1749                                    }
1750    
1751                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N,
1752                                            finderArgs, count);
1753    
1754                                    closeSession(session);
1755                            }
1756                    }
1757    
1758                    return count.intValue();
1759            }
1760    
1761            /**
1762             * Counts all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and version = &#63;.
1763             *
1764             * @param groupId the group id to search with
1765             * @param folderId the folder id to search with
1766             * @param name the name to search with
1767             * @param version the version to search with
1768             * @return the number of matching d l file versions
1769             * @throws SystemException if a system exception occurred
1770             */
1771            public int countByG_F_N_V(long groupId, long folderId, String name,
1772                    String version) throws SystemException {
1773                    Object[] finderArgs = new Object[] { groupId, folderId, name, version };
1774    
1775                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N_V,
1776                                    finderArgs, this);
1777    
1778                    if (count == null) {
1779                            Session session = null;
1780    
1781                            try {
1782                                    session = openSession();
1783    
1784                                    StringBundler query = new StringBundler(5);
1785    
1786                                    query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1787    
1788                                    query.append(_FINDER_COLUMN_G_F_N_V_GROUPID_2);
1789    
1790                                    query.append(_FINDER_COLUMN_G_F_N_V_FOLDERID_2);
1791    
1792                                    if (name == null) {
1793                                            query.append(_FINDER_COLUMN_G_F_N_V_NAME_1);
1794                                    }
1795                                    else {
1796                                            if (name.equals(StringPool.BLANK)) {
1797                                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_3);
1798                                            }
1799                                            else {
1800                                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_2);
1801                                            }
1802                                    }
1803    
1804                                    if (version == null) {
1805                                            query.append(_FINDER_COLUMN_G_F_N_V_VERSION_1);
1806                                    }
1807                                    else {
1808                                            if (version.equals(StringPool.BLANK)) {
1809                                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_3);
1810                                            }
1811                                            else {
1812                                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_2);
1813                                            }
1814                                    }
1815    
1816                                    String sql = query.toString();
1817    
1818                                    Query q = session.createQuery(sql);
1819    
1820                                    QueryPos qPos = QueryPos.getInstance(q);
1821    
1822                                    qPos.add(groupId);
1823    
1824                                    qPos.add(folderId);
1825    
1826                                    if (name != null) {
1827                                            qPos.add(name);
1828                                    }
1829    
1830                                    if (version != null) {
1831                                            qPos.add(version);
1832                                    }
1833    
1834                                    count = (Long)q.uniqueResult();
1835                            }
1836                            catch (Exception e) {
1837                                    throw processException(e);
1838                            }
1839                            finally {
1840                                    if (count == null) {
1841                                            count = Long.valueOf(0);
1842                                    }
1843    
1844                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N_V,
1845                                            finderArgs, count);
1846    
1847                                    closeSession(session);
1848                            }
1849                    }
1850    
1851                    return count.intValue();
1852            }
1853    
1854            /**
1855             * Counts all the d l file versions where groupId = &#63; and folderId = &#63; and name = &#63; and status = &#63;.
1856             *
1857             * @param groupId the group id to search with
1858             * @param folderId the folder id to search with
1859             * @param name the name to search with
1860             * @param status the status to search with
1861             * @return the number of matching d l file versions
1862             * @throws SystemException if a system exception occurred
1863             */
1864            public int countByG_F_N_S(long groupId, long folderId, String name,
1865                    int status) throws SystemException {
1866                    Object[] finderArgs = new Object[] { groupId, folderId, name, status };
1867    
1868                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N_S,
1869                                    finderArgs, this);
1870    
1871                    if (count == null) {
1872                            Session session = null;
1873    
1874                            try {
1875                                    session = openSession();
1876    
1877                                    StringBundler query = new StringBundler(5);
1878    
1879                                    query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1880    
1881                                    query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1882    
1883                                    query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1884    
1885                                    if (name == null) {
1886                                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1887                                    }
1888                                    else {
1889                                            if (name.equals(StringPool.BLANK)) {
1890                                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1891                                            }
1892                                            else {
1893                                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1894                                            }
1895                                    }
1896    
1897                                    query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1898    
1899                                    String sql = query.toString();
1900    
1901                                    Query q = session.createQuery(sql);
1902    
1903                                    QueryPos qPos = QueryPos.getInstance(q);
1904    
1905                                    qPos.add(groupId);
1906    
1907                                    qPos.add(folderId);
1908    
1909                                    if (name != null) {
1910                                            qPos.add(name);
1911                                    }
1912    
1913                                    qPos.add(status);
1914    
1915                                    count = (Long)q.uniqueResult();
1916                            }
1917                            catch (Exception e) {
1918                                    throw processException(e);
1919                            }
1920                            finally {
1921                                    if (count == null) {
1922                                            count = Long.valueOf(0);
1923                                    }
1924    
1925                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N_S,
1926                                            finderArgs, count);
1927    
1928                                    closeSession(session);
1929                            }
1930                    }
1931    
1932                    return count.intValue();
1933            }
1934    
1935            /**
1936             * Counts all the d l file versions.
1937             *
1938             * @return the number of d l file versions
1939             * @throws SystemException if a system exception occurred
1940             */
1941            public int countAll() throws SystemException {
1942                    Object[] finderArgs = new Object[0];
1943    
1944                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1945                                    finderArgs, this);
1946    
1947                    if (count == null) {
1948                            Session session = null;
1949    
1950                            try {
1951                                    session = openSession();
1952    
1953                                    Query q = session.createQuery(_SQL_COUNT_DLFILEVERSION);
1954    
1955                                    count = (Long)q.uniqueResult();
1956                            }
1957                            catch (Exception e) {
1958                                    throw processException(e);
1959                            }
1960                            finally {
1961                                    if (count == null) {
1962                                            count = Long.valueOf(0);
1963                                    }
1964    
1965                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1966                                            count);
1967    
1968                                    closeSession(session);
1969                            }
1970                    }
1971    
1972                    return count.intValue();
1973            }
1974    
1975            /**
1976             * Initializes the d l file version persistence.
1977             */
1978            public void afterPropertiesSet() {
1979                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1980                                            com.liferay.portal.util.PropsUtil.get(
1981                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileVersion")));
1982    
1983                    if (listenerClassNames.length > 0) {
1984                            try {
1985                                    List<ModelListener<DLFileVersion>> listenersList = new ArrayList<ModelListener<DLFileVersion>>();
1986    
1987                                    for (String listenerClassName : listenerClassNames) {
1988                                            listenersList.add((ModelListener<DLFileVersion>)InstanceFactory.newInstance(
1989                                                            listenerClassName));
1990                                    }
1991    
1992                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1993                            }
1994                            catch (Exception e) {
1995                                    _log.error(e);
1996                            }
1997                    }
1998            }
1999    
2000            public void destroy() {
2001                    EntityCacheUtil.removeCache(DLFileVersionImpl.class.getName());
2002                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2003                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2004            }
2005    
2006            @BeanReference(type = DLFileEntryPersistence.class)
2007            protected DLFileEntryPersistence dlFileEntryPersistence;
2008            @BeanReference(type = DLFileRankPersistence.class)
2009            protected DLFileRankPersistence dlFileRankPersistence;
2010            @BeanReference(type = DLFileShortcutPersistence.class)
2011            protected DLFileShortcutPersistence dlFileShortcutPersistence;
2012            @BeanReference(type = DLFileVersionPersistence.class)
2013            protected DLFileVersionPersistence dlFileVersionPersistence;
2014            @BeanReference(type = DLFolderPersistence.class)
2015            protected DLFolderPersistence dlFolderPersistence;
2016            @BeanReference(type = ResourcePersistence.class)
2017            protected ResourcePersistence resourcePersistence;
2018            @BeanReference(type = UserPersistence.class)
2019            protected UserPersistence userPersistence;
2020            @BeanReference(type = AssetEntryPersistence.class)
2021            protected AssetEntryPersistence assetEntryPersistence;
2022            private static final String _SQL_SELECT_DLFILEVERSION = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion";
2023            private static final String _SQL_SELECT_DLFILEVERSION_WHERE = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ";
2024            private static final String _SQL_COUNT_DLFILEVERSION = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion";
2025            private static final String _SQL_COUNT_DLFILEVERSION_WHERE = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion WHERE ";
2026            private static final String _FINDER_COLUMN_G_F_N_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
2027            private static final String _FINDER_COLUMN_G_F_N_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
2028            private static final String _FINDER_COLUMN_G_F_N_NAME_1 = "dlFileVersion.name IS NULL";
2029            private static final String _FINDER_COLUMN_G_F_N_NAME_2 = "dlFileVersion.name = ?";
2030            private static final String _FINDER_COLUMN_G_F_N_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?)";
2031            private static final String _FINDER_COLUMN_G_F_N_V_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
2032            private static final String _FINDER_COLUMN_G_F_N_V_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
2033            private static final String _FINDER_COLUMN_G_F_N_V_NAME_1 = "dlFileVersion.name IS NULL AND ";
2034            private static final String _FINDER_COLUMN_G_F_N_V_NAME_2 = "dlFileVersion.name = ? AND ";
2035            private static final String _FINDER_COLUMN_G_F_N_V_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?) AND ";
2036            private static final String _FINDER_COLUMN_G_F_N_V_VERSION_1 = "dlFileVersion.version IS NULL";
2037            private static final String _FINDER_COLUMN_G_F_N_V_VERSION_2 = "dlFileVersion.version = ?";
2038            private static final String _FINDER_COLUMN_G_F_N_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = ?)";
2039            private static final String _FINDER_COLUMN_G_F_N_S_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
2040            private static final String _FINDER_COLUMN_G_F_N_S_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
2041            private static final String _FINDER_COLUMN_G_F_N_S_NAME_1 = "dlFileVersion.name IS NULL AND ";
2042            private static final String _FINDER_COLUMN_G_F_N_S_NAME_2 = "dlFileVersion.name = ? AND ";
2043            private static final String _FINDER_COLUMN_G_F_N_S_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?) AND ";
2044            private static final String _FINDER_COLUMN_G_F_N_S_STATUS_2 = "dlFileVersion.status = ?";
2045            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileVersion.";
2046            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileVersion exists with the primary key ";
2047            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileVersion exists with the key {";
2048            private static Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
2049    }