001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.documentlibrary.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.SetUtil;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.service.ServiceContext;
039    import com.liferay.portal.service.ServiceContextThreadLocal;
040    import com.liferay.portal.service.persistence.CompanyProvider;
041    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.documentlibrary.exception.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    import com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionPersistence;
049    
050    import java.io.Serializable;
051    
052    import java.util.Collections;
053    import java.util.Date;
054    import java.util.HashMap;
055    import java.util.HashSet;
056    import java.util.Iterator;
057    import java.util.List;
058    import java.util.Map;
059    import java.util.Set;
060    
061    /**
062     * The persistence implementation for the document library file version service.
063     *
064     * <p>
065     * Caching information and settings can be found in <code>portal.properties</code>
066     * </p>
067     *
068     * @author Brian Wing Shun Chan
069     * @see DLFileVersionPersistence
070     * @see com.liferay.portlet.documentlibrary.service.persistence.DLFileVersionUtil
071     * @generated
072     */
073    @ProviderType
074    public class DLFileVersionPersistenceImpl extends BasePersistenceImpl<DLFileVersion>
075            implements DLFileVersionPersistence {
076            /*
077             * NOTE FOR DEVELOPERS:
078             *
079             * Never modify or reference this class directly. Always use {@link DLFileVersionUtil} to access the document library file version persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
080             */
081            public static final String FINDER_CLASS_NAME_ENTITY = DLFileVersionImpl.class.getName();
082            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List1";
084            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085                    ".List2";
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
087                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
088                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
089                            "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
091                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
092                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
093                            "findAll", new String[0]);
094            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
095                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
097            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
098                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
099                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
100                            "findByUuid",
101                            new String[] {
102                                    String.class.getName(),
103                                    
104                            Integer.class.getName(), Integer.class.getName(),
105                                    OrderByComparator.class.getName()
106                            });
107            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
108                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
109                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
110                            "findByUuid", new String[] { String.class.getName() },
111                            DLFileVersionModelImpl.UUID_COLUMN_BITMASK |
112                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
113                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
115                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117                            new String[] { String.class.getName() });
118    
119            /**
120             * Returns all the document library file versions where uuid = &#63;.
121             *
122             * @param uuid the uuid
123             * @return the matching document library file versions
124             */
125            @Override
126            public List<DLFileVersion> findByUuid(String uuid) {
127                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
128            }
129    
130            /**
131             * Returns a range of all the document library file versions where uuid = &#63;.
132             *
133             * <p>
134             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
135             * </p>
136             *
137             * @param uuid the uuid
138             * @param start the lower bound of the range of document library file versions
139             * @param end the upper bound of the range of document library file versions (not inclusive)
140             * @return the range of matching document library file versions
141             */
142            @Override
143            public List<DLFileVersion> findByUuid(String uuid, int start, int end) {
144                    return findByUuid(uuid, start, end, null);
145            }
146    
147            /**
148             * Returns an ordered range of all the document library file versions where uuid = &#63;.
149             *
150             * <p>
151             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
152             * </p>
153             *
154             * @param uuid the uuid
155             * @param start the lower bound of the range of document library file versions
156             * @param end the upper bound of the range of document library file versions (not inclusive)
157             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
158             * @return the ordered range of matching document library file versions
159             */
160            @Override
161            public List<DLFileVersion> findByUuid(String uuid, int start, int end,
162                    OrderByComparator<DLFileVersion> orderByComparator) {
163                    return findByUuid(uuid, start, end, orderByComparator, true);
164            }
165    
166            /**
167             * Returns an ordered range of all the document library file versions where uuid = &#63;.
168             *
169             * <p>
170             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
171             * </p>
172             *
173             * @param uuid the uuid
174             * @param start the lower bound of the range of document library file versions
175             * @param end the upper bound of the range of document library file versions (not inclusive)
176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
177             * @param retrieveFromCache whether to retrieve from the finder cache
178             * @return the ordered range of matching document library file versions
179             */
180            @Override
181            public List<DLFileVersion> findByUuid(String uuid, int start, int end,
182                    OrderByComparator<DLFileVersion> orderByComparator,
183                    boolean retrieveFromCache) {
184                    boolean pagination = true;
185                    FinderPath finderPath = null;
186                    Object[] finderArgs = null;
187    
188                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
189                                    (orderByComparator == null)) {
190                            pagination = false;
191                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
192                            finderArgs = new Object[] { uuid };
193                    }
194                    else {
195                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
196                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
197                    }
198    
199                    List<DLFileVersion> list = null;
200    
201                    if (retrieveFromCache) {
202                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
203                                            finderArgs, this);
204    
205                            if ((list != null) && !list.isEmpty()) {
206                                    for (DLFileVersion dlFileVersion : list) {
207                                            if (!Validator.equals(uuid, dlFileVersion.getUuid())) {
208                                                    list = null;
209    
210                                                    break;
211                                            }
212                                    }
213                            }
214                    }
215    
216                    if (list == null) {
217                            StringBundler query = null;
218    
219                            if (orderByComparator != null) {
220                                    query = new StringBundler(3 +
221                                                    (orderByComparator.getOrderByFields().length * 3));
222                            }
223                            else {
224                                    query = new StringBundler(3);
225                            }
226    
227                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
228    
229                            boolean bindUuid = false;
230    
231                            if (uuid == null) {
232                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
233                            }
234                            else if (uuid.equals(StringPool.BLANK)) {
235                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
236                            }
237                            else {
238                                    bindUuid = true;
239    
240                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
241                            }
242    
243                            if (orderByComparator != null) {
244                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
245                                            orderByComparator);
246                            }
247                            else
248                             if (pagination) {
249                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
250                            }
251    
252                            String sql = query.toString();
253    
254                            Session session = null;
255    
256                            try {
257                                    session = openSession();
258    
259                                    Query q = session.createQuery(sql);
260    
261                                    QueryPos qPos = QueryPos.getInstance(q);
262    
263                                    if (bindUuid) {
264                                            qPos.add(uuid);
265                                    }
266    
267                                    if (!pagination) {
268                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
269                                                            start, end, false);
270    
271                                            Collections.sort(list);
272    
273                                            list = Collections.unmodifiableList(list);
274                                    }
275                                    else {
276                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
277                                                            start, end);
278                                    }
279    
280                                    cacheResult(list);
281    
282                                    finderCache.putResult(finderPath, finderArgs, list);
283                            }
284                            catch (Exception e) {
285                                    finderCache.removeResult(finderPath, finderArgs);
286    
287                                    throw processException(e);
288                            }
289                            finally {
290                                    closeSession(session);
291                            }
292                    }
293    
294                    return list;
295            }
296    
297            /**
298             * Returns the first document library file version in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching document library file version
303             * @throws NoSuchFileVersionException if a matching document library file version could not be found
304             */
305            @Override
306            public DLFileVersion findByUuid_First(String uuid,
307                    OrderByComparator<DLFileVersion> orderByComparator)
308                    throws NoSuchFileVersionException {
309                    DLFileVersion dlFileVersion = fetchByUuid_First(uuid, orderByComparator);
310    
311                    if (dlFileVersion != null) {
312                            return dlFileVersion;
313                    }
314    
315                    StringBundler msg = new StringBundler(4);
316    
317                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
318    
319                    msg.append("uuid=");
320                    msg.append(uuid);
321    
322                    msg.append(StringPool.CLOSE_CURLY_BRACE);
323    
324                    throw new NoSuchFileVersionException(msg.toString());
325            }
326    
327            /**
328             * Returns the first document library file version in the ordered set where uuid = &#63;.
329             *
330             * @param uuid the uuid
331             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
332             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
333             */
334            @Override
335            public DLFileVersion fetchByUuid_First(String uuid,
336                    OrderByComparator<DLFileVersion> orderByComparator) {
337                    List<DLFileVersion> list = findByUuid(uuid, 0, 1, orderByComparator);
338    
339                    if (!list.isEmpty()) {
340                            return list.get(0);
341                    }
342    
343                    return null;
344            }
345    
346            /**
347             * Returns the last document library file version in the ordered set where uuid = &#63;.
348             *
349             * @param uuid the uuid
350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
351             * @return the last matching document library file version
352             * @throws NoSuchFileVersionException if a matching document library file version could not be found
353             */
354            @Override
355            public DLFileVersion findByUuid_Last(String uuid,
356                    OrderByComparator<DLFileVersion> orderByComparator)
357                    throws NoSuchFileVersionException {
358                    DLFileVersion dlFileVersion = fetchByUuid_Last(uuid, orderByComparator);
359    
360                    if (dlFileVersion != null) {
361                            return dlFileVersion;
362                    }
363    
364                    StringBundler msg = new StringBundler(4);
365    
366                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
367    
368                    msg.append("uuid=");
369                    msg.append(uuid);
370    
371                    msg.append(StringPool.CLOSE_CURLY_BRACE);
372    
373                    throw new NoSuchFileVersionException(msg.toString());
374            }
375    
376            /**
377             * Returns the last document library file version in the ordered set where uuid = &#63;.
378             *
379             * @param uuid the uuid
380             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
381             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
382             */
383            @Override
384            public DLFileVersion fetchByUuid_Last(String uuid,
385                    OrderByComparator<DLFileVersion> orderByComparator) {
386                    int count = countByUuid(uuid);
387    
388                    if (count == 0) {
389                            return null;
390                    }
391    
392                    List<DLFileVersion> list = findByUuid(uuid, count - 1, count,
393                                    orderByComparator);
394    
395                    if (!list.isEmpty()) {
396                            return list.get(0);
397                    }
398    
399                    return null;
400            }
401    
402            /**
403             * Returns the document library file versions before and after the current document library file version in the ordered set where uuid = &#63;.
404             *
405             * @param fileVersionId the primary key of the current document library file version
406             * @param uuid the uuid
407             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
408             * @return the previous, current, and next document library file version
409             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
410             */
411            @Override
412            public DLFileVersion[] findByUuid_PrevAndNext(long fileVersionId,
413                    String uuid, OrderByComparator<DLFileVersion> orderByComparator)
414                    throws NoSuchFileVersionException {
415                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
416    
417                    Session session = null;
418    
419                    try {
420                            session = openSession();
421    
422                            DLFileVersion[] array = new DLFileVersionImpl[3];
423    
424                            array[0] = getByUuid_PrevAndNext(session, dlFileVersion, uuid,
425                                            orderByComparator, true);
426    
427                            array[1] = dlFileVersion;
428    
429                            array[2] = getByUuid_PrevAndNext(session, dlFileVersion, uuid,
430                                            orderByComparator, false);
431    
432                            return array;
433                    }
434                    catch (Exception e) {
435                            throw processException(e);
436                    }
437                    finally {
438                            closeSession(session);
439                    }
440            }
441    
442            protected DLFileVersion getByUuid_PrevAndNext(Session session,
443                    DLFileVersion dlFileVersion, String uuid,
444                    OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
445                    StringBundler query = null;
446    
447                    if (orderByComparator != null) {
448                            query = new StringBundler(6 +
449                                            (orderByComparator.getOrderByFields().length * 6));
450                    }
451                    else {
452                            query = new StringBundler(3);
453                    }
454    
455                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
456    
457                    boolean bindUuid = false;
458    
459                    if (uuid == null) {
460                            query.append(_FINDER_COLUMN_UUID_UUID_1);
461                    }
462                    else if (uuid.equals(StringPool.BLANK)) {
463                            query.append(_FINDER_COLUMN_UUID_UUID_3);
464                    }
465                    else {
466                            bindUuid = true;
467    
468                            query.append(_FINDER_COLUMN_UUID_UUID_2);
469                    }
470    
471                    if (orderByComparator != null) {
472                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
473    
474                            if (orderByConditionFields.length > 0) {
475                                    query.append(WHERE_AND);
476                            }
477    
478                            for (int i = 0; i < orderByConditionFields.length; i++) {
479                                    query.append(_ORDER_BY_ENTITY_ALIAS);
480                                    query.append(orderByConditionFields[i]);
481    
482                                    if ((i + 1) < orderByConditionFields.length) {
483                                            if (orderByComparator.isAscending() ^ previous) {
484                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
485                                            }
486                                            else {
487                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
488                                            }
489                                    }
490                                    else {
491                                            if (orderByComparator.isAscending() ^ previous) {
492                                                    query.append(WHERE_GREATER_THAN);
493                                            }
494                                            else {
495                                                    query.append(WHERE_LESSER_THAN);
496                                            }
497                                    }
498                            }
499    
500                            query.append(ORDER_BY_CLAUSE);
501    
502                            String[] orderByFields = orderByComparator.getOrderByFields();
503    
504                            for (int i = 0; i < orderByFields.length; i++) {
505                                    query.append(_ORDER_BY_ENTITY_ALIAS);
506                                    query.append(orderByFields[i]);
507    
508                                    if ((i + 1) < orderByFields.length) {
509                                            if (orderByComparator.isAscending() ^ previous) {
510                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
511                                            }
512                                            else {
513                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
514                                            }
515                                    }
516                                    else {
517                                            if (orderByComparator.isAscending() ^ previous) {
518                                                    query.append(ORDER_BY_ASC);
519                                            }
520                                            else {
521                                                    query.append(ORDER_BY_DESC);
522                                            }
523                                    }
524                            }
525                    }
526                    else {
527                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
528                    }
529    
530                    String sql = query.toString();
531    
532                    Query q = session.createQuery(sql);
533    
534                    q.setFirstResult(0);
535                    q.setMaxResults(2);
536    
537                    QueryPos qPos = QueryPos.getInstance(q);
538    
539                    if (bindUuid) {
540                            qPos.add(uuid);
541                    }
542    
543                    if (orderByComparator != null) {
544                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
545    
546                            for (Object value : values) {
547                                    qPos.add(value);
548                            }
549                    }
550    
551                    List<DLFileVersion> list = q.list();
552    
553                    if (list.size() == 2) {
554                            return list.get(1);
555                    }
556                    else {
557                            return null;
558                    }
559            }
560    
561            /**
562             * Removes all the document library file versions where uuid = &#63; from the database.
563             *
564             * @param uuid the uuid
565             */
566            @Override
567            public void removeByUuid(String uuid) {
568                    for (DLFileVersion dlFileVersion : findByUuid(uuid, QueryUtil.ALL_POS,
569                                    QueryUtil.ALL_POS, null)) {
570                            remove(dlFileVersion);
571                    }
572            }
573    
574            /**
575             * Returns the number of document library file versions where uuid = &#63;.
576             *
577             * @param uuid the uuid
578             * @return the number of matching document library file versions
579             */
580            @Override
581            public int countByUuid(String uuid) {
582                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
583    
584                    Object[] finderArgs = new Object[] { uuid };
585    
586                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
587    
588                    if (count == null) {
589                            StringBundler query = new StringBundler(2);
590    
591                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
592    
593                            boolean bindUuid = false;
594    
595                            if (uuid == null) {
596                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
597                            }
598                            else if (uuid.equals(StringPool.BLANK)) {
599                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
600                            }
601                            else {
602                                    bindUuid = true;
603    
604                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
605                            }
606    
607                            String sql = query.toString();
608    
609                            Session session = null;
610    
611                            try {
612                                    session = openSession();
613    
614                                    Query q = session.createQuery(sql);
615    
616                                    QueryPos qPos = QueryPos.getInstance(q);
617    
618                                    if (bindUuid) {
619                                            qPos.add(uuid);
620                                    }
621    
622                                    count = (Long)q.uniqueResult();
623    
624                                    finderCache.putResult(finderPath, finderArgs, count);
625                            }
626                            catch (Exception e) {
627                                    finderCache.removeResult(finderPath, finderArgs);
628    
629                                    throw processException(e);
630                            }
631                            finally {
632                                    closeSession(session);
633                            }
634                    }
635    
636                    return count.intValue();
637            }
638    
639            private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFileVersion.uuid IS NULL";
640            private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFileVersion.uuid = ?";
641            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFileVersion.uuid IS NULL OR dlFileVersion.uuid = '')";
642            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
643                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
644                            DLFileVersionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
645                            new String[] { String.class.getName(), Long.class.getName() },
646                            DLFileVersionModelImpl.UUID_COLUMN_BITMASK |
647                            DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK);
648            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
649                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
650                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
651                            new String[] { String.class.getName(), Long.class.getName() });
652    
653            /**
654             * Returns the document library file version where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchFileVersionException} if it could not be found.
655             *
656             * @param uuid the uuid
657             * @param groupId the group ID
658             * @return the matching document library file version
659             * @throws NoSuchFileVersionException if a matching document library file version could not be found
660             */
661            @Override
662            public DLFileVersion findByUUID_G(String uuid, long groupId)
663                    throws NoSuchFileVersionException {
664                    DLFileVersion dlFileVersion = fetchByUUID_G(uuid, groupId);
665    
666                    if (dlFileVersion == null) {
667                            StringBundler msg = new StringBundler(6);
668    
669                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
670    
671                            msg.append("uuid=");
672                            msg.append(uuid);
673    
674                            msg.append(", groupId=");
675                            msg.append(groupId);
676    
677                            msg.append(StringPool.CLOSE_CURLY_BRACE);
678    
679                            if (_log.isWarnEnabled()) {
680                                    _log.warn(msg.toString());
681                            }
682    
683                            throw new NoSuchFileVersionException(msg.toString());
684                    }
685    
686                    return dlFileVersion;
687            }
688    
689            /**
690             * Returns the document library file version where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
691             *
692             * @param uuid the uuid
693             * @param groupId the group ID
694             * @return the matching document library file version, or <code>null</code> if a matching document library file version could not be found
695             */
696            @Override
697            public DLFileVersion fetchByUUID_G(String uuid, long groupId) {
698                    return fetchByUUID_G(uuid, groupId, true);
699            }
700    
701            /**
702             * Returns the document library file version where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
703             *
704             * @param uuid the uuid
705             * @param groupId the group ID
706             * @param retrieveFromCache whether to retrieve from the finder cache
707             * @return the matching document library file version, or <code>null</code> if a matching document library file version could not be found
708             */
709            @Override
710            public DLFileVersion fetchByUUID_G(String uuid, long groupId,
711                    boolean retrieveFromCache) {
712                    Object[] finderArgs = new Object[] { uuid, groupId };
713    
714                    Object result = null;
715    
716                    if (retrieveFromCache) {
717                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
718                                            finderArgs, this);
719                    }
720    
721                    if (result instanceof DLFileVersion) {
722                            DLFileVersion dlFileVersion = (DLFileVersion)result;
723    
724                            if (!Validator.equals(uuid, dlFileVersion.getUuid()) ||
725                                            (groupId != dlFileVersion.getGroupId())) {
726                                    result = null;
727                            }
728                    }
729    
730                    if (result == null) {
731                            StringBundler query = new StringBundler(4);
732    
733                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
734    
735                            boolean bindUuid = false;
736    
737                            if (uuid == null) {
738                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
739                            }
740                            else if (uuid.equals(StringPool.BLANK)) {
741                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
742                            }
743                            else {
744                                    bindUuid = true;
745    
746                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
747                            }
748    
749                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
750    
751                            String sql = query.toString();
752    
753                            Session session = null;
754    
755                            try {
756                                    session = openSession();
757    
758                                    Query q = session.createQuery(sql);
759    
760                                    QueryPos qPos = QueryPos.getInstance(q);
761    
762                                    if (bindUuid) {
763                                            qPos.add(uuid);
764                                    }
765    
766                                    qPos.add(groupId);
767    
768                                    List<DLFileVersion> list = q.list();
769    
770                                    if (list.isEmpty()) {
771                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
772                                                    finderArgs, list);
773                                    }
774                                    else {
775                                            DLFileVersion dlFileVersion = list.get(0);
776    
777                                            result = dlFileVersion;
778    
779                                            cacheResult(dlFileVersion);
780    
781                                            if ((dlFileVersion.getUuid() == null) ||
782                                                            !dlFileVersion.getUuid().equals(uuid) ||
783                                                            (dlFileVersion.getGroupId() != groupId)) {
784                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
785                                                            finderArgs, dlFileVersion);
786                                            }
787                                    }
788                            }
789                            catch (Exception e) {
790                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
791    
792                                    throw processException(e);
793                            }
794                            finally {
795                                    closeSession(session);
796                            }
797                    }
798    
799                    if (result instanceof List<?>) {
800                            return null;
801                    }
802                    else {
803                            return (DLFileVersion)result;
804                    }
805            }
806    
807            /**
808             * Removes the document library file version where uuid = &#63; and groupId = &#63; from the database.
809             *
810             * @param uuid the uuid
811             * @param groupId the group ID
812             * @return the document library file version that was removed
813             */
814            @Override
815            public DLFileVersion removeByUUID_G(String uuid, long groupId)
816                    throws NoSuchFileVersionException {
817                    DLFileVersion dlFileVersion = findByUUID_G(uuid, groupId);
818    
819                    return remove(dlFileVersion);
820            }
821    
822            /**
823             * Returns the number of document library file versions where uuid = &#63; and groupId = &#63;.
824             *
825             * @param uuid the uuid
826             * @param groupId the group ID
827             * @return the number of matching document library file versions
828             */
829            @Override
830            public int countByUUID_G(String uuid, long groupId) {
831                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
832    
833                    Object[] finderArgs = new Object[] { uuid, groupId };
834    
835                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
836    
837                    if (count == null) {
838                            StringBundler query = new StringBundler(3);
839    
840                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
841    
842                            boolean bindUuid = false;
843    
844                            if (uuid == null) {
845                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
846                            }
847                            else if (uuid.equals(StringPool.BLANK)) {
848                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
849                            }
850                            else {
851                                    bindUuid = true;
852    
853                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
854                            }
855    
856                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
857    
858                            String sql = query.toString();
859    
860                            Session session = null;
861    
862                            try {
863                                    session = openSession();
864    
865                                    Query q = session.createQuery(sql);
866    
867                                    QueryPos qPos = QueryPos.getInstance(q);
868    
869                                    if (bindUuid) {
870                                            qPos.add(uuid);
871                                    }
872    
873                                    qPos.add(groupId);
874    
875                                    count = (Long)q.uniqueResult();
876    
877                                    finderCache.putResult(finderPath, finderArgs, count);
878                            }
879                            catch (Exception e) {
880                                    finderCache.removeResult(finderPath, finderArgs);
881    
882                                    throw processException(e);
883                            }
884                            finally {
885                                    closeSession(session);
886                            }
887                    }
888    
889                    return count.intValue();
890            }
891    
892            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "dlFileVersion.uuid IS NULL AND ";
893            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "dlFileVersion.uuid = ? AND ";
894            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(dlFileVersion.uuid IS NULL OR dlFileVersion.uuid = '') AND ";
895            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "dlFileVersion.groupId = ?";
896            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
897                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
898                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
899                            "findByUuid_C",
900                            new String[] {
901                                    String.class.getName(), Long.class.getName(),
902                                    
903                            Integer.class.getName(), Integer.class.getName(),
904                                    OrderByComparator.class.getName()
905                            });
906            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
907                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
908                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
909                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
910                            "findByUuid_C",
911                            new String[] { String.class.getName(), Long.class.getName() },
912                            DLFileVersionModelImpl.UUID_COLUMN_BITMASK |
913                            DLFileVersionModelImpl.COMPANYID_COLUMN_BITMASK |
914                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
915                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
916            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
917                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
918                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
919                            new String[] { String.class.getName(), Long.class.getName() });
920    
921            /**
922             * Returns all the document library file versions where uuid = &#63; and companyId = &#63;.
923             *
924             * @param uuid the uuid
925             * @param companyId the company ID
926             * @return the matching document library file versions
927             */
928            @Override
929            public List<DLFileVersion> findByUuid_C(String uuid, long companyId) {
930                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
931                            QueryUtil.ALL_POS, null);
932            }
933    
934            /**
935             * Returns a range of all the document library file versions where uuid = &#63; and companyId = &#63;.
936             *
937             * <p>
938             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
939             * </p>
940             *
941             * @param uuid the uuid
942             * @param companyId the company ID
943             * @param start the lower bound of the range of document library file versions
944             * @param end the upper bound of the range of document library file versions (not inclusive)
945             * @return the range of matching document library file versions
946             */
947            @Override
948            public List<DLFileVersion> findByUuid_C(String uuid, long companyId,
949                    int start, int end) {
950                    return findByUuid_C(uuid, companyId, start, end, null);
951            }
952    
953            /**
954             * Returns an ordered range of all the document library file versions where uuid = &#63; and companyId = &#63;.
955             *
956             * <p>
957             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
958             * </p>
959             *
960             * @param uuid the uuid
961             * @param companyId the company ID
962             * @param start the lower bound of the range of document library file versions
963             * @param end the upper bound of the range of document library file versions (not inclusive)
964             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
965             * @return the ordered range of matching document library file versions
966             */
967            @Override
968            public List<DLFileVersion> findByUuid_C(String uuid, long companyId,
969                    int start, int end, OrderByComparator<DLFileVersion> orderByComparator) {
970                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
971            }
972    
973            /**
974             * Returns an ordered range of all the document library file versions where uuid = &#63; and companyId = &#63;.
975             *
976             * <p>
977             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
978             * </p>
979             *
980             * @param uuid the uuid
981             * @param companyId the company ID
982             * @param start the lower bound of the range of document library file versions
983             * @param end the upper bound of the range of document library file versions (not inclusive)
984             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
985             * @param retrieveFromCache whether to retrieve from the finder cache
986             * @return the ordered range of matching document library file versions
987             */
988            @Override
989            public List<DLFileVersion> findByUuid_C(String uuid, long companyId,
990                    int start, int end, OrderByComparator<DLFileVersion> orderByComparator,
991                    boolean retrieveFromCache) {
992                    boolean pagination = true;
993                    FinderPath finderPath = null;
994                    Object[] finderArgs = null;
995    
996                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
997                                    (orderByComparator == null)) {
998                            pagination = false;
999                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1000                            finderArgs = new Object[] { uuid, companyId };
1001                    }
1002                    else {
1003                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1004                            finderArgs = new Object[] {
1005                                            uuid, companyId,
1006                                            
1007                                            start, end, orderByComparator
1008                                    };
1009                    }
1010    
1011                    List<DLFileVersion> list = null;
1012    
1013                    if (retrieveFromCache) {
1014                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
1015                                            finderArgs, this);
1016    
1017                            if ((list != null) && !list.isEmpty()) {
1018                                    for (DLFileVersion dlFileVersion : list) {
1019                                            if (!Validator.equals(uuid, dlFileVersion.getUuid()) ||
1020                                                            (companyId != dlFileVersion.getCompanyId())) {
1021                                                    list = null;
1022    
1023                                                    break;
1024                                            }
1025                                    }
1026                            }
1027                    }
1028    
1029                    if (list == null) {
1030                            StringBundler query = null;
1031    
1032                            if (orderByComparator != null) {
1033                                    query = new StringBundler(4 +
1034                                                    (orderByComparator.getOrderByFields().length * 3));
1035                            }
1036                            else {
1037                                    query = new StringBundler(4);
1038                            }
1039    
1040                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1041    
1042                            boolean bindUuid = false;
1043    
1044                            if (uuid == null) {
1045                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1046                            }
1047                            else if (uuid.equals(StringPool.BLANK)) {
1048                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1049                            }
1050                            else {
1051                                    bindUuid = true;
1052    
1053                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1054                            }
1055    
1056                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1057    
1058                            if (orderByComparator != null) {
1059                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1060                                            orderByComparator);
1061                            }
1062                            else
1063                             if (pagination) {
1064                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1065                            }
1066    
1067                            String sql = query.toString();
1068    
1069                            Session session = null;
1070    
1071                            try {
1072                                    session = openSession();
1073    
1074                                    Query q = session.createQuery(sql);
1075    
1076                                    QueryPos qPos = QueryPos.getInstance(q);
1077    
1078                                    if (bindUuid) {
1079                                            qPos.add(uuid);
1080                                    }
1081    
1082                                    qPos.add(companyId);
1083    
1084                                    if (!pagination) {
1085                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1086                                                            start, end, false);
1087    
1088                                            Collections.sort(list);
1089    
1090                                            list = Collections.unmodifiableList(list);
1091                                    }
1092                                    else {
1093                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1094                                                            start, end);
1095                                    }
1096    
1097                                    cacheResult(list);
1098    
1099                                    finderCache.putResult(finderPath, finderArgs, list);
1100                            }
1101                            catch (Exception e) {
1102                                    finderCache.removeResult(finderPath, finderArgs);
1103    
1104                                    throw processException(e);
1105                            }
1106                            finally {
1107                                    closeSession(session);
1108                            }
1109                    }
1110    
1111                    return list;
1112            }
1113    
1114            /**
1115             * Returns the first document library file version in the ordered set where uuid = &#63; and companyId = &#63;.
1116             *
1117             * @param uuid the uuid
1118             * @param companyId the company ID
1119             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1120             * @return the first matching document library file version
1121             * @throws NoSuchFileVersionException if a matching document library file version could not be found
1122             */
1123            @Override
1124            public DLFileVersion findByUuid_C_First(String uuid, long companyId,
1125                    OrderByComparator<DLFileVersion> orderByComparator)
1126                    throws NoSuchFileVersionException {
1127                    DLFileVersion dlFileVersion = fetchByUuid_C_First(uuid, companyId,
1128                                    orderByComparator);
1129    
1130                    if (dlFileVersion != null) {
1131                            return dlFileVersion;
1132                    }
1133    
1134                    StringBundler msg = new StringBundler(6);
1135    
1136                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1137    
1138                    msg.append("uuid=");
1139                    msg.append(uuid);
1140    
1141                    msg.append(", companyId=");
1142                    msg.append(companyId);
1143    
1144                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1145    
1146                    throw new NoSuchFileVersionException(msg.toString());
1147            }
1148    
1149            /**
1150             * Returns the first document library file version in the ordered set where uuid = &#63; and companyId = &#63;.
1151             *
1152             * @param uuid the uuid
1153             * @param companyId the company ID
1154             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1155             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
1156             */
1157            @Override
1158            public DLFileVersion fetchByUuid_C_First(String uuid, long companyId,
1159                    OrderByComparator<DLFileVersion> orderByComparator) {
1160                    List<DLFileVersion> list = findByUuid_C(uuid, companyId, 0, 1,
1161                                    orderByComparator);
1162    
1163                    if (!list.isEmpty()) {
1164                            return list.get(0);
1165                    }
1166    
1167                    return null;
1168            }
1169    
1170            /**
1171             * Returns the last document library file version in the ordered set where uuid = &#63; and companyId = &#63;.
1172             *
1173             * @param uuid the uuid
1174             * @param companyId the company ID
1175             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1176             * @return the last matching document library file version
1177             * @throws NoSuchFileVersionException if a matching document library file version could not be found
1178             */
1179            @Override
1180            public DLFileVersion findByUuid_C_Last(String uuid, long companyId,
1181                    OrderByComparator<DLFileVersion> orderByComparator)
1182                    throws NoSuchFileVersionException {
1183                    DLFileVersion dlFileVersion = fetchByUuid_C_Last(uuid, companyId,
1184                                    orderByComparator);
1185    
1186                    if (dlFileVersion != null) {
1187                            return dlFileVersion;
1188                    }
1189    
1190                    StringBundler msg = new StringBundler(6);
1191    
1192                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1193    
1194                    msg.append("uuid=");
1195                    msg.append(uuid);
1196    
1197                    msg.append(", companyId=");
1198                    msg.append(companyId);
1199    
1200                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1201    
1202                    throw new NoSuchFileVersionException(msg.toString());
1203            }
1204    
1205            /**
1206             * Returns the last document library file version in the ordered set where uuid = &#63; and companyId = &#63;.
1207             *
1208             * @param uuid the uuid
1209             * @param companyId the company ID
1210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1211             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
1212             */
1213            @Override
1214            public DLFileVersion fetchByUuid_C_Last(String uuid, long companyId,
1215                    OrderByComparator<DLFileVersion> orderByComparator) {
1216                    int count = countByUuid_C(uuid, companyId);
1217    
1218                    if (count == 0) {
1219                            return null;
1220                    }
1221    
1222                    List<DLFileVersion> list = findByUuid_C(uuid, companyId, count - 1,
1223                                    count, orderByComparator);
1224    
1225                    if (!list.isEmpty()) {
1226                            return list.get(0);
1227                    }
1228    
1229                    return null;
1230            }
1231    
1232            /**
1233             * Returns the document library file versions before and after the current document library file version in the ordered set where uuid = &#63; and companyId = &#63;.
1234             *
1235             * @param fileVersionId the primary key of the current document library file version
1236             * @param uuid the uuid
1237             * @param companyId the company ID
1238             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1239             * @return the previous, current, and next document library file version
1240             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
1241             */
1242            @Override
1243            public DLFileVersion[] findByUuid_C_PrevAndNext(long fileVersionId,
1244                    String uuid, long companyId,
1245                    OrderByComparator<DLFileVersion> orderByComparator)
1246                    throws NoSuchFileVersionException {
1247                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1248    
1249                    Session session = null;
1250    
1251                    try {
1252                            session = openSession();
1253    
1254                            DLFileVersion[] array = new DLFileVersionImpl[3];
1255    
1256                            array[0] = getByUuid_C_PrevAndNext(session, dlFileVersion, uuid,
1257                                            companyId, orderByComparator, true);
1258    
1259                            array[1] = dlFileVersion;
1260    
1261                            array[2] = getByUuid_C_PrevAndNext(session, dlFileVersion, uuid,
1262                                            companyId, orderByComparator, false);
1263    
1264                            return array;
1265                    }
1266                    catch (Exception e) {
1267                            throw processException(e);
1268                    }
1269                    finally {
1270                            closeSession(session);
1271                    }
1272            }
1273    
1274            protected DLFileVersion getByUuid_C_PrevAndNext(Session session,
1275                    DLFileVersion dlFileVersion, String uuid, long companyId,
1276                    OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
1277                    StringBundler query = null;
1278    
1279                    if (orderByComparator != null) {
1280                            query = new StringBundler(6 +
1281                                            (orderByComparator.getOrderByFields().length * 6));
1282                    }
1283                    else {
1284                            query = new StringBundler(3);
1285                    }
1286    
1287                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1288    
1289                    boolean bindUuid = false;
1290    
1291                    if (uuid == null) {
1292                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1293                    }
1294                    else if (uuid.equals(StringPool.BLANK)) {
1295                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1296                    }
1297                    else {
1298                            bindUuid = true;
1299    
1300                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1301                    }
1302    
1303                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1304    
1305                    if (orderByComparator != null) {
1306                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1307    
1308                            if (orderByConditionFields.length > 0) {
1309                                    query.append(WHERE_AND);
1310                            }
1311    
1312                            for (int i = 0; i < orderByConditionFields.length; i++) {
1313                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1314                                    query.append(orderByConditionFields[i]);
1315    
1316                                    if ((i + 1) < orderByConditionFields.length) {
1317                                            if (orderByComparator.isAscending() ^ previous) {
1318                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1319                                            }
1320                                            else {
1321                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1322                                            }
1323                                    }
1324                                    else {
1325                                            if (orderByComparator.isAscending() ^ previous) {
1326                                                    query.append(WHERE_GREATER_THAN);
1327                                            }
1328                                            else {
1329                                                    query.append(WHERE_LESSER_THAN);
1330                                            }
1331                                    }
1332                            }
1333    
1334                            query.append(ORDER_BY_CLAUSE);
1335    
1336                            String[] orderByFields = orderByComparator.getOrderByFields();
1337    
1338                            for (int i = 0; i < orderByFields.length; i++) {
1339                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1340                                    query.append(orderByFields[i]);
1341    
1342                                    if ((i + 1) < orderByFields.length) {
1343                                            if (orderByComparator.isAscending() ^ previous) {
1344                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1345                                            }
1346                                            else {
1347                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1348                                            }
1349                                    }
1350                                    else {
1351                                            if (orderByComparator.isAscending() ^ previous) {
1352                                                    query.append(ORDER_BY_ASC);
1353                                            }
1354                                            else {
1355                                                    query.append(ORDER_BY_DESC);
1356                                            }
1357                                    }
1358                            }
1359                    }
1360                    else {
1361                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1362                    }
1363    
1364                    String sql = query.toString();
1365    
1366                    Query q = session.createQuery(sql);
1367    
1368                    q.setFirstResult(0);
1369                    q.setMaxResults(2);
1370    
1371                    QueryPos qPos = QueryPos.getInstance(q);
1372    
1373                    if (bindUuid) {
1374                            qPos.add(uuid);
1375                    }
1376    
1377                    qPos.add(companyId);
1378    
1379                    if (orderByComparator != null) {
1380                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
1381    
1382                            for (Object value : values) {
1383                                    qPos.add(value);
1384                            }
1385                    }
1386    
1387                    List<DLFileVersion> list = q.list();
1388    
1389                    if (list.size() == 2) {
1390                            return list.get(1);
1391                    }
1392                    else {
1393                            return null;
1394                    }
1395            }
1396    
1397            /**
1398             * Removes all the document library file versions where uuid = &#63; and companyId = &#63; from the database.
1399             *
1400             * @param uuid the uuid
1401             * @param companyId the company ID
1402             */
1403            @Override
1404            public void removeByUuid_C(String uuid, long companyId) {
1405                    for (DLFileVersion dlFileVersion : findByUuid_C(uuid, companyId,
1406                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1407                            remove(dlFileVersion);
1408                    }
1409            }
1410    
1411            /**
1412             * Returns the number of document library file versions where uuid = &#63; and companyId = &#63;.
1413             *
1414             * @param uuid the uuid
1415             * @param companyId the company ID
1416             * @return the number of matching document library file versions
1417             */
1418            @Override
1419            public int countByUuid_C(String uuid, long companyId) {
1420                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1421    
1422                    Object[] finderArgs = new Object[] { uuid, companyId };
1423    
1424                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1425    
1426                    if (count == null) {
1427                            StringBundler query = new StringBundler(3);
1428    
1429                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1430    
1431                            boolean bindUuid = false;
1432    
1433                            if (uuid == null) {
1434                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1435                            }
1436                            else if (uuid.equals(StringPool.BLANK)) {
1437                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1438                            }
1439                            else {
1440                                    bindUuid = true;
1441    
1442                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1443                            }
1444    
1445                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1446    
1447                            String sql = query.toString();
1448    
1449                            Session session = null;
1450    
1451                            try {
1452                                    session = openSession();
1453    
1454                                    Query q = session.createQuery(sql);
1455    
1456                                    QueryPos qPos = QueryPos.getInstance(q);
1457    
1458                                    if (bindUuid) {
1459                                            qPos.add(uuid);
1460                                    }
1461    
1462                                    qPos.add(companyId);
1463    
1464                                    count = (Long)q.uniqueResult();
1465    
1466                                    finderCache.putResult(finderPath, finderArgs, count);
1467                            }
1468                            catch (Exception e) {
1469                                    finderCache.removeResult(finderPath, finderArgs);
1470    
1471                                    throw processException(e);
1472                            }
1473                            finally {
1474                                    closeSession(session);
1475                            }
1476                    }
1477    
1478                    return count.intValue();
1479            }
1480    
1481            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "dlFileVersion.uuid IS NULL AND ";
1482            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "dlFileVersion.uuid = ? AND ";
1483            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(dlFileVersion.uuid IS NULL OR dlFileVersion.uuid = '') AND ";
1484            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "dlFileVersion.companyId = ?";
1485            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1486                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1487                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1488                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1489                            "findByCompanyId",
1490                            new String[] {
1491                                    Long.class.getName(),
1492                                    
1493                            Integer.class.getName(), Integer.class.getName(),
1494                                    OrderByComparator.class.getName()
1495                            });
1496            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1497                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1498                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1499                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1500                            "findByCompanyId", new String[] { Long.class.getName() },
1501                            DLFileVersionModelImpl.COMPANYID_COLUMN_BITMASK |
1502                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
1503                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
1504            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1505                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1506                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1507                            new String[] { Long.class.getName() });
1508    
1509            /**
1510             * Returns all the document library file versions where companyId = &#63;.
1511             *
1512             * @param companyId the company ID
1513             * @return the matching document library file versions
1514             */
1515            @Override
1516            public List<DLFileVersion> findByCompanyId(long companyId) {
1517                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1518                            null);
1519            }
1520    
1521            /**
1522             * Returns a range of all the document library file versions where companyId = &#63;.
1523             *
1524             * <p>
1525             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1526             * </p>
1527             *
1528             * @param companyId the company ID
1529             * @param start the lower bound of the range of document library file versions
1530             * @param end the upper bound of the range of document library file versions (not inclusive)
1531             * @return the range of matching document library file versions
1532             */
1533            @Override
1534            public List<DLFileVersion> findByCompanyId(long companyId, int start,
1535                    int end) {
1536                    return findByCompanyId(companyId, start, end, null);
1537            }
1538    
1539            /**
1540             * Returns an ordered range of all the document library file versions where companyId = &#63;.
1541             *
1542             * <p>
1543             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1544             * </p>
1545             *
1546             * @param companyId the company ID
1547             * @param start the lower bound of the range of document library file versions
1548             * @param end the upper bound of the range of document library file versions (not inclusive)
1549             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1550             * @return the ordered range of matching document library file versions
1551             */
1552            @Override
1553            public List<DLFileVersion> findByCompanyId(long companyId, int start,
1554                    int end, OrderByComparator<DLFileVersion> orderByComparator) {
1555                    return findByCompanyId(companyId, start, end, orderByComparator, true);
1556            }
1557    
1558            /**
1559             * Returns an ordered range of all the document library file versions where companyId = &#63;.
1560             *
1561             * <p>
1562             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1563             * </p>
1564             *
1565             * @param companyId the company ID
1566             * @param start the lower bound of the range of document library file versions
1567             * @param end the upper bound of the range of document library file versions (not inclusive)
1568             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1569             * @param retrieveFromCache whether to retrieve from the finder cache
1570             * @return the ordered range of matching document library file versions
1571             */
1572            @Override
1573            public List<DLFileVersion> findByCompanyId(long companyId, int start,
1574                    int end, OrderByComparator<DLFileVersion> orderByComparator,
1575                    boolean retrieveFromCache) {
1576                    boolean pagination = true;
1577                    FinderPath finderPath = null;
1578                    Object[] finderArgs = null;
1579    
1580                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1581                                    (orderByComparator == null)) {
1582                            pagination = false;
1583                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1584                            finderArgs = new Object[] { companyId };
1585                    }
1586                    else {
1587                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1588                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1589                    }
1590    
1591                    List<DLFileVersion> list = null;
1592    
1593                    if (retrieveFromCache) {
1594                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
1595                                            finderArgs, this);
1596    
1597                            if ((list != null) && !list.isEmpty()) {
1598                                    for (DLFileVersion dlFileVersion : list) {
1599                                            if ((companyId != dlFileVersion.getCompanyId())) {
1600                                                    list = null;
1601    
1602                                                    break;
1603                                            }
1604                                    }
1605                            }
1606                    }
1607    
1608                    if (list == null) {
1609                            StringBundler query = null;
1610    
1611                            if (orderByComparator != null) {
1612                                    query = new StringBundler(3 +
1613                                                    (orderByComparator.getOrderByFields().length * 3));
1614                            }
1615                            else {
1616                                    query = new StringBundler(3);
1617                            }
1618    
1619                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1620    
1621                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1622    
1623                            if (orderByComparator != null) {
1624                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1625                                            orderByComparator);
1626                            }
1627                            else
1628                             if (pagination) {
1629                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1630                            }
1631    
1632                            String sql = query.toString();
1633    
1634                            Session session = null;
1635    
1636                            try {
1637                                    session = openSession();
1638    
1639                                    Query q = session.createQuery(sql);
1640    
1641                                    QueryPos qPos = QueryPos.getInstance(q);
1642    
1643                                    qPos.add(companyId);
1644    
1645                                    if (!pagination) {
1646                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1647                                                            start, end, false);
1648    
1649                                            Collections.sort(list);
1650    
1651                                            list = Collections.unmodifiableList(list);
1652                                    }
1653                                    else {
1654                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1655                                                            start, end);
1656                                    }
1657    
1658                                    cacheResult(list);
1659    
1660                                    finderCache.putResult(finderPath, finderArgs, list);
1661                            }
1662                            catch (Exception e) {
1663                                    finderCache.removeResult(finderPath, finderArgs);
1664    
1665                                    throw processException(e);
1666                            }
1667                            finally {
1668                                    closeSession(session);
1669                            }
1670                    }
1671    
1672                    return list;
1673            }
1674    
1675            /**
1676             * Returns the first document library file version in the ordered set where companyId = &#63;.
1677             *
1678             * @param companyId the company ID
1679             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1680             * @return the first matching document library file version
1681             * @throws NoSuchFileVersionException if a matching document library file version could not be found
1682             */
1683            @Override
1684            public DLFileVersion findByCompanyId_First(long companyId,
1685                    OrderByComparator<DLFileVersion> orderByComparator)
1686                    throws NoSuchFileVersionException {
1687                    DLFileVersion dlFileVersion = fetchByCompanyId_First(companyId,
1688                                    orderByComparator);
1689    
1690                    if (dlFileVersion != null) {
1691                            return dlFileVersion;
1692                    }
1693    
1694                    StringBundler msg = new StringBundler(4);
1695    
1696                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1697    
1698                    msg.append("companyId=");
1699                    msg.append(companyId);
1700    
1701                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1702    
1703                    throw new NoSuchFileVersionException(msg.toString());
1704            }
1705    
1706            /**
1707             * Returns the first document library file version in the ordered set where companyId = &#63;.
1708             *
1709             * @param companyId the company ID
1710             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1711             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
1712             */
1713            @Override
1714            public DLFileVersion fetchByCompanyId_First(long companyId,
1715                    OrderByComparator<DLFileVersion> orderByComparator) {
1716                    List<DLFileVersion> list = findByCompanyId(companyId, 0, 1,
1717                                    orderByComparator);
1718    
1719                    if (!list.isEmpty()) {
1720                            return list.get(0);
1721                    }
1722    
1723                    return null;
1724            }
1725    
1726            /**
1727             * Returns the last document library file version in the ordered set where companyId = &#63;.
1728             *
1729             * @param companyId the company ID
1730             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1731             * @return the last matching document library file version
1732             * @throws NoSuchFileVersionException if a matching document library file version could not be found
1733             */
1734            @Override
1735            public DLFileVersion findByCompanyId_Last(long companyId,
1736                    OrderByComparator<DLFileVersion> orderByComparator)
1737                    throws NoSuchFileVersionException {
1738                    DLFileVersion dlFileVersion = fetchByCompanyId_Last(companyId,
1739                                    orderByComparator);
1740    
1741                    if (dlFileVersion != null) {
1742                            return dlFileVersion;
1743                    }
1744    
1745                    StringBundler msg = new StringBundler(4);
1746    
1747                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1748    
1749                    msg.append("companyId=");
1750                    msg.append(companyId);
1751    
1752                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1753    
1754                    throw new NoSuchFileVersionException(msg.toString());
1755            }
1756    
1757            /**
1758             * Returns the last document library file version in the ordered set where companyId = &#63;.
1759             *
1760             * @param companyId the company ID
1761             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1762             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
1763             */
1764            @Override
1765            public DLFileVersion fetchByCompanyId_Last(long companyId,
1766                    OrderByComparator<DLFileVersion> orderByComparator) {
1767                    int count = countByCompanyId(companyId);
1768    
1769                    if (count == 0) {
1770                            return null;
1771                    }
1772    
1773                    List<DLFileVersion> list = findByCompanyId(companyId, count - 1, count,
1774                                    orderByComparator);
1775    
1776                    if (!list.isEmpty()) {
1777                            return list.get(0);
1778                    }
1779    
1780                    return null;
1781            }
1782    
1783            /**
1784             * Returns the document library file versions before and after the current document library file version in the ordered set where companyId = &#63;.
1785             *
1786             * @param fileVersionId the primary key of the current document library file version
1787             * @param companyId the company ID
1788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1789             * @return the previous, current, and next document library file version
1790             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
1791             */
1792            @Override
1793            public DLFileVersion[] findByCompanyId_PrevAndNext(long fileVersionId,
1794                    long companyId, OrderByComparator<DLFileVersion> orderByComparator)
1795                    throws NoSuchFileVersionException {
1796                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1797    
1798                    Session session = null;
1799    
1800                    try {
1801                            session = openSession();
1802    
1803                            DLFileVersion[] array = new DLFileVersionImpl[3];
1804    
1805                            array[0] = getByCompanyId_PrevAndNext(session, dlFileVersion,
1806                                            companyId, orderByComparator, true);
1807    
1808                            array[1] = dlFileVersion;
1809    
1810                            array[2] = getByCompanyId_PrevAndNext(session, dlFileVersion,
1811                                            companyId, orderByComparator, false);
1812    
1813                            return array;
1814                    }
1815                    catch (Exception e) {
1816                            throw processException(e);
1817                    }
1818                    finally {
1819                            closeSession(session);
1820                    }
1821            }
1822    
1823            protected DLFileVersion getByCompanyId_PrevAndNext(Session session,
1824                    DLFileVersion dlFileVersion, long companyId,
1825                    OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
1826                    StringBundler query = null;
1827    
1828                    if (orderByComparator != null) {
1829                            query = new StringBundler(6 +
1830                                            (orderByComparator.getOrderByFields().length * 6));
1831                    }
1832                    else {
1833                            query = new StringBundler(3);
1834                    }
1835    
1836                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1837    
1838                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1839    
1840                    if (orderByComparator != null) {
1841                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1842    
1843                            if (orderByConditionFields.length > 0) {
1844                                    query.append(WHERE_AND);
1845                            }
1846    
1847                            for (int i = 0; i < orderByConditionFields.length; i++) {
1848                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1849                                    query.append(orderByConditionFields[i]);
1850    
1851                                    if ((i + 1) < orderByConditionFields.length) {
1852                                            if (orderByComparator.isAscending() ^ previous) {
1853                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1854                                            }
1855                                            else {
1856                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1857                                            }
1858                                    }
1859                                    else {
1860                                            if (orderByComparator.isAscending() ^ previous) {
1861                                                    query.append(WHERE_GREATER_THAN);
1862                                            }
1863                                            else {
1864                                                    query.append(WHERE_LESSER_THAN);
1865                                            }
1866                                    }
1867                            }
1868    
1869                            query.append(ORDER_BY_CLAUSE);
1870    
1871                            String[] orderByFields = orderByComparator.getOrderByFields();
1872    
1873                            for (int i = 0; i < orderByFields.length; i++) {
1874                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1875                                    query.append(orderByFields[i]);
1876    
1877                                    if ((i + 1) < orderByFields.length) {
1878                                            if (orderByComparator.isAscending() ^ previous) {
1879                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1880                                            }
1881                                            else {
1882                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1883                                            }
1884                                    }
1885                                    else {
1886                                            if (orderByComparator.isAscending() ^ previous) {
1887                                                    query.append(ORDER_BY_ASC);
1888                                            }
1889                                            else {
1890                                                    query.append(ORDER_BY_DESC);
1891                                            }
1892                                    }
1893                            }
1894                    }
1895                    else {
1896                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1897                    }
1898    
1899                    String sql = query.toString();
1900    
1901                    Query q = session.createQuery(sql);
1902    
1903                    q.setFirstResult(0);
1904                    q.setMaxResults(2);
1905    
1906                    QueryPos qPos = QueryPos.getInstance(q);
1907    
1908                    qPos.add(companyId);
1909    
1910                    if (orderByComparator != null) {
1911                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
1912    
1913                            for (Object value : values) {
1914                                    qPos.add(value);
1915                            }
1916                    }
1917    
1918                    List<DLFileVersion> list = q.list();
1919    
1920                    if (list.size() == 2) {
1921                            return list.get(1);
1922                    }
1923                    else {
1924                            return null;
1925                    }
1926            }
1927    
1928            /**
1929             * Removes all the document library file versions where companyId = &#63; from the database.
1930             *
1931             * @param companyId the company ID
1932             */
1933            @Override
1934            public void removeByCompanyId(long companyId) {
1935                    for (DLFileVersion dlFileVersion : findByCompanyId(companyId,
1936                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1937                            remove(dlFileVersion);
1938                    }
1939            }
1940    
1941            /**
1942             * Returns the number of document library file versions where companyId = &#63;.
1943             *
1944             * @param companyId the company ID
1945             * @return the number of matching document library file versions
1946             */
1947            @Override
1948            public int countByCompanyId(long companyId) {
1949                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1950    
1951                    Object[] finderArgs = new Object[] { companyId };
1952    
1953                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1954    
1955                    if (count == null) {
1956                            StringBundler query = new StringBundler(2);
1957    
1958                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1959    
1960                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1961    
1962                            String sql = query.toString();
1963    
1964                            Session session = null;
1965    
1966                            try {
1967                                    session = openSession();
1968    
1969                                    Query q = session.createQuery(sql);
1970    
1971                                    QueryPos qPos = QueryPos.getInstance(q);
1972    
1973                                    qPos.add(companyId);
1974    
1975                                    count = (Long)q.uniqueResult();
1976    
1977                                    finderCache.putResult(finderPath, finderArgs, count);
1978                            }
1979                            catch (Exception e) {
1980                                    finderCache.removeResult(finderPath, finderArgs);
1981    
1982                                    throw processException(e);
1983                            }
1984                            finally {
1985                                    closeSession(session);
1986                            }
1987                    }
1988    
1989                    return count.intValue();
1990            }
1991    
1992            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "dlFileVersion.companyId = ?";
1993            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID =
1994                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1995                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1996                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1997                            "findByFileEntryId",
1998                            new String[] {
1999                                    Long.class.getName(),
2000                                    
2001                            Integer.class.getName(), Integer.class.getName(),
2002                                    OrderByComparator.class.getName()
2003                            });
2004            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID =
2005                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2006                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
2007                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2008                            "findByFileEntryId", new String[] { Long.class.getName() },
2009                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
2010                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
2011            public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2012                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2013                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileEntryId",
2014                            new String[] { Long.class.getName() });
2015    
2016            /**
2017             * Returns all the document library file versions where fileEntryId = &#63;.
2018             *
2019             * @param fileEntryId the file entry ID
2020             * @return the matching document library file versions
2021             */
2022            @Override
2023            public List<DLFileVersion> findByFileEntryId(long fileEntryId) {
2024                    return findByFileEntryId(fileEntryId, QueryUtil.ALL_POS,
2025                            QueryUtil.ALL_POS, null);
2026            }
2027    
2028            /**
2029             * Returns a range of all the document library file versions where fileEntryId = &#63;.
2030             *
2031             * <p>
2032             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2033             * </p>
2034             *
2035             * @param fileEntryId the file entry ID
2036             * @param start the lower bound of the range of document library file versions
2037             * @param end the upper bound of the range of document library file versions (not inclusive)
2038             * @return the range of matching document library file versions
2039             */
2040            @Override
2041            public List<DLFileVersion> findByFileEntryId(long fileEntryId, int start,
2042                    int end) {
2043                    return findByFileEntryId(fileEntryId, start, end, null);
2044            }
2045    
2046            /**
2047             * Returns an ordered range of all the document library file versions where fileEntryId = &#63;.
2048             *
2049             * <p>
2050             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2051             * </p>
2052             *
2053             * @param fileEntryId the file entry ID
2054             * @param start the lower bound of the range of document library file versions
2055             * @param end the upper bound of the range of document library file versions (not inclusive)
2056             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2057             * @return the ordered range of matching document library file versions
2058             */
2059            @Override
2060            public List<DLFileVersion> findByFileEntryId(long fileEntryId, int start,
2061                    int end, OrderByComparator<DLFileVersion> orderByComparator) {
2062                    return findByFileEntryId(fileEntryId, start, end, orderByComparator,
2063                            true);
2064            }
2065    
2066            /**
2067             * Returns an ordered range of all the document library file versions where fileEntryId = &#63;.
2068             *
2069             * <p>
2070             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2071             * </p>
2072             *
2073             * @param fileEntryId the file entry ID
2074             * @param start the lower bound of the range of document library file versions
2075             * @param end the upper bound of the range of document library file versions (not inclusive)
2076             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2077             * @param retrieveFromCache whether to retrieve from the finder cache
2078             * @return the ordered range of matching document library file versions
2079             */
2080            @Override
2081            public List<DLFileVersion> findByFileEntryId(long fileEntryId, int start,
2082                    int end, OrderByComparator<DLFileVersion> orderByComparator,
2083                    boolean retrieveFromCache) {
2084                    boolean pagination = true;
2085                    FinderPath finderPath = null;
2086                    Object[] finderArgs = null;
2087    
2088                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2089                                    (orderByComparator == null)) {
2090                            pagination = false;
2091                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID;
2092                            finderArgs = new Object[] { fileEntryId };
2093                    }
2094                    else {
2095                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID;
2096                            finderArgs = new Object[] { fileEntryId, start, end, orderByComparator };
2097                    }
2098    
2099                    List<DLFileVersion> list = null;
2100    
2101                    if (retrieveFromCache) {
2102                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
2103                                            finderArgs, this);
2104    
2105                            if ((list != null) && !list.isEmpty()) {
2106                                    for (DLFileVersion dlFileVersion : list) {
2107                                            if ((fileEntryId != dlFileVersion.getFileEntryId())) {
2108                                                    list = null;
2109    
2110                                                    break;
2111                                            }
2112                                    }
2113                            }
2114                    }
2115    
2116                    if (list == null) {
2117                            StringBundler query = null;
2118    
2119                            if (orderByComparator != null) {
2120                                    query = new StringBundler(3 +
2121                                                    (orderByComparator.getOrderByFields().length * 3));
2122                            }
2123                            else {
2124                                    query = new StringBundler(3);
2125                            }
2126    
2127                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2128    
2129                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2130    
2131                            if (orderByComparator != null) {
2132                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2133                                            orderByComparator);
2134                            }
2135                            else
2136                             if (pagination) {
2137                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2138                            }
2139    
2140                            String sql = query.toString();
2141    
2142                            Session session = null;
2143    
2144                            try {
2145                                    session = openSession();
2146    
2147                                    Query q = session.createQuery(sql);
2148    
2149                                    QueryPos qPos = QueryPos.getInstance(q);
2150    
2151                                    qPos.add(fileEntryId);
2152    
2153                                    if (!pagination) {
2154                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2155                                                            start, end, false);
2156    
2157                                            Collections.sort(list);
2158    
2159                                            list = Collections.unmodifiableList(list);
2160                                    }
2161                                    else {
2162                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2163                                                            start, end);
2164                                    }
2165    
2166                                    cacheResult(list);
2167    
2168                                    finderCache.putResult(finderPath, finderArgs, list);
2169                            }
2170                            catch (Exception e) {
2171                                    finderCache.removeResult(finderPath, finderArgs);
2172    
2173                                    throw processException(e);
2174                            }
2175                            finally {
2176                                    closeSession(session);
2177                            }
2178                    }
2179    
2180                    return list;
2181            }
2182    
2183            /**
2184             * Returns the first document library file version in the ordered set where fileEntryId = &#63;.
2185             *
2186             * @param fileEntryId the file entry ID
2187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2188             * @return the first matching document library file version
2189             * @throws NoSuchFileVersionException if a matching document library file version could not be found
2190             */
2191            @Override
2192            public DLFileVersion findByFileEntryId_First(long fileEntryId,
2193                    OrderByComparator<DLFileVersion> orderByComparator)
2194                    throws NoSuchFileVersionException {
2195                    DLFileVersion dlFileVersion = fetchByFileEntryId_First(fileEntryId,
2196                                    orderByComparator);
2197    
2198                    if (dlFileVersion != null) {
2199                            return dlFileVersion;
2200                    }
2201    
2202                    StringBundler msg = new StringBundler(4);
2203    
2204                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2205    
2206                    msg.append("fileEntryId=");
2207                    msg.append(fileEntryId);
2208    
2209                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2210    
2211                    throw new NoSuchFileVersionException(msg.toString());
2212            }
2213    
2214            /**
2215             * Returns the first document library file version in the ordered set where fileEntryId = &#63;.
2216             *
2217             * @param fileEntryId the file entry ID
2218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2219             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
2220             */
2221            @Override
2222            public DLFileVersion fetchByFileEntryId_First(long fileEntryId,
2223                    OrderByComparator<DLFileVersion> orderByComparator) {
2224                    List<DLFileVersion> list = findByFileEntryId(fileEntryId, 0, 1,
2225                                    orderByComparator);
2226    
2227                    if (!list.isEmpty()) {
2228                            return list.get(0);
2229                    }
2230    
2231                    return null;
2232            }
2233    
2234            /**
2235             * Returns the last document library file version in the ordered set where fileEntryId = &#63;.
2236             *
2237             * @param fileEntryId the file entry ID
2238             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2239             * @return the last matching document library file version
2240             * @throws NoSuchFileVersionException if a matching document library file version could not be found
2241             */
2242            @Override
2243            public DLFileVersion findByFileEntryId_Last(long fileEntryId,
2244                    OrderByComparator<DLFileVersion> orderByComparator)
2245                    throws NoSuchFileVersionException {
2246                    DLFileVersion dlFileVersion = fetchByFileEntryId_Last(fileEntryId,
2247                                    orderByComparator);
2248    
2249                    if (dlFileVersion != null) {
2250                            return dlFileVersion;
2251                    }
2252    
2253                    StringBundler msg = new StringBundler(4);
2254    
2255                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2256    
2257                    msg.append("fileEntryId=");
2258                    msg.append(fileEntryId);
2259    
2260                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2261    
2262                    throw new NoSuchFileVersionException(msg.toString());
2263            }
2264    
2265            /**
2266             * Returns the last document library file version in the ordered set where fileEntryId = &#63;.
2267             *
2268             * @param fileEntryId the file entry ID
2269             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2270             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
2271             */
2272            @Override
2273            public DLFileVersion fetchByFileEntryId_Last(long fileEntryId,
2274                    OrderByComparator<DLFileVersion> orderByComparator) {
2275                    int count = countByFileEntryId(fileEntryId);
2276    
2277                    if (count == 0) {
2278                            return null;
2279                    }
2280    
2281                    List<DLFileVersion> list = findByFileEntryId(fileEntryId, count - 1,
2282                                    count, orderByComparator);
2283    
2284                    if (!list.isEmpty()) {
2285                            return list.get(0);
2286                    }
2287    
2288                    return null;
2289            }
2290    
2291            /**
2292             * Returns the document library file versions before and after the current document library file version in the ordered set where fileEntryId = &#63;.
2293             *
2294             * @param fileVersionId the primary key of the current document library file version
2295             * @param fileEntryId the file entry ID
2296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2297             * @return the previous, current, and next document library file version
2298             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
2299             */
2300            @Override
2301            public DLFileVersion[] findByFileEntryId_PrevAndNext(long fileVersionId,
2302                    long fileEntryId, OrderByComparator<DLFileVersion> orderByComparator)
2303                    throws NoSuchFileVersionException {
2304                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
2305    
2306                    Session session = null;
2307    
2308                    try {
2309                            session = openSession();
2310    
2311                            DLFileVersion[] array = new DLFileVersionImpl[3];
2312    
2313                            array[0] = getByFileEntryId_PrevAndNext(session, dlFileVersion,
2314                                            fileEntryId, orderByComparator, true);
2315    
2316                            array[1] = dlFileVersion;
2317    
2318                            array[2] = getByFileEntryId_PrevAndNext(session, dlFileVersion,
2319                                            fileEntryId, orderByComparator, false);
2320    
2321                            return array;
2322                    }
2323                    catch (Exception e) {
2324                            throw processException(e);
2325                    }
2326                    finally {
2327                            closeSession(session);
2328                    }
2329            }
2330    
2331            protected DLFileVersion getByFileEntryId_PrevAndNext(Session session,
2332                    DLFileVersion dlFileVersion, long fileEntryId,
2333                    OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
2334                    StringBundler query = null;
2335    
2336                    if (orderByComparator != null) {
2337                            query = new StringBundler(6 +
2338                                            (orderByComparator.getOrderByFields().length * 6));
2339                    }
2340                    else {
2341                            query = new StringBundler(3);
2342                    }
2343    
2344                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2345    
2346                    query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2347    
2348                    if (orderByComparator != null) {
2349                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2350    
2351                            if (orderByConditionFields.length > 0) {
2352                                    query.append(WHERE_AND);
2353                            }
2354    
2355                            for (int i = 0; i < orderByConditionFields.length; i++) {
2356                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2357                                    query.append(orderByConditionFields[i]);
2358    
2359                                    if ((i + 1) < orderByConditionFields.length) {
2360                                            if (orderByComparator.isAscending() ^ previous) {
2361                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2362                                            }
2363                                            else {
2364                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2365                                            }
2366                                    }
2367                                    else {
2368                                            if (orderByComparator.isAscending() ^ previous) {
2369                                                    query.append(WHERE_GREATER_THAN);
2370                                            }
2371                                            else {
2372                                                    query.append(WHERE_LESSER_THAN);
2373                                            }
2374                                    }
2375                            }
2376    
2377                            query.append(ORDER_BY_CLAUSE);
2378    
2379                            String[] orderByFields = orderByComparator.getOrderByFields();
2380    
2381                            for (int i = 0; i < orderByFields.length; i++) {
2382                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2383                                    query.append(orderByFields[i]);
2384    
2385                                    if ((i + 1) < orderByFields.length) {
2386                                            if (orderByComparator.isAscending() ^ previous) {
2387                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2388                                            }
2389                                            else {
2390                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2391                                            }
2392                                    }
2393                                    else {
2394                                            if (orderByComparator.isAscending() ^ previous) {
2395                                                    query.append(ORDER_BY_ASC);
2396                                            }
2397                                            else {
2398                                                    query.append(ORDER_BY_DESC);
2399                                            }
2400                                    }
2401                            }
2402                    }
2403                    else {
2404                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2405                    }
2406    
2407                    String sql = query.toString();
2408    
2409                    Query q = session.createQuery(sql);
2410    
2411                    q.setFirstResult(0);
2412                    q.setMaxResults(2);
2413    
2414                    QueryPos qPos = QueryPos.getInstance(q);
2415    
2416                    qPos.add(fileEntryId);
2417    
2418                    if (orderByComparator != null) {
2419                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
2420    
2421                            for (Object value : values) {
2422                                    qPos.add(value);
2423                            }
2424                    }
2425    
2426                    List<DLFileVersion> list = q.list();
2427    
2428                    if (list.size() == 2) {
2429                            return list.get(1);
2430                    }
2431                    else {
2432                            return null;
2433                    }
2434            }
2435    
2436            /**
2437             * Removes all the document library file versions where fileEntryId = &#63; from the database.
2438             *
2439             * @param fileEntryId the file entry ID
2440             */
2441            @Override
2442            public void removeByFileEntryId(long fileEntryId) {
2443                    for (DLFileVersion dlFileVersion : findByFileEntryId(fileEntryId,
2444                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2445                            remove(dlFileVersion);
2446                    }
2447            }
2448    
2449            /**
2450             * Returns the number of document library file versions where fileEntryId = &#63;.
2451             *
2452             * @param fileEntryId the file entry ID
2453             * @return the number of matching document library file versions
2454             */
2455            @Override
2456            public int countByFileEntryId(long fileEntryId) {
2457                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEENTRYID;
2458    
2459                    Object[] finderArgs = new Object[] { fileEntryId };
2460    
2461                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2462    
2463                    if (count == null) {
2464                            StringBundler query = new StringBundler(2);
2465    
2466                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
2467    
2468                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
2469    
2470                            String sql = query.toString();
2471    
2472                            Session session = null;
2473    
2474                            try {
2475                                    session = openSession();
2476    
2477                                    Query q = session.createQuery(sql);
2478    
2479                                    QueryPos qPos = QueryPos.getInstance(q);
2480    
2481                                    qPos.add(fileEntryId);
2482    
2483                                    count = (Long)q.uniqueResult();
2484    
2485                                    finderCache.putResult(finderPath, finderArgs, count);
2486                            }
2487                            catch (Exception e) {
2488                                    finderCache.removeResult(finderPath, finderArgs);
2489    
2490                                    throw processException(e);
2491                            }
2492                            finally {
2493                                    closeSession(session);
2494                            }
2495                    }
2496    
2497                    return count.intValue();
2498            }
2499    
2500            private static final String _FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ?";
2501            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_MIMETYPE = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2502                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
2503                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2504                            "findByMimeType",
2505                            new String[] {
2506                                    String.class.getName(),
2507                                    
2508                            Integer.class.getName(), Integer.class.getName(),
2509                                    OrderByComparator.class.getName()
2510                            });
2511            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE =
2512                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2513                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
2514                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2515                            "findByMimeType", new String[] { String.class.getName() },
2516                            DLFileVersionModelImpl.MIMETYPE_COLUMN_BITMASK |
2517                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
2518                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
2519            public static final FinderPath FINDER_PATH_COUNT_BY_MIMETYPE = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2520                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2521                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMimeType",
2522                            new String[] { String.class.getName() });
2523    
2524            /**
2525             * Returns all the document library file versions where mimeType = &#63;.
2526             *
2527             * @param mimeType the mime type
2528             * @return the matching document library file versions
2529             */
2530            @Override
2531            public List<DLFileVersion> findByMimeType(String mimeType) {
2532                    return findByMimeType(mimeType, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2533                            null);
2534            }
2535    
2536            /**
2537             * Returns a range of all the document library file versions where mimeType = &#63;.
2538             *
2539             * <p>
2540             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2541             * </p>
2542             *
2543             * @param mimeType the mime type
2544             * @param start the lower bound of the range of document library file versions
2545             * @param end the upper bound of the range of document library file versions (not inclusive)
2546             * @return the range of matching document library file versions
2547             */
2548            @Override
2549            public List<DLFileVersion> findByMimeType(String mimeType, int start,
2550                    int end) {
2551                    return findByMimeType(mimeType, start, end, null);
2552            }
2553    
2554            /**
2555             * Returns an ordered range of all the document library file versions where mimeType = &#63;.
2556             *
2557             * <p>
2558             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2559             * </p>
2560             *
2561             * @param mimeType the mime type
2562             * @param start the lower bound of the range of document library file versions
2563             * @param end the upper bound of the range of document library file versions (not inclusive)
2564             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2565             * @return the ordered range of matching document library file versions
2566             */
2567            @Override
2568            public List<DLFileVersion> findByMimeType(String mimeType, int start,
2569                    int end, OrderByComparator<DLFileVersion> orderByComparator) {
2570                    return findByMimeType(mimeType, start, end, orderByComparator, true);
2571            }
2572    
2573            /**
2574             * Returns an ordered range of all the document library file versions where mimeType = &#63;.
2575             *
2576             * <p>
2577             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2578             * </p>
2579             *
2580             * @param mimeType the mime type
2581             * @param start the lower bound of the range of document library file versions
2582             * @param end the upper bound of the range of document library file versions (not inclusive)
2583             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2584             * @param retrieveFromCache whether to retrieve from the finder cache
2585             * @return the ordered range of matching document library file versions
2586             */
2587            @Override
2588            public List<DLFileVersion> findByMimeType(String mimeType, int start,
2589                    int end, OrderByComparator<DLFileVersion> orderByComparator,
2590                    boolean retrieveFromCache) {
2591                    boolean pagination = true;
2592                    FinderPath finderPath = null;
2593                    Object[] finderArgs = null;
2594    
2595                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2596                                    (orderByComparator == null)) {
2597                            pagination = false;
2598                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE;
2599                            finderArgs = new Object[] { mimeType };
2600                    }
2601                    else {
2602                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_MIMETYPE;
2603                            finderArgs = new Object[] { mimeType, start, end, orderByComparator };
2604                    }
2605    
2606                    List<DLFileVersion> list = null;
2607    
2608                    if (retrieveFromCache) {
2609                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
2610                                            finderArgs, this);
2611    
2612                            if ((list != null) && !list.isEmpty()) {
2613                                    for (DLFileVersion dlFileVersion : list) {
2614                                            if (!Validator.equals(mimeType, dlFileVersion.getMimeType())) {
2615                                                    list = null;
2616    
2617                                                    break;
2618                                            }
2619                                    }
2620                            }
2621                    }
2622    
2623                    if (list == null) {
2624                            StringBundler query = null;
2625    
2626                            if (orderByComparator != null) {
2627                                    query = new StringBundler(3 +
2628                                                    (orderByComparator.getOrderByFields().length * 3));
2629                            }
2630                            else {
2631                                    query = new StringBundler(3);
2632                            }
2633    
2634                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2635    
2636                            boolean bindMimeType = false;
2637    
2638                            if (mimeType == null) {
2639                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
2640                            }
2641                            else if (mimeType.equals(StringPool.BLANK)) {
2642                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
2643                            }
2644                            else {
2645                                    bindMimeType = true;
2646    
2647                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
2648                            }
2649    
2650                            if (orderByComparator != null) {
2651                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2652                                            orderByComparator);
2653                            }
2654                            else
2655                             if (pagination) {
2656                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2657                            }
2658    
2659                            String sql = query.toString();
2660    
2661                            Session session = null;
2662    
2663                            try {
2664                                    session = openSession();
2665    
2666                                    Query q = session.createQuery(sql);
2667    
2668                                    QueryPos qPos = QueryPos.getInstance(q);
2669    
2670                                    if (bindMimeType) {
2671                                            qPos.add(mimeType);
2672                                    }
2673    
2674                                    if (!pagination) {
2675                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2676                                                            start, end, false);
2677    
2678                                            Collections.sort(list);
2679    
2680                                            list = Collections.unmodifiableList(list);
2681                                    }
2682                                    else {
2683                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2684                                                            start, end);
2685                                    }
2686    
2687                                    cacheResult(list);
2688    
2689                                    finderCache.putResult(finderPath, finderArgs, list);
2690                            }
2691                            catch (Exception e) {
2692                                    finderCache.removeResult(finderPath, finderArgs);
2693    
2694                                    throw processException(e);
2695                            }
2696                            finally {
2697                                    closeSession(session);
2698                            }
2699                    }
2700    
2701                    return list;
2702            }
2703    
2704            /**
2705             * Returns the first document library file version in the ordered set where mimeType = &#63;.
2706             *
2707             * @param mimeType the mime type
2708             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2709             * @return the first matching document library file version
2710             * @throws NoSuchFileVersionException if a matching document library file version could not be found
2711             */
2712            @Override
2713            public DLFileVersion findByMimeType_First(String mimeType,
2714                    OrderByComparator<DLFileVersion> orderByComparator)
2715                    throws NoSuchFileVersionException {
2716                    DLFileVersion dlFileVersion = fetchByMimeType_First(mimeType,
2717                                    orderByComparator);
2718    
2719                    if (dlFileVersion != null) {
2720                            return dlFileVersion;
2721                    }
2722    
2723                    StringBundler msg = new StringBundler(4);
2724    
2725                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2726    
2727                    msg.append("mimeType=");
2728                    msg.append(mimeType);
2729    
2730                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2731    
2732                    throw new NoSuchFileVersionException(msg.toString());
2733            }
2734    
2735            /**
2736             * Returns the first document library file version in the ordered set where mimeType = &#63;.
2737             *
2738             * @param mimeType the mime type
2739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2740             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
2741             */
2742            @Override
2743            public DLFileVersion fetchByMimeType_First(String mimeType,
2744                    OrderByComparator<DLFileVersion> orderByComparator) {
2745                    List<DLFileVersion> list = findByMimeType(mimeType, 0, 1,
2746                                    orderByComparator);
2747    
2748                    if (!list.isEmpty()) {
2749                            return list.get(0);
2750                    }
2751    
2752                    return null;
2753            }
2754    
2755            /**
2756             * Returns the last document library file version in the ordered set where mimeType = &#63;.
2757             *
2758             * @param mimeType the mime type
2759             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2760             * @return the last matching document library file version
2761             * @throws NoSuchFileVersionException if a matching document library file version could not be found
2762             */
2763            @Override
2764            public DLFileVersion findByMimeType_Last(String mimeType,
2765                    OrderByComparator<DLFileVersion> orderByComparator)
2766                    throws NoSuchFileVersionException {
2767                    DLFileVersion dlFileVersion = fetchByMimeType_Last(mimeType,
2768                                    orderByComparator);
2769    
2770                    if (dlFileVersion != null) {
2771                            return dlFileVersion;
2772                    }
2773    
2774                    StringBundler msg = new StringBundler(4);
2775    
2776                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2777    
2778                    msg.append("mimeType=");
2779                    msg.append(mimeType);
2780    
2781                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2782    
2783                    throw new NoSuchFileVersionException(msg.toString());
2784            }
2785    
2786            /**
2787             * Returns the last document library file version in the ordered set where mimeType = &#63;.
2788             *
2789             * @param mimeType the mime type
2790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2791             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
2792             */
2793            @Override
2794            public DLFileVersion fetchByMimeType_Last(String mimeType,
2795                    OrderByComparator<DLFileVersion> orderByComparator) {
2796                    int count = countByMimeType(mimeType);
2797    
2798                    if (count == 0) {
2799                            return null;
2800                    }
2801    
2802                    List<DLFileVersion> list = findByMimeType(mimeType, count - 1, count,
2803                                    orderByComparator);
2804    
2805                    if (!list.isEmpty()) {
2806                            return list.get(0);
2807                    }
2808    
2809                    return null;
2810            }
2811    
2812            /**
2813             * Returns the document library file versions before and after the current document library file version in the ordered set where mimeType = &#63;.
2814             *
2815             * @param fileVersionId the primary key of the current document library file version
2816             * @param mimeType the mime type
2817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2818             * @return the previous, current, and next document library file version
2819             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
2820             */
2821            @Override
2822            public DLFileVersion[] findByMimeType_PrevAndNext(long fileVersionId,
2823                    String mimeType, OrderByComparator<DLFileVersion> orderByComparator)
2824                    throws NoSuchFileVersionException {
2825                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
2826    
2827                    Session session = null;
2828    
2829                    try {
2830                            session = openSession();
2831    
2832                            DLFileVersion[] array = new DLFileVersionImpl[3];
2833    
2834                            array[0] = getByMimeType_PrevAndNext(session, dlFileVersion,
2835                                            mimeType, orderByComparator, true);
2836    
2837                            array[1] = dlFileVersion;
2838    
2839                            array[2] = getByMimeType_PrevAndNext(session, dlFileVersion,
2840                                            mimeType, orderByComparator, false);
2841    
2842                            return array;
2843                    }
2844                    catch (Exception e) {
2845                            throw processException(e);
2846                    }
2847                    finally {
2848                            closeSession(session);
2849                    }
2850            }
2851    
2852            protected DLFileVersion getByMimeType_PrevAndNext(Session session,
2853                    DLFileVersion dlFileVersion, String mimeType,
2854                    OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
2855                    StringBundler query = null;
2856    
2857                    if (orderByComparator != null) {
2858                            query = new StringBundler(6 +
2859                                            (orderByComparator.getOrderByFields().length * 6));
2860                    }
2861                    else {
2862                            query = new StringBundler(3);
2863                    }
2864    
2865                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2866    
2867                    boolean bindMimeType = false;
2868    
2869                    if (mimeType == null) {
2870                            query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
2871                    }
2872                    else if (mimeType.equals(StringPool.BLANK)) {
2873                            query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
2874                    }
2875                    else {
2876                            bindMimeType = true;
2877    
2878                            query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
2879                    }
2880    
2881                    if (orderByComparator != null) {
2882                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2883    
2884                            if (orderByConditionFields.length > 0) {
2885                                    query.append(WHERE_AND);
2886                            }
2887    
2888                            for (int i = 0; i < orderByConditionFields.length; i++) {
2889                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2890                                    query.append(orderByConditionFields[i]);
2891    
2892                                    if ((i + 1) < orderByConditionFields.length) {
2893                                            if (orderByComparator.isAscending() ^ previous) {
2894                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2895                                            }
2896                                            else {
2897                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2898                                            }
2899                                    }
2900                                    else {
2901                                            if (orderByComparator.isAscending() ^ previous) {
2902                                                    query.append(WHERE_GREATER_THAN);
2903                                            }
2904                                            else {
2905                                                    query.append(WHERE_LESSER_THAN);
2906                                            }
2907                                    }
2908                            }
2909    
2910                            query.append(ORDER_BY_CLAUSE);
2911    
2912                            String[] orderByFields = orderByComparator.getOrderByFields();
2913    
2914                            for (int i = 0; i < orderByFields.length; i++) {
2915                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2916                                    query.append(orderByFields[i]);
2917    
2918                                    if ((i + 1) < orderByFields.length) {
2919                                            if (orderByComparator.isAscending() ^ previous) {
2920                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2921                                            }
2922                                            else {
2923                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2924                                            }
2925                                    }
2926                                    else {
2927                                            if (orderByComparator.isAscending() ^ previous) {
2928                                                    query.append(ORDER_BY_ASC);
2929                                            }
2930                                            else {
2931                                                    query.append(ORDER_BY_DESC);
2932                                            }
2933                                    }
2934                            }
2935                    }
2936                    else {
2937                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2938                    }
2939    
2940                    String sql = query.toString();
2941    
2942                    Query q = session.createQuery(sql);
2943    
2944                    q.setFirstResult(0);
2945                    q.setMaxResults(2);
2946    
2947                    QueryPos qPos = QueryPos.getInstance(q);
2948    
2949                    if (bindMimeType) {
2950                            qPos.add(mimeType);
2951                    }
2952    
2953                    if (orderByComparator != null) {
2954                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
2955    
2956                            for (Object value : values) {
2957                                    qPos.add(value);
2958                            }
2959                    }
2960    
2961                    List<DLFileVersion> list = q.list();
2962    
2963                    if (list.size() == 2) {
2964                            return list.get(1);
2965                    }
2966                    else {
2967                            return null;
2968                    }
2969            }
2970    
2971            /**
2972             * Removes all the document library file versions where mimeType = &#63; from the database.
2973             *
2974             * @param mimeType the mime type
2975             */
2976            @Override
2977            public void removeByMimeType(String mimeType) {
2978                    for (DLFileVersion dlFileVersion : findByMimeType(mimeType,
2979                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2980                            remove(dlFileVersion);
2981                    }
2982            }
2983    
2984            /**
2985             * Returns the number of document library file versions where mimeType = &#63;.
2986             *
2987             * @param mimeType the mime type
2988             * @return the number of matching document library file versions
2989             */
2990            @Override
2991            public int countByMimeType(String mimeType) {
2992                    FinderPath finderPath = FINDER_PATH_COUNT_BY_MIMETYPE;
2993    
2994                    Object[] finderArgs = new Object[] { mimeType };
2995    
2996                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2997    
2998                    if (count == null) {
2999                            StringBundler query = new StringBundler(2);
3000    
3001                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
3002    
3003                            boolean bindMimeType = false;
3004    
3005                            if (mimeType == null) {
3006                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
3007                            }
3008                            else if (mimeType.equals(StringPool.BLANK)) {
3009                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
3010                            }
3011                            else {
3012                                    bindMimeType = true;
3013    
3014                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
3015                            }
3016    
3017                            String sql = query.toString();
3018    
3019                            Session session = null;
3020    
3021                            try {
3022                                    session = openSession();
3023    
3024                                    Query q = session.createQuery(sql);
3025    
3026                                    QueryPos qPos = QueryPos.getInstance(q);
3027    
3028                                    if (bindMimeType) {
3029                                            qPos.add(mimeType);
3030                                    }
3031    
3032                                    count = (Long)q.uniqueResult();
3033    
3034                                    finderCache.putResult(finderPath, finderArgs, count);
3035                            }
3036                            catch (Exception e) {
3037                                    finderCache.removeResult(finderPath, finderArgs);
3038    
3039                                    throw processException(e);
3040                            }
3041                            finally {
3042                                    closeSession(session);
3043                            }
3044                    }
3045    
3046                    return count.intValue();
3047            }
3048    
3049            private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_1 = "dlFileVersion.mimeType IS NULL";
3050            private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_2 = "dlFileVersion.mimeType = ?";
3051            private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_3 = "(dlFileVersion.mimeType IS NULL OR dlFileVersion.mimeType = '')";
3052            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3053                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3054                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3055                            "findByC_NotS",
3056                            new String[] {
3057                                    Long.class.getName(), Integer.class.getName(),
3058                                    
3059                            Integer.class.getName(), Integer.class.getName(),
3060                                    OrderByComparator.class.getName()
3061                            });
3062            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3063                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3064                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_NotS",
3065                            new String[] { Long.class.getName(), Integer.class.getName() });
3066    
3067            /**
3068             * Returns all the document library file versions where companyId = &#63; and status &ne; &#63;.
3069             *
3070             * @param companyId the company ID
3071             * @param status the status
3072             * @return the matching document library file versions
3073             */
3074            @Override
3075            public List<DLFileVersion> findByC_NotS(long companyId, int status) {
3076                    return findByC_NotS(companyId, status, QueryUtil.ALL_POS,
3077                            QueryUtil.ALL_POS, null);
3078            }
3079    
3080            /**
3081             * Returns a range of all the document library file versions where companyId = &#63; and status &ne; &#63;.
3082             *
3083             * <p>
3084             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3085             * </p>
3086             *
3087             * @param companyId the company ID
3088             * @param status the status
3089             * @param start the lower bound of the range of document library file versions
3090             * @param end the upper bound of the range of document library file versions (not inclusive)
3091             * @return the range of matching document library file versions
3092             */
3093            @Override
3094            public List<DLFileVersion> findByC_NotS(long companyId, int status,
3095                    int start, int end) {
3096                    return findByC_NotS(companyId, status, start, end, null);
3097            }
3098    
3099            /**
3100             * Returns an ordered range of all the document library file versions where companyId = &#63; and status &ne; &#63;.
3101             *
3102             * <p>
3103             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3104             * </p>
3105             *
3106             * @param companyId the company ID
3107             * @param status the status
3108             * @param start the lower bound of the range of document library file versions
3109             * @param end the upper bound of the range of document library file versions (not inclusive)
3110             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3111             * @return the ordered range of matching document library file versions
3112             */
3113            @Override
3114            public List<DLFileVersion> findByC_NotS(long companyId, int status,
3115                    int start, int end, OrderByComparator<DLFileVersion> orderByComparator) {
3116                    return findByC_NotS(companyId, status, start, end, orderByComparator,
3117                            true);
3118            }
3119    
3120            /**
3121             * Returns an ordered range of all the document library file versions where companyId = &#63; and status &ne; &#63;.
3122             *
3123             * <p>
3124             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3125             * </p>
3126             *
3127             * @param companyId the company ID
3128             * @param status the status
3129             * @param start the lower bound of the range of document library file versions
3130             * @param end the upper bound of the range of document library file versions (not inclusive)
3131             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3132             * @param retrieveFromCache whether to retrieve from the finder cache
3133             * @return the ordered range of matching document library file versions
3134             */
3135            @Override
3136            public List<DLFileVersion> findByC_NotS(long companyId, int status,
3137                    int start, int end, OrderByComparator<DLFileVersion> orderByComparator,
3138                    boolean retrieveFromCache) {
3139                    boolean pagination = true;
3140                    FinderPath finderPath = null;
3141                    Object[] finderArgs = null;
3142    
3143                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTS;
3144                    finderArgs = new Object[] {
3145                                    companyId, status,
3146                                    
3147                                    start, end, orderByComparator
3148                            };
3149    
3150                    List<DLFileVersion> list = null;
3151    
3152                    if (retrieveFromCache) {
3153                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
3154                                            finderArgs, this);
3155    
3156                            if ((list != null) && !list.isEmpty()) {
3157                                    for (DLFileVersion dlFileVersion : list) {
3158                                            if ((companyId != dlFileVersion.getCompanyId()) ||
3159                                                            (status == dlFileVersion.getStatus())) {
3160                                                    list = null;
3161    
3162                                                    break;
3163                                            }
3164                                    }
3165                            }
3166                    }
3167    
3168                    if (list == null) {
3169                            StringBundler query = null;
3170    
3171                            if (orderByComparator != null) {
3172                                    query = new StringBundler(4 +
3173                                                    (orderByComparator.getOrderByFields().length * 3));
3174                            }
3175                            else {
3176                                    query = new StringBundler(4);
3177                            }
3178    
3179                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3180    
3181                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
3182    
3183                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
3184    
3185                            if (orderByComparator != null) {
3186                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3187                                            orderByComparator);
3188                            }
3189                            else
3190                             if (pagination) {
3191                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3192                            }
3193    
3194                            String sql = query.toString();
3195    
3196                            Session session = null;
3197    
3198                            try {
3199                                    session = openSession();
3200    
3201                                    Query q = session.createQuery(sql);
3202    
3203                                    QueryPos qPos = QueryPos.getInstance(q);
3204    
3205                                    qPos.add(companyId);
3206    
3207                                    qPos.add(status);
3208    
3209                                    if (!pagination) {
3210                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3211                                                            start, end, false);
3212    
3213                                            Collections.sort(list);
3214    
3215                                            list = Collections.unmodifiableList(list);
3216                                    }
3217                                    else {
3218                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3219                                                            start, end);
3220                                    }
3221    
3222                                    cacheResult(list);
3223    
3224                                    finderCache.putResult(finderPath, finderArgs, list);
3225                            }
3226                            catch (Exception e) {
3227                                    finderCache.removeResult(finderPath, finderArgs);
3228    
3229                                    throw processException(e);
3230                            }
3231                            finally {
3232                                    closeSession(session);
3233                            }
3234                    }
3235    
3236                    return list;
3237            }
3238    
3239            /**
3240             * Returns the first document library file version in the ordered set where companyId = &#63; and status &ne; &#63;.
3241             *
3242             * @param companyId the company ID
3243             * @param status the status
3244             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3245             * @return the first matching document library file version
3246             * @throws NoSuchFileVersionException if a matching document library file version could not be found
3247             */
3248            @Override
3249            public DLFileVersion findByC_NotS_First(long companyId, int status,
3250                    OrderByComparator<DLFileVersion> orderByComparator)
3251                    throws NoSuchFileVersionException {
3252                    DLFileVersion dlFileVersion = fetchByC_NotS_First(companyId, status,
3253                                    orderByComparator);
3254    
3255                    if (dlFileVersion != null) {
3256                            return dlFileVersion;
3257                    }
3258    
3259                    StringBundler msg = new StringBundler(6);
3260    
3261                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3262    
3263                    msg.append("companyId=");
3264                    msg.append(companyId);
3265    
3266                    msg.append(", status=");
3267                    msg.append(status);
3268    
3269                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3270    
3271                    throw new NoSuchFileVersionException(msg.toString());
3272            }
3273    
3274            /**
3275             * Returns the first document library file version in the ordered set where companyId = &#63; and status &ne; &#63;.
3276             *
3277             * @param companyId the company ID
3278             * @param status the status
3279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3280             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
3281             */
3282            @Override
3283            public DLFileVersion fetchByC_NotS_First(long companyId, int status,
3284                    OrderByComparator<DLFileVersion> orderByComparator) {
3285                    List<DLFileVersion> list = findByC_NotS(companyId, status, 0, 1,
3286                                    orderByComparator);
3287    
3288                    if (!list.isEmpty()) {
3289                            return list.get(0);
3290                    }
3291    
3292                    return null;
3293            }
3294    
3295            /**
3296             * Returns the last document library file version in the ordered set where companyId = &#63; and status &ne; &#63;.
3297             *
3298             * @param companyId the company ID
3299             * @param status the status
3300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3301             * @return the last matching document library file version
3302             * @throws NoSuchFileVersionException if a matching document library file version could not be found
3303             */
3304            @Override
3305            public DLFileVersion findByC_NotS_Last(long companyId, int status,
3306                    OrderByComparator<DLFileVersion> orderByComparator)
3307                    throws NoSuchFileVersionException {
3308                    DLFileVersion dlFileVersion = fetchByC_NotS_Last(companyId, status,
3309                                    orderByComparator);
3310    
3311                    if (dlFileVersion != null) {
3312                            return dlFileVersion;
3313                    }
3314    
3315                    StringBundler msg = new StringBundler(6);
3316    
3317                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3318    
3319                    msg.append("companyId=");
3320                    msg.append(companyId);
3321    
3322                    msg.append(", status=");
3323                    msg.append(status);
3324    
3325                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3326    
3327                    throw new NoSuchFileVersionException(msg.toString());
3328            }
3329    
3330            /**
3331             * Returns the last document library file version in the ordered set where companyId = &#63; and status &ne; &#63;.
3332             *
3333             * @param companyId the company ID
3334             * @param status the status
3335             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3336             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
3337             */
3338            @Override
3339            public DLFileVersion fetchByC_NotS_Last(long companyId, int status,
3340                    OrderByComparator<DLFileVersion> orderByComparator) {
3341                    int count = countByC_NotS(companyId, status);
3342    
3343                    if (count == 0) {
3344                            return null;
3345                    }
3346    
3347                    List<DLFileVersion> list = findByC_NotS(companyId, status, count - 1,
3348                                    count, orderByComparator);
3349    
3350                    if (!list.isEmpty()) {
3351                            return list.get(0);
3352                    }
3353    
3354                    return null;
3355            }
3356    
3357            /**
3358             * Returns the document library file versions before and after the current document library file version in the ordered set where companyId = &#63; and status &ne; &#63;.
3359             *
3360             * @param fileVersionId the primary key of the current document library file version
3361             * @param companyId the company ID
3362             * @param status the status
3363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3364             * @return the previous, current, and next document library file version
3365             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
3366             */
3367            @Override
3368            public DLFileVersion[] findByC_NotS_PrevAndNext(long fileVersionId,
3369                    long companyId, int status,
3370                    OrderByComparator<DLFileVersion> orderByComparator)
3371                    throws NoSuchFileVersionException {
3372                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
3373    
3374                    Session session = null;
3375    
3376                    try {
3377                            session = openSession();
3378    
3379                            DLFileVersion[] array = new DLFileVersionImpl[3];
3380    
3381                            array[0] = getByC_NotS_PrevAndNext(session, dlFileVersion,
3382                                            companyId, status, orderByComparator, true);
3383    
3384                            array[1] = dlFileVersion;
3385    
3386                            array[2] = getByC_NotS_PrevAndNext(session, dlFileVersion,
3387                                            companyId, status, orderByComparator, false);
3388    
3389                            return array;
3390                    }
3391                    catch (Exception e) {
3392                            throw processException(e);
3393                    }
3394                    finally {
3395                            closeSession(session);
3396                    }
3397            }
3398    
3399            protected DLFileVersion getByC_NotS_PrevAndNext(Session session,
3400                    DLFileVersion dlFileVersion, long companyId, int status,
3401                    OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
3402                    StringBundler query = null;
3403    
3404                    if (orderByComparator != null) {
3405                            query = new StringBundler(6 +
3406                                            (orderByComparator.getOrderByFields().length * 6));
3407                    }
3408                    else {
3409                            query = new StringBundler(3);
3410                    }
3411    
3412                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3413    
3414                    query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
3415    
3416                    query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
3417    
3418                    if (orderByComparator != null) {
3419                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3420    
3421                            if (orderByConditionFields.length > 0) {
3422                                    query.append(WHERE_AND);
3423                            }
3424    
3425                            for (int i = 0; i < orderByConditionFields.length; i++) {
3426                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3427                                    query.append(orderByConditionFields[i]);
3428    
3429                                    if ((i + 1) < orderByConditionFields.length) {
3430                                            if (orderByComparator.isAscending() ^ previous) {
3431                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3432                                            }
3433                                            else {
3434                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3435                                            }
3436                                    }
3437                                    else {
3438                                            if (orderByComparator.isAscending() ^ previous) {
3439                                                    query.append(WHERE_GREATER_THAN);
3440                                            }
3441                                            else {
3442                                                    query.append(WHERE_LESSER_THAN);
3443                                            }
3444                                    }
3445                            }
3446    
3447                            query.append(ORDER_BY_CLAUSE);
3448    
3449                            String[] orderByFields = orderByComparator.getOrderByFields();
3450    
3451                            for (int i = 0; i < orderByFields.length; i++) {
3452                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3453                                    query.append(orderByFields[i]);
3454    
3455                                    if ((i + 1) < orderByFields.length) {
3456                                            if (orderByComparator.isAscending() ^ previous) {
3457                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3458                                            }
3459                                            else {
3460                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3461                                            }
3462                                    }
3463                                    else {
3464                                            if (orderByComparator.isAscending() ^ previous) {
3465                                                    query.append(ORDER_BY_ASC);
3466                                            }
3467                                            else {
3468                                                    query.append(ORDER_BY_DESC);
3469                                            }
3470                                    }
3471                            }
3472                    }
3473                    else {
3474                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3475                    }
3476    
3477                    String sql = query.toString();
3478    
3479                    Query q = session.createQuery(sql);
3480    
3481                    q.setFirstResult(0);
3482                    q.setMaxResults(2);
3483    
3484                    QueryPos qPos = QueryPos.getInstance(q);
3485    
3486                    qPos.add(companyId);
3487    
3488                    qPos.add(status);
3489    
3490                    if (orderByComparator != null) {
3491                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
3492    
3493                            for (Object value : values) {
3494                                    qPos.add(value);
3495                            }
3496                    }
3497    
3498                    List<DLFileVersion> list = q.list();
3499    
3500                    if (list.size() == 2) {
3501                            return list.get(1);
3502                    }
3503                    else {
3504                            return null;
3505                    }
3506            }
3507    
3508            /**
3509             * Removes all the document library file versions where companyId = &#63; and status &ne; &#63; from the database.
3510             *
3511             * @param companyId the company ID
3512             * @param status the status
3513             */
3514            @Override
3515            public void removeByC_NotS(long companyId, int status) {
3516                    for (DLFileVersion dlFileVersion : findByC_NotS(companyId, status,
3517                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3518                            remove(dlFileVersion);
3519                    }
3520            }
3521    
3522            /**
3523             * Returns the number of document library file versions where companyId = &#63; and status &ne; &#63;.
3524             *
3525             * @param companyId the company ID
3526             * @param status the status
3527             * @return the number of matching document library file versions
3528             */
3529            @Override
3530            public int countByC_NotS(long companyId, int status) {
3531                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTS;
3532    
3533                    Object[] finderArgs = new Object[] { companyId, status };
3534    
3535                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3536    
3537                    if (count == null) {
3538                            StringBundler query = new StringBundler(3);
3539    
3540                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
3541    
3542                            query.append(_FINDER_COLUMN_C_NOTS_COMPANYID_2);
3543    
3544                            query.append(_FINDER_COLUMN_C_NOTS_STATUS_2);
3545    
3546                            String sql = query.toString();
3547    
3548                            Session session = null;
3549    
3550                            try {
3551                                    session = openSession();
3552    
3553                                    Query q = session.createQuery(sql);
3554    
3555                                    QueryPos qPos = QueryPos.getInstance(q);
3556    
3557                                    qPos.add(companyId);
3558    
3559                                    qPos.add(status);
3560    
3561                                    count = (Long)q.uniqueResult();
3562    
3563                                    finderCache.putResult(finderPath, finderArgs, count);
3564                            }
3565                            catch (Exception e) {
3566                                    finderCache.removeResult(finderPath, finderArgs);
3567    
3568                                    throw processException(e);
3569                            }
3570                            finally {
3571                                    closeSession(session);
3572                            }
3573                    }
3574    
3575                    return count.intValue();
3576            }
3577    
3578            private static final String _FINDER_COLUMN_C_NOTS_COMPANYID_2 = "dlFileVersion.companyId = ? AND ";
3579            private static final String _FINDER_COLUMN_C_NOTS_STATUS_2 = "dlFileVersion.status != ?";
3580            public static final FinderPath FINDER_PATH_FETCH_BY_F_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3581                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3582                            DLFileVersionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByF_V",
3583                            new String[] { Long.class.getName(), String.class.getName() },
3584                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
3585                            DLFileVersionModelImpl.VERSION_COLUMN_BITMASK);
3586            public static final FinderPath FINDER_PATH_COUNT_BY_F_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3587                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3588                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByF_V",
3589                            new String[] { Long.class.getName(), String.class.getName() });
3590    
3591            /**
3592             * Returns the document library file version where fileEntryId = &#63; and version = &#63; or throws a {@link NoSuchFileVersionException} if it could not be found.
3593             *
3594             * @param fileEntryId the file entry ID
3595             * @param version the version
3596             * @return the matching document library file version
3597             * @throws NoSuchFileVersionException if a matching document library file version could not be found
3598             */
3599            @Override
3600            public DLFileVersion findByF_V(long fileEntryId, String version)
3601                    throws NoSuchFileVersionException {
3602                    DLFileVersion dlFileVersion = fetchByF_V(fileEntryId, version);
3603    
3604                    if (dlFileVersion == null) {
3605                            StringBundler msg = new StringBundler(6);
3606    
3607                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3608    
3609                            msg.append("fileEntryId=");
3610                            msg.append(fileEntryId);
3611    
3612                            msg.append(", version=");
3613                            msg.append(version);
3614    
3615                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3616    
3617                            if (_log.isWarnEnabled()) {
3618                                    _log.warn(msg.toString());
3619                            }
3620    
3621                            throw new NoSuchFileVersionException(msg.toString());
3622                    }
3623    
3624                    return dlFileVersion;
3625            }
3626    
3627            /**
3628             * Returns the document library file version where fileEntryId = &#63; and version = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
3629             *
3630             * @param fileEntryId the file entry ID
3631             * @param version the version
3632             * @return the matching document library file version, or <code>null</code> if a matching document library file version could not be found
3633             */
3634            @Override
3635            public DLFileVersion fetchByF_V(long fileEntryId, String version) {
3636                    return fetchByF_V(fileEntryId, version, true);
3637            }
3638    
3639            /**
3640             * Returns the document library file version where fileEntryId = &#63; and version = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
3641             *
3642             * @param fileEntryId the file entry ID
3643             * @param version the version
3644             * @param retrieveFromCache whether to retrieve from the finder cache
3645             * @return the matching document library file version, or <code>null</code> if a matching document library file version could not be found
3646             */
3647            @Override
3648            public DLFileVersion fetchByF_V(long fileEntryId, String version,
3649                    boolean retrieveFromCache) {
3650                    Object[] finderArgs = new Object[] { fileEntryId, version };
3651    
3652                    Object result = null;
3653    
3654                    if (retrieveFromCache) {
3655                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_F_V,
3656                                            finderArgs, this);
3657                    }
3658    
3659                    if (result instanceof DLFileVersion) {
3660                            DLFileVersion dlFileVersion = (DLFileVersion)result;
3661    
3662                            if ((fileEntryId != dlFileVersion.getFileEntryId()) ||
3663                                            !Validator.equals(version, dlFileVersion.getVersion())) {
3664                                    result = null;
3665                            }
3666                    }
3667    
3668                    if (result == null) {
3669                            StringBundler query = new StringBundler(4);
3670    
3671                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3672    
3673                            query.append(_FINDER_COLUMN_F_V_FILEENTRYID_2);
3674    
3675                            boolean bindVersion = false;
3676    
3677                            if (version == null) {
3678                                    query.append(_FINDER_COLUMN_F_V_VERSION_1);
3679                            }
3680                            else if (version.equals(StringPool.BLANK)) {
3681                                    query.append(_FINDER_COLUMN_F_V_VERSION_3);
3682                            }
3683                            else {
3684                                    bindVersion = true;
3685    
3686                                    query.append(_FINDER_COLUMN_F_V_VERSION_2);
3687                            }
3688    
3689                            String sql = query.toString();
3690    
3691                            Session session = null;
3692    
3693                            try {
3694                                    session = openSession();
3695    
3696                                    Query q = session.createQuery(sql);
3697    
3698                                    QueryPos qPos = QueryPos.getInstance(q);
3699    
3700                                    qPos.add(fileEntryId);
3701    
3702                                    if (bindVersion) {
3703                                            qPos.add(version);
3704                                    }
3705    
3706                                    List<DLFileVersion> list = q.list();
3707    
3708                                    if (list.isEmpty()) {
3709                                            finderCache.putResult(FINDER_PATH_FETCH_BY_F_V, finderArgs,
3710                                                    list);
3711                                    }
3712                                    else {
3713                                            DLFileVersion dlFileVersion = list.get(0);
3714    
3715                                            result = dlFileVersion;
3716    
3717                                            cacheResult(dlFileVersion);
3718    
3719                                            if ((dlFileVersion.getFileEntryId() != fileEntryId) ||
3720                                                            (dlFileVersion.getVersion() == null) ||
3721                                                            !dlFileVersion.getVersion().equals(version)) {
3722                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_F_V,
3723                                                            finderArgs, dlFileVersion);
3724                                            }
3725                                    }
3726                            }
3727                            catch (Exception e) {
3728                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_F_V, finderArgs);
3729    
3730                                    throw processException(e);
3731                            }
3732                            finally {
3733                                    closeSession(session);
3734                            }
3735                    }
3736    
3737                    if (result instanceof List<?>) {
3738                            return null;
3739                    }
3740                    else {
3741                            return (DLFileVersion)result;
3742                    }
3743            }
3744    
3745            /**
3746             * Removes the document library file version where fileEntryId = &#63; and version = &#63; from the database.
3747             *
3748             * @param fileEntryId the file entry ID
3749             * @param version the version
3750             * @return the document library file version that was removed
3751             */
3752            @Override
3753            public DLFileVersion removeByF_V(long fileEntryId, String version)
3754                    throws NoSuchFileVersionException {
3755                    DLFileVersion dlFileVersion = findByF_V(fileEntryId, version);
3756    
3757                    return remove(dlFileVersion);
3758            }
3759    
3760            /**
3761             * Returns the number of document library file versions where fileEntryId = &#63; and version = &#63;.
3762             *
3763             * @param fileEntryId the file entry ID
3764             * @param version the version
3765             * @return the number of matching document library file versions
3766             */
3767            @Override
3768            public int countByF_V(long fileEntryId, String version) {
3769                    FinderPath finderPath = FINDER_PATH_COUNT_BY_F_V;
3770    
3771                    Object[] finderArgs = new Object[] { fileEntryId, version };
3772    
3773                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3774    
3775                    if (count == null) {
3776                            StringBundler query = new StringBundler(3);
3777    
3778                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
3779    
3780                            query.append(_FINDER_COLUMN_F_V_FILEENTRYID_2);
3781    
3782                            boolean bindVersion = false;
3783    
3784                            if (version == null) {
3785                                    query.append(_FINDER_COLUMN_F_V_VERSION_1);
3786                            }
3787                            else if (version.equals(StringPool.BLANK)) {
3788                                    query.append(_FINDER_COLUMN_F_V_VERSION_3);
3789                            }
3790                            else {
3791                                    bindVersion = true;
3792    
3793                                    query.append(_FINDER_COLUMN_F_V_VERSION_2);
3794                            }
3795    
3796                            String sql = query.toString();
3797    
3798                            Session session = null;
3799    
3800                            try {
3801                                    session = openSession();
3802    
3803                                    Query q = session.createQuery(sql);
3804    
3805                                    QueryPos qPos = QueryPos.getInstance(q);
3806    
3807                                    qPos.add(fileEntryId);
3808    
3809                                    if (bindVersion) {
3810                                            qPos.add(version);
3811                                    }
3812    
3813                                    count = (Long)q.uniqueResult();
3814    
3815                                    finderCache.putResult(finderPath, finderArgs, count);
3816                            }
3817                            catch (Exception e) {
3818                                    finderCache.removeResult(finderPath, finderArgs);
3819    
3820                                    throw processException(e);
3821                            }
3822                            finally {
3823                                    closeSession(session);
3824                            }
3825                    }
3826    
3827                    return count.intValue();
3828            }
3829    
3830            private static final String _FINDER_COLUMN_F_V_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ? AND ";
3831            private static final String _FINDER_COLUMN_F_V_VERSION_1 = "dlFileVersion.version IS NULL";
3832            private static final String _FINDER_COLUMN_F_V_VERSION_2 = "dlFileVersion.version = ?";
3833            private static final String _FINDER_COLUMN_F_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = '')";
3834            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3835                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3836                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3837                            "findByF_S",
3838                            new String[] {
3839                                    Long.class.getName(), Integer.class.getName(),
3840                                    
3841                            Integer.class.getName(), Integer.class.getName(),
3842                                    OrderByComparator.class.getName()
3843                            });
3844            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3845                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3846                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3847                            "findByF_S",
3848                            new String[] { Long.class.getName(), Integer.class.getName() },
3849                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
3850                            DLFileVersionModelImpl.STATUS_COLUMN_BITMASK |
3851                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
3852            public static final FinderPath FINDER_PATH_COUNT_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3853                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3854                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByF_S",
3855                            new String[] { Long.class.getName(), Integer.class.getName() });
3856    
3857            /**
3858             * Returns all the document library file versions where fileEntryId = &#63; and status = &#63;.
3859             *
3860             * @param fileEntryId the file entry ID
3861             * @param status the status
3862             * @return the matching document library file versions
3863             */
3864            @Override
3865            public List<DLFileVersion> findByF_S(long fileEntryId, int status) {
3866                    return findByF_S(fileEntryId, status, QueryUtil.ALL_POS,
3867                            QueryUtil.ALL_POS, null);
3868            }
3869    
3870            /**
3871             * Returns a range of all the document library file versions where fileEntryId = &#63; and status = &#63;.
3872             *
3873             * <p>
3874             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3875             * </p>
3876             *
3877             * @param fileEntryId the file entry ID
3878             * @param status the status
3879             * @param start the lower bound of the range of document library file versions
3880             * @param end the upper bound of the range of document library file versions (not inclusive)
3881             * @return the range of matching document library file versions
3882             */
3883            @Override
3884            public List<DLFileVersion> findByF_S(long fileEntryId, int status,
3885                    int start, int end) {
3886                    return findByF_S(fileEntryId, status, start, end, null);
3887            }
3888    
3889            /**
3890             * Returns an ordered range of all the document library file versions where fileEntryId = &#63; and status = &#63;.
3891             *
3892             * <p>
3893             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3894             * </p>
3895             *
3896             * @param fileEntryId the file entry ID
3897             * @param status the status
3898             * @param start the lower bound of the range of document library file versions
3899             * @param end the upper bound of the range of document library file versions (not inclusive)
3900             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3901             * @return the ordered range of matching document library file versions
3902             */
3903            @Override
3904            public List<DLFileVersion> findByF_S(long fileEntryId, int status,
3905                    int start, int end, OrderByComparator<DLFileVersion> orderByComparator) {
3906                    return findByF_S(fileEntryId, status, start, end, orderByComparator,
3907                            true);
3908            }
3909    
3910            /**
3911             * Returns an ordered range of all the document library file versions where fileEntryId = &#63; and status = &#63;.
3912             *
3913             * <p>
3914             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3915             * </p>
3916             *
3917             * @param fileEntryId the file entry ID
3918             * @param status the status
3919             * @param start the lower bound of the range of document library file versions
3920             * @param end the upper bound of the range of document library file versions (not inclusive)
3921             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3922             * @param retrieveFromCache whether to retrieve from the finder cache
3923             * @return the ordered range of matching document library file versions
3924             */
3925            @Override
3926            public List<DLFileVersion> findByF_S(long fileEntryId, int status,
3927                    int start, int end, OrderByComparator<DLFileVersion> orderByComparator,
3928                    boolean retrieveFromCache) {
3929                    boolean pagination = true;
3930                    FinderPath finderPath = null;
3931                    Object[] finderArgs = null;
3932    
3933                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3934                                    (orderByComparator == null)) {
3935                            pagination = false;
3936                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S;
3937                            finderArgs = new Object[] { fileEntryId, status };
3938                    }
3939                    else {
3940                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_F_S;
3941                            finderArgs = new Object[] {
3942                                            fileEntryId, status,
3943                                            
3944                                            start, end, orderByComparator
3945                                    };
3946                    }
3947    
3948                    List<DLFileVersion> list = null;
3949    
3950                    if (retrieveFromCache) {
3951                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
3952                                            finderArgs, this);
3953    
3954                            if ((list != null) && !list.isEmpty()) {
3955                                    for (DLFileVersion dlFileVersion : list) {
3956                                            if ((fileEntryId != dlFileVersion.getFileEntryId()) ||
3957                                                            (status != dlFileVersion.getStatus())) {
3958                                                    list = null;
3959    
3960                                                    break;
3961                                            }
3962                                    }
3963                            }
3964                    }
3965    
3966                    if (list == null) {
3967                            StringBundler query = null;
3968    
3969                            if (orderByComparator != null) {
3970                                    query = new StringBundler(4 +
3971                                                    (orderByComparator.getOrderByFields().length * 3));
3972                            }
3973                            else {
3974                                    query = new StringBundler(4);
3975                            }
3976    
3977                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3978    
3979                            query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
3980    
3981                            query.append(_FINDER_COLUMN_F_S_STATUS_2);
3982    
3983                            if (orderByComparator != null) {
3984                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3985                                            orderByComparator);
3986                            }
3987                            else
3988                             if (pagination) {
3989                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3990                            }
3991    
3992                            String sql = query.toString();
3993    
3994                            Session session = null;
3995    
3996                            try {
3997                                    session = openSession();
3998    
3999                                    Query q = session.createQuery(sql);
4000    
4001                                    QueryPos qPos = QueryPos.getInstance(q);
4002    
4003                                    qPos.add(fileEntryId);
4004    
4005                                    qPos.add(status);
4006    
4007                                    if (!pagination) {
4008                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4009                                                            start, end, false);
4010    
4011                                            Collections.sort(list);
4012    
4013                                            list = Collections.unmodifiableList(list);
4014                                    }
4015                                    else {
4016                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4017                                                            start, end);
4018                                    }
4019    
4020                                    cacheResult(list);
4021    
4022                                    finderCache.putResult(finderPath, finderArgs, list);
4023                            }
4024                            catch (Exception e) {
4025                                    finderCache.removeResult(finderPath, finderArgs);
4026    
4027                                    throw processException(e);
4028                            }
4029                            finally {
4030                                    closeSession(session);
4031                            }
4032                    }
4033    
4034                    return list;
4035            }
4036    
4037            /**
4038             * Returns the first document library file version in the ordered set where fileEntryId = &#63; and status = &#63;.
4039             *
4040             * @param fileEntryId the file entry ID
4041             * @param status the status
4042             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4043             * @return the first matching document library file version
4044             * @throws NoSuchFileVersionException if a matching document library file version could not be found
4045             */
4046            @Override
4047            public DLFileVersion findByF_S_First(long fileEntryId, int status,
4048                    OrderByComparator<DLFileVersion> orderByComparator)
4049                    throws NoSuchFileVersionException {
4050                    DLFileVersion dlFileVersion = fetchByF_S_First(fileEntryId, status,
4051                                    orderByComparator);
4052    
4053                    if (dlFileVersion != null) {
4054                            return dlFileVersion;
4055                    }
4056    
4057                    StringBundler msg = new StringBundler(6);
4058    
4059                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4060    
4061                    msg.append("fileEntryId=");
4062                    msg.append(fileEntryId);
4063    
4064                    msg.append(", status=");
4065                    msg.append(status);
4066    
4067                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4068    
4069                    throw new NoSuchFileVersionException(msg.toString());
4070            }
4071    
4072            /**
4073             * Returns the first document library file version in the ordered set where fileEntryId = &#63; and status = &#63;.
4074             *
4075             * @param fileEntryId the file entry ID
4076             * @param status the status
4077             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4078             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
4079             */
4080            @Override
4081            public DLFileVersion fetchByF_S_First(long fileEntryId, int status,
4082                    OrderByComparator<DLFileVersion> orderByComparator) {
4083                    List<DLFileVersion> list = findByF_S(fileEntryId, status, 0, 1,
4084                                    orderByComparator);
4085    
4086                    if (!list.isEmpty()) {
4087                            return list.get(0);
4088                    }
4089    
4090                    return null;
4091            }
4092    
4093            /**
4094             * Returns the last document library file version in the ordered set where fileEntryId = &#63; and status = &#63;.
4095             *
4096             * @param fileEntryId the file entry ID
4097             * @param status the status
4098             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4099             * @return the last matching document library file version
4100             * @throws NoSuchFileVersionException if a matching document library file version could not be found
4101             */
4102            @Override
4103            public DLFileVersion findByF_S_Last(long fileEntryId, int status,
4104                    OrderByComparator<DLFileVersion> orderByComparator)
4105                    throws NoSuchFileVersionException {
4106                    DLFileVersion dlFileVersion = fetchByF_S_Last(fileEntryId, status,
4107                                    orderByComparator);
4108    
4109                    if (dlFileVersion != null) {
4110                            return dlFileVersion;
4111                    }
4112    
4113                    StringBundler msg = new StringBundler(6);
4114    
4115                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4116    
4117                    msg.append("fileEntryId=");
4118                    msg.append(fileEntryId);
4119    
4120                    msg.append(", status=");
4121                    msg.append(status);
4122    
4123                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4124    
4125                    throw new NoSuchFileVersionException(msg.toString());
4126            }
4127    
4128            /**
4129             * Returns the last document library file version in the ordered set where fileEntryId = &#63; and status = &#63;.
4130             *
4131             * @param fileEntryId the file entry ID
4132             * @param status the status
4133             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4134             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
4135             */
4136            @Override
4137            public DLFileVersion fetchByF_S_Last(long fileEntryId, int status,
4138                    OrderByComparator<DLFileVersion> orderByComparator) {
4139                    int count = countByF_S(fileEntryId, status);
4140    
4141                    if (count == 0) {
4142                            return null;
4143                    }
4144    
4145                    List<DLFileVersion> list = findByF_S(fileEntryId, status, count - 1,
4146                                    count, orderByComparator);
4147    
4148                    if (!list.isEmpty()) {
4149                            return list.get(0);
4150                    }
4151    
4152                    return null;
4153            }
4154    
4155            /**
4156             * Returns the document library file versions before and after the current document library file version in the ordered set where fileEntryId = &#63; and status = &#63;.
4157             *
4158             * @param fileVersionId the primary key of the current document library file version
4159             * @param fileEntryId the file entry ID
4160             * @param status the status
4161             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4162             * @return the previous, current, and next document library file version
4163             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
4164             */
4165            @Override
4166            public DLFileVersion[] findByF_S_PrevAndNext(long fileVersionId,
4167                    long fileEntryId, int status,
4168                    OrderByComparator<DLFileVersion> orderByComparator)
4169                    throws NoSuchFileVersionException {
4170                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
4171    
4172                    Session session = null;
4173    
4174                    try {
4175                            session = openSession();
4176    
4177                            DLFileVersion[] array = new DLFileVersionImpl[3];
4178    
4179                            array[0] = getByF_S_PrevAndNext(session, dlFileVersion,
4180                                            fileEntryId, status, orderByComparator, true);
4181    
4182                            array[1] = dlFileVersion;
4183    
4184                            array[2] = getByF_S_PrevAndNext(session, dlFileVersion,
4185                                            fileEntryId, status, orderByComparator, false);
4186    
4187                            return array;
4188                    }
4189                    catch (Exception e) {
4190                            throw processException(e);
4191                    }
4192                    finally {
4193                            closeSession(session);
4194                    }
4195            }
4196    
4197            protected DLFileVersion getByF_S_PrevAndNext(Session session,
4198                    DLFileVersion dlFileVersion, long fileEntryId, int status,
4199                    OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
4200                    StringBundler query = null;
4201    
4202                    if (orderByComparator != null) {
4203                            query = new StringBundler(6 +
4204                                            (orderByComparator.getOrderByFields().length * 6));
4205                    }
4206                    else {
4207                            query = new StringBundler(3);
4208                    }
4209    
4210                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
4211    
4212                    query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
4213    
4214                    query.append(_FINDER_COLUMN_F_S_STATUS_2);
4215    
4216                    if (orderByComparator != null) {
4217                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4218    
4219                            if (orderByConditionFields.length > 0) {
4220                                    query.append(WHERE_AND);
4221                            }
4222    
4223                            for (int i = 0; i < orderByConditionFields.length; i++) {
4224                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4225                                    query.append(orderByConditionFields[i]);
4226    
4227                                    if ((i + 1) < orderByConditionFields.length) {
4228                                            if (orderByComparator.isAscending() ^ previous) {
4229                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4230                                            }
4231                                            else {
4232                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4233                                            }
4234                                    }
4235                                    else {
4236                                            if (orderByComparator.isAscending() ^ previous) {
4237                                                    query.append(WHERE_GREATER_THAN);
4238                                            }
4239                                            else {
4240                                                    query.append(WHERE_LESSER_THAN);
4241                                            }
4242                                    }
4243                            }
4244    
4245                            query.append(ORDER_BY_CLAUSE);
4246    
4247                            String[] orderByFields = orderByComparator.getOrderByFields();
4248    
4249                            for (int i = 0; i < orderByFields.length; i++) {
4250                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4251                                    query.append(orderByFields[i]);
4252    
4253                                    if ((i + 1) < orderByFields.length) {
4254                                            if (orderByComparator.isAscending() ^ previous) {
4255                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4256                                            }
4257                                            else {
4258                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4259                                            }
4260                                    }
4261                                    else {
4262                                            if (orderByComparator.isAscending() ^ previous) {
4263                                                    query.append(ORDER_BY_ASC);
4264                                            }
4265                                            else {
4266                                                    query.append(ORDER_BY_DESC);
4267                                            }
4268                                    }
4269                            }
4270                    }
4271                    else {
4272                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
4273                    }
4274    
4275                    String sql = query.toString();
4276    
4277                    Query q = session.createQuery(sql);
4278    
4279                    q.setFirstResult(0);
4280                    q.setMaxResults(2);
4281    
4282                    QueryPos qPos = QueryPos.getInstance(q);
4283    
4284                    qPos.add(fileEntryId);
4285    
4286                    qPos.add(status);
4287    
4288                    if (orderByComparator != null) {
4289                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
4290    
4291                            for (Object value : values) {
4292                                    qPos.add(value);
4293                            }
4294                    }
4295    
4296                    List<DLFileVersion> list = q.list();
4297    
4298                    if (list.size() == 2) {
4299                            return list.get(1);
4300                    }
4301                    else {
4302                            return null;
4303                    }
4304            }
4305    
4306            /**
4307             * Removes all the document library file versions where fileEntryId = &#63; and status = &#63; from the database.
4308             *
4309             * @param fileEntryId the file entry ID
4310             * @param status the status
4311             */
4312            @Override
4313            public void removeByF_S(long fileEntryId, int status) {
4314                    for (DLFileVersion dlFileVersion : findByF_S(fileEntryId, status,
4315                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4316                            remove(dlFileVersion);
4317                    }
4318            }
4319    
4320            /**
4321             * Returns the number of document library file versions where fileEntryId = &#63; and status = &#63;.
4322             *
4323             * @param fileEntryId the file entry ID
4324             * @param status the status
4325             * @return the number of matching document library file versions
4326             */
4327            @Override
4328            public int countByF_S(long fileEntryId, int status) {
4329                    FinderPath finderPath = FINDER_PATH_COUNT_BY_F_S;
4330    
4331                    Object[] finderArgs = new Object[] { fileEntryId, status };
4332    
4333                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4334    
4335                    if (count == null) {
4336                            StringBundler query = new StringBundler(3);
4337    
4338                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4339    
4340                            query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
4341    
4342                            query.append(_FINDER_COLUMN_F_S_STATUS_2);
4343    
4344                            String sql = query.toString();
4345    
4346                            Session session = null;
4347    
4348                            try {
4349                                    session = openSession();
4350    
4351                                    Query q = session.createQuery(sql);
4352    
4353                                    QueryPos qPos = QueryPos.getInstance(q);
4354    
4355                                    qPos.add(fileEntryId);
4356    
4357                                    qPos.add(status);
4358    
4359                                    count = (Long)q.uniqueResult();
4360    
4361                                    finderCache.putResult(finderPath, finderArgs, count);
4362                            }
4363                            catch (Exception e) {
4364                                    finderCache.removeResult(finderPath, finderArgs);
4365    
4366                                    throw processException(e);
4367                            }
4368                            finally {
4369                                    closeSession(session);
4370                            }
4371                    }
4372    
4373                    return count.intValue();
4374            }
4375    
4376            private static final String _FINDER_COLUMN_F_S_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ? AND ";
4377            private static final String _FINDER_COLUMN_F_S_STATUS_2 = "dlFileVersion.status = ?";
4378            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4379                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
4380                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4381                            "findByG_F_S",
4382                            new String[] {
4383                                    Long.class.getName(), Long.class.getName(),
4384                                    Integer.class.getName(),
4385                                    
4386                            Integer.class.getName(), Integer.class.getName(),
4387                                    OrderByComparator.class.getName()
4388                            });
4389            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4390                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
4391                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4392                            "findByG_F_S",
4393                            new String[] {
4394                                    Long.class.getName(), Long.class.getName(),
4395                                    Integer.class.getName()
4396                            },
4397                            DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK |
4398                            DLFileVersionModelImpl.FOLDERID_COLUMN_BITMASK |
4399                            DLFileVersionModelImpl.STATUS_COLUMN_BITMASK |
4400                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
4401                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
4402            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4403                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
4404                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F_S",
4405                            new String[] {
4406                                    Long.class.getName(), Long.class.getName(),
4407                                    Integer.class.getName()
4408                            });
4409    
4410            /**
4411             * Returns all the document library file versions where groupId = &#63; and folderId = &#63; and status = &#63;.
4412             *
4413             * @param groupId the group ID
4414             * @param folderId the folder ID
4415             * @param status the status
4416             * @return the matching document library file versions
4417             */
4418            @Override
4419            public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
4420                    int status) {
4421                    return findByG_F_S(groupId, folderId, status, QueryUtil.ALL_POS,
4422                            QueryUtil.ALL_POS, null);
4423            }
4424    
4425            /**
4426             * Returns a range of all the document library file versions where groupId = &#63; and folderId = &#63; and status = &#63;.
4427             *
4428             * <p>
4429             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4430             * </p>
4431             *
4432             * @param groupId the group ID
4433             * @param folderId the folder ID
4434             * @param status the status
4435             * @param start the lower bound of the range of document library file versions
4436             * @param end the upper bound of the range of document library file versions (not inclusive)
4437             * @return the range of matching document library file versions
4438             */
4439            @Override
4440            public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
4441                    int status, int start, int end) {
4442                    return findByG_F_S(groupId, folderId, status, start, end, null);
4443            }
4444    
4445            /**
4446             * Returns an ordered range of all the document library file versions where groupId = &#63; and folderId = &#63; and status = &#63;.
4447             *
4448             * <p>
4449             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4450             * </p>
4451             *
4452             * @param groupId the group ID
4453             * @param folderId the folder ID
4454             * @param status the status
4455             * @param start the lower bound of the range of document library file versions
4456             * @param end the upper bound of the range of document library file versions (not inclusive)
4457             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4458             * @return the ordered range of matching document library file versions
4459             */
4460            @Override
4461            public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
4462                    int status, int start, int end,
4463                    OrderByComparator<DLFileVersion> orderByComparator) {
4464                    return findByG_F_S(groupId, folderId, status, start, end,
4465                            orderByComparator, true);
4466            }
4467    
4468            /**
4469             * Returns an ordered range of all the document library file versions where groupId = &#63; and folderId = &#63; and status = &#63;.
4470             *
4471             * <p>
4472             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4473             * </p>
4474             *
4475             * @param groupId the group ID
4476             * @param folderId the folder ID
4477             * @param status the status
4478             * @param start the lower bound of the range of document library file versions
4479             * @param end the upper bound of the range of document library file versions (not inclusive)
4480             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4481             * @param retrieveFromCache whether to retrieve from the finder cache
4482             * @return the ordered range of matching document library file versions
4483             */
4484            @Override
4485            public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
4486                    int status, int start, int end,
4487                    OrderByComparator<DLFileVersion> orderByComparator,
4488                    boolean retrieveFromCache) {
4489                    boolean pagination = true;
4490                    FinderPath finderPath = null;
4491                    Object[] finderArgs = null;
4492    
4493                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4494                                    (orderByComparator == null)) {
4495                            pagination = false;
4496                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S;
4497                            finderArgs = new Object[] { groupId, folderId, status };
4498                    }
4499                    else {
4500                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S;
4501                            finderArgs = new Object[] {
4502                                            groupId, folderId, status,
4503                                            
4504                                            start, end, orderByComparator
4505                                    };
4506                    }
4507    
4508                    List<DLFileVersion> list = null;
4509    
4510                    if (retrieveFromCache) {
4511                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
4512                                            finderArgs, this);
4513    
4514                            if ((list != null) && !list.isEmpty()) {
4515                                    for (DLFileVersion dlFileVersion : list) {
4516                                            if ((groupId != dlFileVersion.getGroupId()) ||
4517                                                            (folderId != dlFileVersion.getFolderId()) ||
4518                                                            (status != dlFileVersion.getStatus())) {
4519                                                    list = null;
4520    
4521                                                    break;
4522                                            }
4523                                    }
4524                            }
4525                    }
4526    
4527                    if (list == null) {
4528                            StringBundler query = null;
4529    
4530                            if (orderByComparator != null) {
4531                                    query = new StringBundler(5 +
4532                                                    (orderByComparator.getOrderByFields().length * 3));
4533                            }
4534                            else {
4535                                    query = new StringBundler(5);
4536                            }
4537    
4538                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
4539    
4540                            query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
4541    
4542                            query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
4543    
4544                            query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
4545    
4546                            if (orderByComparator != null) {
4547                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4548                                            orderByComparator);
4549                            }
4550                            else
4551                             if (pagination) {
4552                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
4553                            }
4554    
4555                            String sql = query.toString();
4556    
4557                            Session session = null;
4558    
4559                            try {
4560                                    session = openSession();
4561    
4562                                    Query q = session.createQuery(sql);
4563    
4564                                    QueryPos qPos = QueryPos.getInstance(q);
4565    
4566                                    qPos.add(groupId);
4567    
4568                                    qPos.add(folderId);
4569    
4570                                    qPos.add(status);
4571    
4572                                    if (!pagination) {
4573                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4574                                                            start, end, false);
4575    
4576                                            Collections.sort(list);
4577    
4578                                            list = Collections.unmodifiableList(list);
4579                                    }
4580                                    else {
4581                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4582                                                            start, end);
4583                                    }
4584    
4585                                    cacheResult(list);
4586    
4587                                    finderCache.putResult(finderPath, finderArgs, list);
4588                            }
4589                            catch (Exception e) {
4590                                    finderCache.removeResult(finderPath, finderArgs);
4591    
4592                                    throw processException(e);
4593                            }
4594                            finally {
4595                                    closeSession(session);
4596                            }
4597                    }
4598    
4599                    return list;
4600            }
4601    
4602            /**
4603             * Returns the first document library file version in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
4604             *
4605             * @param groupId the group ID
4606             * @param folderId the folder ID
4607             * @param status the status
4608             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4609             * @return the first matching document library file version
4610             * @throws NoSuchFileVersionException if a matching document library file version could not be found
4611             */
4612            @Override
4613            public DLFileVersion findByG_F_S_First(long groupId, long folderId,
4614                    int status, OrderByComparator<DLFileVersion> orderByComparator)
4615                    throws NoSuchFileVersionException {
4616                    DLFileVersion dlFileVersion = fetchByG_F_S_First(groupId, folderId,
4617                                    status, orderByComparator);
4618    
4619                    if (dlFileVersion != null) {
4620                            return dlFileVersion;
4621                    }
4622    
4623                    StringBundler msg = new StringBundler(8);
4624    
4625                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4626    
4627                    msg.append("groupId=");
4628                    msg.append(groupId);
4629    
4630                    msg.append(", folderId=");
4631                    msg.append(folderId);
4632    
4633                    msg.append(", status=");
4634                    msg.append(status);
4635    
4636                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4637    
4638                    throw new NoSuchFileVersionException(msg.toString());
4639            }
4640    
4641            /**
4642             * Returns the first document library file version in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
4643             *
4644             * @param groupId the group ID
4645             * @param folderId the folder ID
4646             * @param status the status
4647             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4648             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
4649             */
4650            @Override
4651            public DLFileVersion fetchByG_F_S_First(long groupId, long folderId,
4652                    int status, OrderByComparator<DLFileVersion> orderByComparator) {
4653                    List<DLFileVersion> list = findByG_F_S(groupId, folderId, status, 0, 1,
4654                                    orderByComparator);
4655    
4656                    if (!list.isEmpty()) {
4657                            return list.get(0);
4658                    }
4659    
4660                    return null;
4661            }
4662    
4663            /**
4664             * Returns the last document library file version in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
4665             *
4666             * @param groupId the group ID
4667             * @param folderId the folder ID
4668             * @param status the status
4669             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4670             * @return the last matching document library file version
4671             * @throws NoSuchFileVersionException if a matching document library file version could not be found
4672             */
4673            @Override
4674            public DLFileVersion findByG_F_S_Last(long groupId, long folderId,
4675                    int status, OrderByComparator<DLFileVersion> orderByComparator)
4676                    throws NoSuchFileVersionException {
4677                    DLFileVersion dlFileVersion = fetchByG_F_S_Last(groupId, folderId,
4678                                    status, orderByComparator);
4679    
4680                    if (dlFileVersion != null) {
4681                            return dlFileVersion;
4682                    }
4683    
4684                    StringBundler msg = new StringBundler(8);
4685    
4686                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4687    
4688                    msg.append("groupId=");
4689                    msg.append(groupId);
4690    
4691                    msg.append(", folderId=");
4692                    msg.append(folderId);
4693    
4694                    msg.append(", status=");
4695                    msg.append(status);
4696    
4697                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4698    
4699                    throw new NoSuchFileVersionException(msg.toString());
4700            }
4701    
4702            /**
4703             * Returns the last document library file version in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
4704             *
4705             * @param groupId the group ID
4706             * @param folderId the folder ID
4707             * @param status the status
4708             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4709             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
4710             */
4711            @Override
4712            public DLFileVersion fetchByG_F_S_Last(long groupId, long folderId,
4713                    int status, OrderByComparator<DLFileVersion> orderByComparator) {
4714                    int count = countByG_F_S(groupId, folderId, status);
4715    
4716                    if (count == 0) {
4717                            return null;
4718                    }
4719    
4720                    List<DLFileVersion> list = findByG_F_S(groupId, folderId, status,
4721                                    count - 1, count, orderByComparator);
4722    
4723                    if (!list.isEmpty()) {
4724                            return list.get(0);
4725                    }
4726    
4727                    return null;
4728            }
4729    
4730            /**
4731             * Returns the document library file versions before and after the current document library file version in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
4732             *
4733             * @param fileVersionId the primary key of the current document library file version
4734             * @param groupId the group ID
4735             * @param folderId the folder ID
4736             * @param status the status
4737             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4738             * @return the previous, current, and next document library file version
4739             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
4740             */
4741            @Override
4742            public DLFileVersion[] findByG_F_S_PrevAndNext(long fileVersionId,
4743                    long groupId, long folderId, int status,
4744                    OrderByComparator<DLFileVersion> orderByComparator)
4745                    throws NoSuchFileVersionException {
4746                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
4747    
4748                    Session session = null;
4749    
4750                    try {
4751                            session = openSession();
4752    
4753                            DLFileVersion[] array = new DLFileVersionImpl[3];
4754    
4755                            array[0] = getByG_F_S_PrevAndNext(session, dlFileVersion, groupId,
4756                                            folderId, status, orderByComparator, true);
4757    
4758                            array[1] = dlFileVersion;
4759    
4760                            array[2] = getByG_F_S_PrevAndNext(session, dlFileVersion, groupId,
4761                                            folderId, status, orderByComparator, false);
4762    
4763                            return array;
4764                    }
4765                    catch (Exception e) {
4766                            throw processException(e);
4767                    }
4768                    finally {
4769                            closeSession(session);
4770                    }
4771            }
4772    
4773            protected DLFileVersion getByG_F_S_PrevAndNext(Session session,
4774                    DLFileVersion dlFileVersion, long groupId, long folderId, int status,
4775                    OrderByComparator<DLFileVersion> orderByComparator, boolean previous) {
4776                    StringBundler query = null;
4777    
4778                    if (orderByComparator != null) {
4779                            query = new StringBundler(6 +
4780                                            (orderByComparator.getOrderByFields().length * 6));
4781                    }
4782                    else {
4783                            query = new StringBundler(3);
4784                    }
4785    
4786                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
4787    
4788                    query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
4789    
4790                    query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
4791    
4792                    query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
4793    
4794                    if (orderByComparator != null) {
4795                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4796    
4797                            if (orderByConditionFields.length > 0) {
4798                                    query.append(WHERE_AND);
4799                            }
4800    
4801                            for (int i = 0; i < orderByConditionFields.length; i++) {
4802                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4803                                    query.append(orderByConditionFields[i]);
4804    
4805                                    if ((i + 1) < orderByConditionFields.length) {
4806                                            if (orderByComparator.isAscending() ^ previous) {
4807                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4808                                            }
4809                                            else {
4810                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4811                                            }
4812                                    }
4813                                    else {
4814                                            if (orderByComparator.isAscending() ^ previous) {
4815                                                    query.append(WHERE_GREATER_THAN);
4816                                            }
4817                                            else {
4818                                                    query.append(WHERE_LESSER_THAN);
4819                                            }
4820                                    }
4821                            }
4822    
4823                            query.append(ORDER_BY_CLAUSE);
4824    
4825                            String[] orderByFields = orderByComparator.getOrderByFields();
4826    
4827                            for (int i = 0; i < orderByFields.length; i++) {
4828                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4829                                    query.append(orderByFields[i]);
4830    
4831                                    if ((i + 1) < orderByFields.length) {
4832                                            if (orderByComparator.isAscending() ^ previous) {
4833                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4834                                            }
4835                                            else {
4836                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4837                                            }
4838                                    }
4839                                    else {
4840                                            if (orderByComparator.isAscending() ^ previous) {
4841                                                    query.append(ORDER_BY_ASC);
4842                                            }
4843                                            else {
4844                                                    query.append(ORDER_BY_DESC);
4845                                            }
4846                                    }
4847                            }
4848                    }
4849                    else {
4850                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
4851                    }
4852    
4853                    String sql = query.toString();
4854    
4855                    Query q = session.createQuery(sql);
4856    
4857                    q.setFirstResult(0);
4858                    q.setMaxResults(2);
4859    
4860                    QueryPos qPos = QueryPos.getInstance(q);
4861    
4862                    qPos.add(groupId);
4863    
4864                    qPos.add(folderId);
4865    
4866                    qPos.add(status);
4867    
4868                    if (orderByComparator != null) {
4869                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
4870    
4871                            for (Object value : values) {
4872                                    qPos.add(value);
4873                            }
4874                    }
4875    
4876                    List<DLFileVersion> list = q.list();
4877    
4878                    if (list.size() == 2) {
4879                            return list.get(1);
4880                    }
4881                    else {
4882                            return null;
4883                    }
4884            }
4885    
4886            /**
4887             * Removes all the document library file versions where groupId = &#63; and folderId = &#63; and status = &#63; from the database.
4888             *
4889             * @param groupId the group ID
4890             * @param folderId the folder ID
4891             * @param status the status
4892             */
4893            @Override
4894            public void removeByG_F_S(long groupId, long folderId, int status) {
4895                    for (DLFileVersion dlFileVersion : findByG_F_S(groupId, folderId,
4896                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4897                            remove(dlFileVersion);
4898                    }
4899            }
4900    
4901            /**
4902             * Returns the number of document library file versions where groupId = &#63; and folderId = &#63; and status = &#63;.
4903             *
4904             * @param groupId the group ID
4905             * @param folderId the folder ID
4906             * @param status the status
4907             * @return the number of matching document library file versions
4908             */
4909            @Override
4910            public int countByG_F_S(long groupId, long folderId, int status) {
4911                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_F_S;
4912    
4913                    Object[] finderArgs = new Object[] { groupId, folderId, status };
4914    
4915                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4916    
4917                    if (count == null) {
4918                            StringBundler query = new StringBundler(4);
4919    
4920                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4921    
4922                            query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
4923    
4924                            query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
4925    
4926                            query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
4927    
4928                            String sql = query.toString();
4929    
4930                            Session session = null;
4931    
4932                            try {
4933                                    session = openSession();
4934    
4935                                    Query q = session.createQuery(sql);
4936    
4937                                    QueryPos qPos = QueryPos.getInstance(q);
4938    
4939                                    qPos.add(groupId);
4940    
4941                                    qPos.add(folderId);
4942    
4943                                    qPos.add(status);
4944    
4945                                    count = (Long)q.uniqueResult();
4946    
4947                                    finderCache.putResult(finderPath, finderArgs, count);
4948                            }
4949                            catch (Exception e) {
4950                                    finderCache.removeResult(finderPath, finderArgs);
4951    
4952                                    throw processException(e);
4953                            }
4954                            finally {
4955                                    closeSession(session);
4956                            }
4957                    }
4958    
4959                    return count.intValue();
4960            }
4961    
4962            private static final String _FINDER_COLUMN_G_F_S_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
4963            private static final String _FINDER_COLUMN_G_F_S_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
4964            private static final String _FINDER_COLUMN_G_F_S_STATUS_2 = "dlFileVersion.status = ?";
4965            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_T_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4966                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
4967                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4968                            "findByG_F_T_V",
4969                            new String[] {
4970                                    Long.class.getName(), Long.class.getName(),
4971                                    String.class.getName(), String.class.getName(),
4972                                    
4973                            Integer.class.getName(), Integer.class.getName(),
4974                                    OrderByComparator.class.getName()
4975                            });
4976            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V =
4977                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4978                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
4979                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4980                            "findByG_F_T_V",
4981                            new String[] {
4982                                    Long.class.getName(), Long.class.getName(),
4983                                    String.class.getName(), String.class.getName()
4984                            },
4985                            DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK |
4986                            DLFileVersionModelImpl.FOLDERID_COLUMN_BITMASK |
4987                            DLFileVersionModelImpl.TITLE_COLUMN_BITMASK |
4988                            DLFileVersionModelImpl.VERSION_COLUMN_BITMASK |
4989                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
4990                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
4991            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_T_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4992                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
4993                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F_T_V",
4994                            new String[] {
4995                                    Long.class.getName(), Long.class.getName(),
4996                                    String.class.getName(), String.class.getName()
4997                            });
4998    
4999            /**
5000             * Returns all the document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5001             *
5002             * @param groupId the group ID
5003             * @param folderId the folder ID
5004             * @param title the title
5005             * @param version the version
5006             * @return the matching document library file versions
5007             */
5008            @Override
5009            public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
5010                    String title, String version) {
5011                    return findByG_F_T_V(groupId, folderId, title, version,
5012                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5013            }
5014    
5015            /**
5016             * Returns a range of all the document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5017             *
5018             * <p>
5019             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5020             * </p>
5021             *
5022             * @param groupId the group ID
5023             * @param folderId the folder ID
5024             * @param title the title
5025             * @param version the version
5026             * @param start the lower bound of the range of document library file versions
5027             * @param end the upper bound of the range of document library file versions (not inclusive)
5028             * @return the range of matching document library file versions
5029             */
5030            @Override
5031            public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
5032                    String title, String version, int start, int end) {
5033                    return findByG_F_T_V(groupId, folderId, title, version, start, end, null);
5034            }
5035    
5036            /**
5037             * Returns an ordered range of all the document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5038             *
5039             * <p>
5040             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5041             * </p>
5042             *
5043             * @param groupId the group ID
5044             * @param folderId the folder ID
5045             * @param title the title
5046             * @param version the version
5047             * @param start the lower bound of the range of document library file versions
5048             * @param end the upper bound of the range of document library file versions (not inclusive)
5049             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5050             * @return the ordered range of matching document library file versions
5051             */
5052            @Override
5053            public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
5054                    String title, String version, int start, int end,
5055                    OrderByComparator<DLFileVersion> orderByComparator) {
5056                    return findByG_F_T_V(groupId, folderId, title, version, start, end,
5057                            orderByComparator, true);
5058            }
5059    
5060            /**
5061             * Returns an ordered range of all the document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5062             *
5063             * <p>
5064             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5065             * </p>
5066             *
5067             * @param groupId the group ID
5068             * @param folderId the folder ID
5069             * @param title the title
5070             * @param version the version
5071             * @param start the lower bound of the range of document library file versions
5072             * @param end the upper bound of the range of document library file versions (not inclusive)
5073             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5074             * @param retrieveFromCache whether to retrieve from the finder cache
5075             * @return the ordered range of matching document library file versions
5076             */
5077            @Override
5078            public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
5079                    String title, String version, int start, int end,
5080                    OrderByComparator<DLFileVersion> orderByComparator,
5081                    boolean retrieveFromCache) {
5082                    boolean pagination = true;
5083                    FinderPath finderPath = null;
5084                    Object[] finderArgs = null;
5085    
5086                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5087                                    (orderByComparator == null)) {
5088                            pagination = false;
5089                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V;
5090                            finderArgs = new Object[] { groupId, folderId, title, version };
5091                    }
5092                    else {
5093                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_T_V;
5094                            finderArgs = new Object[] {
5095                                            groupId, folderId, title, version,
5096                                            
5097                                            start, end, orderByComparator
5098                                    };
5099                    }
5100    
5101                    List<DLFileVersion> list = null;
5102    
5103                    if (retrieveFromCache) {
5104                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
5105                                            finderArgs, this);
5106    
5107                            if ((list != null) && !list.isEmpty()) {
5108                                    for (DLFileVersion dlFileVersion : list) {
5109                                            if ((groupId != dlFileVersion.getGroupId()) ||
5110                                                            (folderId != dlFileVersion.getFolderId()) ||
5111                                                            !Validator.equals(title, dlFileVersion.getTitle()) ||
5112                                                            !Validator.equals(version,
5113                                                                    dlFileVersion.getVersion())) {
5114                                                    list = null;
5115    
5116                                                    break;
5117                                            }
5118                                    }
5119                            }
5120                    }
5121    
5122                    if (list == null) {
5123                            StringBundler query = null;
5124    
5125                            if (orderByComparator != null) {
5126                                    query = new StringBundler(6 +
5127                                                    (orderByComparator.getOrderByFields().length * 3));
5128                            }
5129                            else {
5130                                    query = new StringBundler(6);
5131                            }
5132    
5133                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
5134    
5135                            query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
5136    
5137                            query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
5138    
5139                            boolean bindTitle = false;
5140    
5141                            if (title == null) {
5142                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
5143                            }
5144                            else if (title.equals(StringPool.BLANK)) {
5145                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
5146                            }
5147                            else {
5148                                    bindTitle = true;
5149    
5150                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
5151                            }
5152    
5153                            boolean bindVersion = false;
5154    
5155                            if (version == null) {
5156                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
5157                            }
5158                            else if (version.equals(StringPool.BLANK)) {
5159                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
5160                            }
5161                            else {
5162                                    bindVersion = true;
5163    
5164                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
5165                            }
5166    
5167                            if (orderByComparator != null) {
5168                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5169                                            orderByComparator);
5170                            }
5171                            else
5172                             if (pagination) {
5173                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
5174                            }
5175    
5176                            String sql = query.toString();
5177    
5178                            Session session = null;
5179    
5180                            try {
5181                                    session = openSession();
5182    
5183                                    Query q = session.createQuery(sql);
5184    
5185                                    QueryPos qPos = QueryPos.getInstance(q);
5186    
5187                                    qPos.add(groupId);
5188    
5189                                    qPos.add(folderId);
5190    
5191                                    if (bindTitle) {
5192                                            qPos.add(title);
5193                                    }
5194    
5195                                    if (bindVersion) {
5196                                            qPos.add(version);
5197                                    }
5198    
5199                                    if (!pagination) {
5200                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
5201                                                            start, end, false);
5202    
5203                                            Collections.sort(list);
5204    
5205                                            list = Collections.unmodifiableList(list);
5206                                    }
5207                                    else {
5208                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
5209                                                            start, end);
5210                                    }
5211    
5212                                    cacheResult(list);
5213    
5214                                    finderCache.putResult(finderPath, finderArgs, list);
5215                            }
5216                            catch (Exception e) {
5217                                    finderCache.removeResult(finderPath, finderArgs);
5218    
5219                                    throw processException(e);
5220                            }
5221                            finally {
5222                                    closeSession(session);
5223                            }
5224                    }
5225    
5226                    return list;
5227            }
5228    
5229            /**
5230             * Returns the first document library file version in the ordered set where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5231             *
5232             * @param groupId the group ID
5233             * @param folderId the folder ID
5234             * @param title the title
5235             * @param version the version
5236             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5237             * @return the first matching document library file version
5238             * @throws NoSuchFileVersionException if a matching document library file version could not be found
5239             */
5240            @Override
5241            public DLFileVersion findByG_F_T_V_First(long groupId, long folderId,
5242                    String title, String version,
5243                    OrderByComparator<DLFileVersion> orderByComparator)
5244                    throws NoSuchFileVersionException {
5245                    DLFileVersion dlFileVersion = fetchByG_F_T_V_First(groupId, folderId,
5246                                    title, version, orderByComparator);
5247    
5248                    if (dlFileVersion != null) {
5249                            return dlFileVersion;
5250                    }
5251    
5252                    StringBundler msg = new StringBundler(10);
5253    
5254                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5255    
5256                    msg.append("groupId=");
5257                    msg.append(groupId);
5258    
5259                    msg.append(", folderId=");
5260                    msg.append(folderId);
5261    
5262                    msg.append(", title=");
5263                    msg.append(title);
5264    
5265                    msg.append(", version=");
5266                    msg.append(version);
5267    
5268                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5269    
5270                    throw new NoSuchFileVersionException(msg.toString());
5271            }
5272    
5273            /**
5274             * Returns the first document library file version in the ordered set where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5275             *
5276             * @param groupId the group ID
5277             * @param folderId the folder ID
5278             * @param title the title
5279             * @param version the version
5280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5281             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
5282             */
5283            @Override
5284            public DLFileVersion fetchByG_F_T_V_First(long groupId, long folderId,
5285                    String title, String version,
5286                    OrderByComparator<DLFileVersion> orderByComparator) {
5287                    List<DLFileVersion> list = findByG_F_T_V(groupId, folderId, title,
5288                                    version, 0, 1, orderByComparator);
5289    
5290                    if (!list.isEmpty()) {
5291                            return list.get(0);
5292                    }
5293    
5294                    return null;
5295            }
5296    
5297            /**
5298             * Returns the last document library file version in the ordered set where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5299             *
5300             * @param groupId the group ID
5301             * @param folderId the folder ID
5302             * @param title the title
5303             * @param version the version
5304             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5305             * @return the last matching document library file version
5306             * @throws NoSuchFileVersionException if a matching document library file version could not be found
5307             */
5308            @Override
5309            public DLFileVersion findByG_F_T_V_Last(long groupId, long folderId,
5310                    String title, String version,
5311                    OrderByComparator<DLFileVersion> orderByComparator)
5312                    throws NoSuchFileVersionException {
5313                    DLFileVersion dlFileVersion = fetchByG_F_T_V_Last(groupId, folderId,
5314                                    title, version, orderByComparator);
5315    
5316                    if (dlFileVersion != null) {
5317                            return dlFileVersion;
5318                    }
5319    
5320                    StringBundler msg = new StringBundler(10);
5321    
5322                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5323    
5324                    msg.append("groupId=");
5325                    msg.append(groupId);
5326    
5327                    msg.append(", folderId=");
5328                    msg.append(folderId);
5329    
5330                    msg.append(", title=");
5331                    msg.append(title);
5332    
5333                    msg.append(", version=");
5334                    msg.append(version);
5335    
5336                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5337    
5338                    throw new NoSuchFileVersionException(msg.toString());
5339            }
5340    
5341            /**
5342             * Returns the last document library file version in the ordered set where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5343             *
5344             * @param groupId the group ID
5345             * @param folderId the folder ID
5346             * @param title the title
5347             * @param version the version
5348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5349             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
5350             */
5351            @Override
5352            public DLFileVersion fetchByG_F_T_V_Last(long groupId, long folderId,
5353                    String title, String version,
5354                    OrderByComparator<DLFileVersion> orderByComparator) {
5355                    int count = countByG_F_T_V(groupId, folderId, title, version);
5356    
5357                    if (count == 0) {
5358                            return null;
5359                    }
5360    
5361                    List<DLFileVersion> list = findByG_F_T_V(groupId, folderId, title,
5362                                    version, count - 1, count, orderByComparator);
5363    
5364                    if (!list.isEmpty()) {
5365                            return list.get(0);
5366                    }
5367    
5368                    return null;
5369            }
5370    
5371            /**
5372             * Returns the document library file versions before and after the current document library file version in the ordered set where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5373             *
5374             * @param fileVersionId the primary key of the current document library file version
5375             * @param groupId the group ID
5376             * @param folderId the folder ID
5377             * @param title the title
5378             * @param version the version
5379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5380             * @return the previous, current, and next document library file version
5381             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
5382             */
5383            @Override
5384            public DLFileVersion[] findByG_F_T_V_PrevAndNext(long fileVersionId,
5385                    long groupId, long folderId, String title, String version,
5386                    OrderByComparator<DLFileVersion> orderByComparator)
5387                    throws NoSuchFileVersionException {
5388                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
5389    
5390                    Session session = null;
5391    
5392                    try {
5393                            session = openSession();
5394    
5395                            DLFileVersion[] array = new DLFileVersionImpl[3];
5396    
5397                            array[0] = getByG_F_T_V_PrevAndNext(session, dlFileVersion,
5398                                            groupId, folderId, title, version, orderByComparator, true);
5399    
5400                            array[1] = dlFileVersion;
5401    
5402                            array[2] = getByG_F_T_V_PrevAndNext(session, dlFileVersion,
5403                                            groupId, folderId, title, version, orderByComparator, false);
5404    
5405                            return array;
5406                    }
5407                    catch (Exception e) {
5408                            throw processException(e);
5409                    }
5410                    finally {
5411                            closeSession(session);
5412                    }
5413            }
5414    
5415            protected DLFileVersion getByG_F_T_V_PrevAndNext(Session session,
5416                    DLFileVersion dlFileVersion, long groupId, long folderId, String title,
5417                    String version, OrderByComparator<DLFileVersion> orderByComparator,
5418                    boolean previous) {
5419                    StringBundler query = null;
5420    
5421                    if (orderByComparator != null) {
5422                            query = new StringBundler(6 +
5423                                            (orderByComparator.getOrderByFields().length * 6));
5424                    }
5425                    else {
5426                            query = new StringBundler(3);
5427                    }
5428    
5429                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
5430    
5431                    query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
5432    
5433                    query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
5434    
5435                    boolean bindTitle = false;
5436    
5437                    if (title == null) {
5438                            query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
5439                    }
5440                    else if (title.equals(StringPool.BLANK)) {
5441                            query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
5442                    }
5443                    else {
5444                            bindTitle = true;
5445    
5446                            query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
5447                    }
5448    
5449                    boolean bindVersion = false;
5450    
5451                    if (version == null) {
5452                            query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
5453                    }
5454                    else if (version.equals(StringPool.BLANK)) {
5455                            query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
5456                    }
5457                    else {
5458                            bindVersion = true;
5459    
5460                            query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
5461                    }
5462    
5463                    if (orderByComparator != null) {
5464                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5465    
5466                            if (orderByConditionFields.length > 0) {
5467                                    query.append(WHERE_AND);
5468                            }
5469    
5470                            for (int i = 0; i < orderByConditionFields.length; i++) {
5471                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5472                                    query.append(orderByConditionFields[i]);
5473    
5474                                    if ((i + 1) < orderByConditionFields.length) {
5475                                            if (orderByComparator.isAscending() ^ previous) {
5476                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5477                                            }
5478                                            else {
5479                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5480                                            }
5481                                    }
5482                                    else {
5483                                            if (orderByComparator.isAscending() ^ previous) {
5484                                                    query.append(WHERE_GREATER_THAN);
5485                                            }
5486                                            else {
5487                                                    query.append(WHERE_LESSER_THAN);
5488                                            }
5489                                    }
5490                            }
5491    
5492                            query.append(ORDER_BY_CLAUSE);
5493    
5494                            String[] orderByFields = orderByComparator.getOrderByFields();
5495    
5496                            for (int i = 0; i < orderByFields.length; i++) {
5497                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5498                                    query.append(orderByFields[i]);
5499    
5500                                    if ((i + 1) < orderByFields.length) {
5501                                            if (orderByComparator.isAscending() ^ previous) {
5502                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5503                                            }
5504                                            else {
5505                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5506                                            }
5507                                    }
5508                                    else {
5509                                            if (orderByComparator.isAscending() ^ previous) {
5510                                                    query.append(ORDER_BY_ASC);
5511                                            }
5512                                            else {
5513                                                    query.append(ORDER_BY_DESC);
5514                                            }
5515                                    }
5516                            }
5517                    }
5518                    else {
5519                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
5520                    }
5521    
5522                    String sql = query.toString();
5523    
5524                    Query q = session.createQuery(sql);
5525    
5526                    q.setFirstResult(0);
5527                    q.setMaxResults(2);
5528    
5529                    QueryPos qPos = QueryPos.getInstance(q);
5530    
5531                    qPos.add(groupId);
5532    
5533                    qPos.add(folderId);
5534    
5535                    if (bindTitle) {
5536                            qPos.add(title);
5537                    }
5538    
5539                    if (bindVersion) {
5540                            qPos.add(version);
5541                    }
5542    
5543                    if (orderByComparator != null) {
5544                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
5545    
5546                            for (Object value : values) {
5547                                    qPos.add(value);
5548                            }
5549                    }
5550    
5551                    List<DLFileVersion> list = q.list();
5552    
5553                    if (list.size() == 2) {
5554                            return list.get(1);
5555                    }
5556                    else {
5557                            return null;
5558                    }
5559            }
5560    
5561            /**
5562             * Removes all the document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63; from the database.
5563             *
5564             * @param groupId the group ID
5565             * @param folderId the folder ID
5566             * @param title the title
5567             * @param version the version
5568             */
5569            @Override
5570            public void removeByG_F_T_V(long groupId, long folderId, String title,
5571                    String version) {
5572                    for (DLFileVersion dlFileVersion : findByG_F_T_V(groupId, folderId,
5573                                    title, version, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5574                            remove(dlFileVersion);
5575                    }
5576            }
5577    
5578            /**
5579             * Returns the number of document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
5580             *
5581             * @param groupId the group ID
5582             * @param folderId the folder ID
5583             * @param title the title
5584             * @param version the version
5585             * @return the number of matching document library file versions
5586             */
5587            @Override
5588            public int countByG_F_T_V(long groupId, long folderId, String title,
5589                    String version) {
5590                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_F_T_V;
5591    
5592                    Object[] finderArgs = new Object[] { groupId, folderId, title, version };
5593    
5594                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5595    
5596                    if (count == null) {
5597                            StringBundler query = new StringBundler(5);
5598    
5599                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
5600    
5601                            query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
5602    
5603                            query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
5604    
5605                            boolean bindTitle = false;
5606    
5607                            if (title == null) {
5608                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
5609                            }
5610                            else if (title.equals(StringPool.BLANK)) {
5611                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
5612                            }
5613                            else {
5614                                    bindTitle = true;
5615    
5616                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
5617                            }
5618    
5619                            boolean bindVersion = false;
5620    
5621                            if (version == null) {
5622                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
5623                            }
5624                            else if (version.equals(StringPool.BLANK)) {
5625                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
5626                            }
5627                            else {
5628                                    bindVersion = true;
5629    
5630                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
5631                            }
5632    
5633                            String sql = query.toString();
5634    
5635                            Session session = null;
5636    
5637                            try {
5638                                    session = openSession();
5639    
5640                                    Query q = session.createQuery(sql);
5641    
5642                                    QueryPos qPos = QueryPos.getInstance(q);
5643    
5644                                    qPos.add(groupId);
5645    
5646                                    qPos.add(folderId);
5647    
5648                                    if (bindTitle) {
5649                                            qPos.add(title);
5650                                    }
5651    
5652                                    if (bindVersion) {
5653                                            qPos.add(version);
5654                                    }
5655    
5656                                    count = (Long)q.uniqueResult();
5657    
5658                                    finderCache.putResult(finderPath, finderArgs, count);
5659                            }
5660                            catch (Exception e) {
5661                                    finderCache.removeResult(finderPath, finderArgs);
5662    
5663                                    throw processException(e);
5664                            }
5665                            finally {
5666                                    closeSession(session);
5667                            }
5668                    }
5669    
5670                    return count.intValue();
5671            }
5672    
5673            private static final String _FINDER_COLUMN_G_F_T_V_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
5674            private static final String _FINDER_COLUMN_G_F_T_V_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
5675            private static final String _FINDER_COLUMN_G_F_T_V_TITLE_1 = "dlFileVersion.title IS NULL AND ";
5676            private static final String _FINDER_COLUMN_G_F_T_V_TITLE_2 = "dlFileVersion.title = ? AND ";
5677            private static final String _FINDER_COLUMN_G_F_T_V_TITLE_3 = "(dlFileVersion.title IS NULL OR dlFileVersion.title = '') AND ";
5678            private static final String _FINDER_COLUMN_G_F_T_V_VERSION_1 = "dlFileVersion.version IS NULL";
5679            private static final String _FINDER_COLUMN_G_F_T_V_VERSION_2 = "dlFileVersion.version = ?";
5680            private static final String _FINDER_COLUMN_G_F_T_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = '')";
5681    
5682            public DLFileVersionPersistenceImpl() {
5683                    setModelClass(DLFileVersion.class);
5684            }
5685    
5686            /**
5687             * Caches the document library file version in the entity cache if it is enabled.
5688             *
5689             * @param dlFileVersion the document library file version
5690             */
5691            @Override
5692            public void cacheResult(DLFileVersion dlFileVersion) {
5693                    entityCache.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5694                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
5695                            dlFileVersion);
5696    
5697                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
5698                            new Object[] { dlFileVersion.getUuid(), dlFileVersion.getGroupId() },
5699                            dlFileVersion);
5700    
5701                    finderCache.putResult(FINDER_PATH_FETCH_BY_F_V,
5702                            new Object[] {
5703                                    dlFileVersion.getFileEntryId(), dlFileVersion.getVersion()
5704                            }, dlFileVersion);
5705    
5706                    dlFileVersion.resetOriginalValues();
5707            }
5708    
5709            /**
5710             * Caches the document library file versions in the entity cache if it is enabled.
5711             *
5712             * @param dlFileVersions the document library file versions
5713             */
5714            @Override
5715            public void cacheResult(List<DLFileVersion> dlFileVersions) {
5716                    for (DLFileVersion dlFileVersion : dlFileVersions) {
5717                            if (entityCache.getResult(
5718                                                    DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5719                                                    DLFileVersionImpl.class, dlFileVersion.getPrimaryKey()) == null) {
5720                                    cacheResult(dlFileVersion);
5721                            }
5722                            else {
5723                                    dlFileVersion.resetOriginalValues();
5724                            }
5725                    }
5726            }
5727    
5728            /**
5729             * Clears the cache for all document library file versions.
5730             *
5731             * <p>
5732             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
5733             * </p>
5734             */
5735            @Override
5736            public void clearCache() {
5737                    entityCache.clearCache(DLFileVersionImpl.class);
5738    
5739                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
5740                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5741                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5742            }
5743    
5744            /**
5745             * Clears the cache for the document library file version.
5746             *
5747             * <p>
5748             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
5749             * </p>
5750             */
5751            @Override
5752            public void clearCache(DLFileVersion dlFileVersion) {
5753                    entityCache.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5754                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
5755    
5756                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5757                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5758    
5759                    clearUniqueFindersCache((DLFileVersionModelImpl)dlFileVersion);
5760            }
5761    
5762            @Override
5763            public void clearCache(List<DLFileVersion> dlFileVersions) {
5764                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5765                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5766    
5767                    for (DLFileVersion dlFileVersion : dlFileVersions) {
5768                            entityCache.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5769                                    DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
5770    
5771                            clearUniqueFindersCache((DLFileVersionModelImpl)dlFileVersion);
5772                    }
5773            }
5774    
5775            protected void cacheUniqueFindersCache(
5776                    DLFileVersionModelImpl dlFileVersionModelImpl, boolean isNew) {
5777                    if (isNew) {
5778                            Object[] args = new Object[] {
5779                                            dlFileVersionModelImpl.getUuid(),
5780                                            dlFileVersionModelImpl.getGroupId()
5781                                    };
5782    
5783                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
5784                                    Long.valueOf(1));
5785                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
5786                                    dlFileVersionModelImpl);
5787    
5788                            args = new Object[] {
5789                                            dlFileVersionModelImpl.getFileEntryId(),
5790                                            dlFileVersionModelImpl.getVersion()
5791                                    };
5792    
5793                            finderCache.putResult(FINDER_PATH_COUNT_BY_F_V, args,
5794                                    Long.valueOf(1));
5795                            finderCache.putResult(FINDER_PATH_FETCH_BY_F_V, args,
5796                                    dlFileVersionModelImpl);
5797                    }
5798                    else {
5799                            if ((dlFileVersionModelImpl.getColumnBitmask() &
5800                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
5801                                    Object[] args = new Object[] {
5802                                                    dlFileVersionModelImpl.getUuid(),
5803                                                    dlFileVersionModelImpl.getGroupId()
5804                                            };
5805    
5806                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
5807                                            Long.valueOf(1));
5808                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
5809                                            dlFileVersionModelImpl);
5810                            }
5811    
5812                            if ((dlFileVersionModelImpl.getColumnBitmask() &
5813                                            FINDER_PATH_FETCH_BY_F_V.getColumnBitmask()) != 0) {
5814                                    Object[] args = new Object[] {
5815                                                    dlFileVersionModelImpl.getFileEntryId(),
5816                                                    dlFileVersionModelImpl.getVersion()
5817                                            };
5818    
5819                                    finderCache.putResult(FINDER_PATH_COUNT_BY_F_V, args,
5820                                            Long.valueOf(1));
5821                                    finderCache.putResult(FINDER_PATH_FETCH_BY_F_V, args,
5822                                            dlFileVersionModelImpl);
5823                            }
5824                    }
5825            }
5826    
5827            protected void clearUniqueFindersCache(
5828                    DLFileVersionModelImpl dlFileVersionModelImpl) {
5829                    Object[] args = new Object[] {
5830                                    dlFileVersionModelImpl.getUuid(),
5831                                    dlFileVersionModelImpl.getGroupId()
5832                            };
5833    
5834                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
5835                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
5836    
5837                    if ((dlFileVersionModelImpl.getColumnBitmask() &
5838                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
5839                            args = new Object[] {
5840                                            dlFileVersionModelImpl.getOriginalUuid(),
5841                                            dlFileVersionModelImpl.getOriginalGroupId()
5842                                    };
5843    
5844                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
5845                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
5846                    }
5847    
5848                    args = new Object[] {
5849                                    dlFileVersionModelImpl.getFileEntryId(),
5850                                    dlFileVersionModelImpl.getVersion()
5851                            };
5852    
5853                    finderCache.removeResult(FINDER_PATH_COUNT_BY_F_V, args);
5854                    finderCache.removeResult(FINDER_PATH_FETCH_BY_F_V, args);
5855    
5856                    if ((dlFileVersionModelImpl.getColumnBitmask() &
5857                                    FINDER_PATH_FETCH_BY_F_V.getColumnBitmask()) != 0) {
5858                            args = new Object[] {
5859                                            dlFileVersionModelImpl.getOriginalFileEntryId(),
5860                                            dlFileVersionModelImpl.getOriginalVersion()
5861                                    };
5862    
5863                            finderCache.removeResult(FINDER_PATH_COUNT_BY_F_V, args);
5864                            finderCache.removeResult(FINDER_PATH_FETCH_BY_F_V, args);
5865                    }
5866            }
5867    
5868            /**
5869             * Creates a new document library file version with the primary key. Does not add the document library file version to the database.
5870             *
5871             * @param fileVersionId the primary key for the new document library file version
5872             * @return the new document library file version
5873             */
5874            @Override
5875            public DLFileVersion create(long fileVersionId) {
5876                    DLFileVersion dlFileVersion = new DLFileVersionImpl();
5877    
5878                    dlFileVersion.setNew(true);
5879                    dlFileVersion.setPrimaryKey(fileVersionId);
5880    
5881                    String uuid = PortalUUIDUtil.generate();
5882    
5883                    dlFileVersion.setUuid(uuid);
5884    
5885                    dlFileVersion.setCompanyId(companyProvider.getCompanyId());
5886    
5887                    return dlFileVersion;
5888            }
5889    
5890            /**
5891             * Removes the document library file version with the primary key from the database. Also notifies the appropriate model listeners.
5892             *
5893             * @param fileVersionId the primary key of the document library file version
5894             * @return the document library file version that was removed
5895             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
5896             */
5897            @Override
5898            public DLFileVersion remove(long fileVersionId)
5899                    throws NoSuchFileVersionException {
5900                    return remove((Serializable)fileVersionId);
5901            }
5902    
5903            /**
5904             * Removes the document library file version with the primary key from the database. Also notifies the appropriate model listeners.
5905             *
5906             * @param primaryKey the primary key of the document library file version
5907             * @return the document library file version that was removed
5908             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
5909             */
5910            @Override
5911            public DLFileVersion remove(Serializable primaryKey)
5912                    throws NoSuchFileVersionException {
5913                    Session session = null;
5914    
5915                    try {
5916                            session = openSession();
5917    
5918                            DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
5919                                            primaryKey);
5920    
5921                            if (dlFileVersion == null) {
5922                                    if (_log.isWarnEnabled()) {
5923                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5924                                    }
5925    
5926                                    throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5927                                            primaryKey);
5928                            }
5929    
5930                            return remove(dlFileVersion);
5931                    }
5932                    catch (NoSuchFileVersionException nsee) {
5933                            throw nsee;
5934                    }
5935                    catch (Exception e) {
5936                            throw processException(e);
5937                    }
5938                    finally {
5939                            closeSession(session);
5940                    }
5941            }
5942    
5943            @Override
5944            protected DLFileVersion removeImpl(DLFileVersion dlFileVersion) {
5945                    dlFileVersion = toUnwrappedModel(dlFileVersion);
5946    
5947                    Session session = null;
5948    
5949                    try {
5950                            session = openSession();
5951    
5952                            if (!session.contains(dlFileVersion)) {
5953                                    dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
5954                                                    dlFileVersion.getPrimaryKeyObj());
5955                            }
5956    
5957                            if (dlFileVersion != null) {
5958                                    session.delete(dlFileVersion);
5959                            }
5960                    }
5961                    catch (Exception e) {
5962                            throw processException(e);
5963                    }
5964                    finally {
5965                            closeSession(session);
5966                    }
5967    
5968                    if (dlFileVersion != null) {
5969                            clearCache(dlFileVersion);
5970                    }
5971    
5972                    return dlFileVersion;
5973            }
5974    
5975            @Override
5976            public DLFileVersion updateImpl(DLFileVersion dlFileVersion) {
5977                    dlFileVersion = toUnwrappedModel(dlFileVersion);
5978    
5979                    boolean isNew = dlFileVersion.isNew();
5980    
5981                    DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
5982    
5983                    if (Validator.isNull(dlFileVersion.getUuid())) {
5984                            String uuid = PortalUUIDUtil.generate();
5985    
5986                            dlFileVersion.setUuid(uuid);
5987                    }
5988    
5989                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
5990    
5991                    Date now = new Date();
5992    
5993                    if (isNew && (dlFileVersion.getCreateDate() == null)) {
5994                            if (serviceContext == null) {
5995                                    dlFileVersion.setCreateDate(now);
5996                            }
5997                            else {
5998                                    dlFileVersion.setCreateDate(serviceContext.getCreateDate(now));
5999                            }
6000                    }
6001    
6002                    if (!dlFileVersionModelImpl.hasSetModifiedDate()) {
6003                            if (serviceContext == null) {
6004                                    dlFileVersion.setModifiedDate(now);
6005                            }
6006                            else {
6007                                    dlFileVersion.setModifiedDate(serviceContext.getModifiedDate(
6008                                                    now));
6009                            }
6010                    }
6011    
6012                    Session session = null;
6013    
6014                    try {
6015                            session = openSession();
6016    
6017                            if (dlFileVersion.isNew()) {
6018                                    session.save(dlFileVersion);
6019    
6020                                    dlFileVersion.setNew(false);
6021                            }
6022                            else {
6023                                    dlFileVersion = (DLFileVersion)session.merge(dlFileVersion);
6024                            }
6025                    }
6026                    catch (Exception e) {
6027                            throw processException(e);
6028                    }
6029                    finally {
6030                            closeSession(session);
6031                    }
6032    
6033                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6034    
6035                    if (isNew || !DLFileVersionModelImpl.COLUMN_BITMASK_ENABLED) {
6036                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6037                    }
6038    
6039                    else {
6040                            if ((dlFileVersionModelImpl.getColumnBitmask() &
6041                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6042                                    Object[] args = new Object[] {
6043                                                    dlFileVersionModelImpl.getOriginalUuid()
6044                                            };
6045    
6046                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6047                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6048                                            args);
6049    
6050                                    args = new Object[] { dlFileVersionModelImpl.getUuid() };
6051    
6052                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6053                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6054                                            args);
6055                            }
6056    
6057                            if ((dlFileVersionModelImpl.getColumnBitmask() &
6058                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6059                                    Object[] args = new Object[] {
6060                                                    dlFileVersionModelImpl.getOriginalUuid(),
6061                                                    dlFileVersionModelImpl.getOriginalCompanyId()
6062                                            };
6063    
6064                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6065                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6066                                            args);
6067    
6068                                    args = new Object[] {
6069                                                    dlFileVersionModelImpl.getUuid(),
6070                                                    dlFileVersionModelImpl.getCompanyId()
6071                                            };
6072    
6073                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6074                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6075                                            args);
6076                            }
6077    
6078                            if ((dlFileVersionModelImpl.getColumnBitmask() &
6079                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6080                                    Object[] args = new Object[] {
6081                                                    dlFileVersionModelImpl.getOriginalCompanyId()
6082                                            };
6083    
6084                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
6085                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6086                                            args);
6087    
6088                                    args = new Object[] { dlFileVersionModelImpl.getCompanyId() };
6089    
6090                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
6091                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6092                                            args);
6093                            }
6094    
6095                            if ((dlFileVersionModelImpl.getColumnBitmask() &
6096                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
6097                                    Object[] args = new Object[] {
6098                                                    dlFileVersionModelImpl.getOriginalFileEntryId()
6099                                            };
6100    
6101                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID, args);
6102                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
6103                                            args);
6104    
6105                                    args = new Object[] { dlFileVersionModelImpl.getFileEntryId() };
6106    
6107                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID, args);
6108                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
6109                                            args);
6110                            }
6111    
6112                            if ((dlFileVersionModelImpl.getColumnBitmask() &
6113                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE.getColumnBitmask()) != 0) {
6114                                    Object[] args = new Object[] {
6115                                                    dlFileVersionModelImpl.getOriginalMimeType()
6116                                            };
6117    
6118                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_MIMETYPE, args);
6119                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE,
6120                                            args);
6121    
6122                                    args = new Object[] { dlFileVersionModelImpl.getMimeType() };
6123    
6124                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_MIMETYPE, args);
6125                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE,
6126                                            args);
6127                            }
6128    
6129                            if ((dlFileVersionModelImpl.getColumnBitmask() &
6130                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S.getColumnBitmask()) != 0) {
6131                                    Object[] args = new Object[] {
6132                                                    dlFileVersionModelImpl.getOriginalFileEntryId(),
6133                                                    dlFileVersionModelImpl.getOriginalStatus()
6134                                            };
6135    
6136                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_F_S, args);
6137                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S,
6138                                            args);
6139    
6140                                    args = new Object[] {
6141                                                    dlFileVersionModelImpl.getFileEntryId(),
6142                                                    dlFileVersionModelImpl.getStatus()
6143                                            };
6144    
6145                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_F_S, args);
6146                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S,
6147                                            args);
6148                            }
6149    
6150                            if ((dlFileVersionModelImpl.getColumnBitmask() &
6151                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S.getColumnBitmask()) != 0) {
6152                                    Object[] args = new Object[] {
6153                                                    dlFileVersionModelImpl.getOriginalGroupId(),
6154                                                    dlFileVersionModelImpl.getOriginalFolderId(),
6155                                                    dlFileVersionModelImpl.getOriginalStatus()
6156                                            };
6157    
6158                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_F_S, args);
6159                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S,
6160                                            args);
6161    
6162                                    args = new Object[] {
6163                                                    dlFileVersionModelImpl.getGroupId(),
6164                                                    dlFileVersionModelImpl.getFolderId(),
6165                                                    dlFileVersionModelImpl.getStatus()
6166                                            };
6167    
6168                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_F_S, args);
6169                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S,
6170                                            args);
6171                            }
6172    
6173                            if ((dlFileVersionModelImpl.getColumnBitmask() &
6174                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V.getColumnBitmask()) != 0) {
6175                                    Object[] args = new Object[] {
6176                                                    dlFileVersionModelImpl.getOriginalGroupId(),
6177                                                    dlFileVersionModelImpl.getOriginalFolderId(),
6178                                                    dlFileVersionModelImpl.getOriginalTitle(),
6179                                                    dlFileVersionModelImpl.getOriginalVersion()
6180                                            };
6181    
6182                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_F_T_V, args);
6183                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V,
6184                                            args);
6185    
6186                                    args = new Object[] {
6187                                                    dlFileVersionModelImpl.getGroupId(),
6188                                                    dlFileVersionModelImpl.getFolderId(),
6189                                                    dlFileVersionModelImpl.getTitle(),
6190                                                    dlFileVersionModelImpl.getVersion()
6191                                            };
6192    
6193                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_F_T_V, args);
6194                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V,
6195                                            args);
6196                            }
6197                    }
6198    
6199                    entityCache.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6200                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
6201                            dlFileVersion, false);
6202    
6203                    clearUniqueFindersCache(dlFileVersionModelImpl);
6204                    cacheUniqueFindersCache(dlFileVersionModelImpl, isNew);
6205    
6206                    dlFileVersion.resetOriginalValues();
6207    
6208                    return dlFileVersion;
6209            }
6210    
6211            protected DLFileVersion toUnwrappedModel(DLFileVersion dlFileVersion) {
6212                    if (dlFileVersion instanceof DLFileVersionImpl) {
6213                            return dlFileVersion;
6214                    }
6215    
6216                    DLFileVersionImpl dlFileVersionImpl = new DLFileVersionImpl();
6217    
6218                    dlFileVersionImpl.setNew(dlFileVersion.isNew());
6219                    dlFileVersionImpl.setPrimaryKey(dlFileVersion.getPrimaryKey());
6220    
6221                    dlFileVersionImpl.setUuid(dlFileVersion.getUuid());
6222                    dlFileVersionImpl.setFileVersionId(dlFileVersion.getFileVersionId());
6223                    dlFileVersionImpl.setGroupId(dlFileVersion.getGroupId());
6224                    dlFileVersionImpl.setCompanyId(dlFileVersion.getCompanyId());
6225                    dlFileVersionImpl.setUserId(dlFileVersion.getUserId());
6226                    dlFileVersionImpl.setUserName(dlFileVersion.getUserName());
6227                    dlFileVersionImpl.setCreateDate(dlFileVersion.getCreateDate());
6228                    dlFileVersionImpl.setModifiedDate(dlFileVersion.getModifiedDate());
6229                    dlFileVersionImpl.setRepositoryId(dlFileVersion.getRepositoryId());
6230                    dlFileVersionImpl.setFolderId(dlFileVersion.getFolderId());
6231                    dlFileVersionImpl.setFileEntryId(dlFileVersion.getFileEntryId());
6232                    dlFileVersionImpl.setTreePath(dlFileVersion.getTreePath());
6233                    dlFileVersionImpl.setFileName(dlFileVersion.getFileName());
6234                    dlFileVersionImpl.setExtension(dlFileVersion.getExtension());
6235                    dlFileVersionImpl.setMimeType(dlFileVersion.getMimeType());
6236                    dlFileVersionImpl.setTitle(dlFileVersion.getTitle());
6237                    dlFileVersionImpl.setDescription(dlFileVersion.getDescription());
6238                    dlFileVersionImpl.setChangeLog(dlFileVersion.getChangeLog());
6239                    dlFileVersionImpl.setExtraSettings(dlFileVersion.getExtraSettings());
6240                    dlFileVersionImpl.setFileEntryTypeId(dlFileVersion.getFileEntryTypeId());
6241                    dlFileVersionImpl.setVersion(dlFileVersion.getVersion());
6242                    dlFileVersionImpl.setSize(dlFileVersion.getSize());
6243                    dlFileVersionImpl.setChecksum(dlFileVersion.getChecksum());
6244                    dlFileVersionImpl.setLastPublishDate(dlFileVersion.getLastPublishDate());
6245                    dlFileVersionImpl.setStatus(dlFileVersion.getStatus());
6246                    dlFileVersionImpl.setStatusByUserId(dlFileVersion.getStatusByUserId());
6247                    dlFileVersionImpl.setStatusByUserName(dlFileVersion.getStatusByUserName());
6248                    dlFileVersionImpl.setStatusDate(dlFileVersion.getStatusDate());
6249    
6250                    return dlFileVersionImpl;
6251            }
6252    
6253            /**
6254             * Returns the document library file version with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
6255             *
6256             * @param primaryKey the primary key of the document library file version
6257             * @return the document library file version
6258             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
6259             */
6260            @Override
6261            public DLFileVersion findByPrimaryKey(Serializable primaryKey)
6262                    throws NoSuchFileVersionException {
6263                    DLFileVersion dlFileVersion = fetchByPrimaryKey(primaryKey);
6264    
6265                    if (dlFileVersion == null) {
6266                            if (_log.isWarnEnabled()) {
6267                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6268                            }
6269    
6270                            throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6271                                    primaryKey);
6272                    }
6273    
6274                    return dlFileVersion;
6275            }
6276    
6277            /**
6278             * Returns the document library file version with the primary key or throws a {@link NoSuchFileVersionException} if it could not be found.
6279             *
6280             * @param fileVersionId the primary key of the document library file version
6281             * @return the document library file version
6282             * @throws NoSuchFileVersionException if a document library file version with the primary key could not be found
6283             */
6284            @Override
6285            public DLFileVersion findByPrimaryKey(long fileVersionId)
6286                    throws NoSuchFileVersionException {
6287                    return findByPrimaryKey((Serializable)fileVersionId);
6288            }
6289    
6290            /**
6291             * Returns the document library file version with the primary key or returns <code>null</code> if it could not be found.
6292             *
6293             * @param primaryKey the primary key of the document library file version
6294             * @return the document library file version, or <code>null</code> if a document library file version with the primary key could not be found
6295             */
6296            @Override
6297            public DLFileVersion fetchByPrimaryKey(Serializable primaryKey) {
6298                    DLFileVersion dlFileVersion = (DLFileVersion)entityCache.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6299                                    DLFileVersionImpl.class, primaryKey);
6300    
6301                    if (dlFileVersion == _nullDLFileVersion) {
6302                            return null;
6303                    }
6304    
6305                    if (dlFileVersion == null) {
6306                            Session session = null;
6307    
6308                            try {
6309                                    session = openSession();
6310    
6311                                    dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
6312                                                    primaryKey);
6313    
6314                                    if (dlFileVersion != null) {
6315                                            cacheResult(dlFileVersion);
6316                                    }
6317                                    else {
6318                                            entityCache.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6319                                                    DLFileVersionImpl.class, primaryKey, _nullDLFileVersion);
6320                                    }
6321                            }
6322                            catch (Exception e) {
6323                                    entityCache.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6324                                            DLFileVersionImpl.class, primaryKey);
6325    
6326                                    throw processException(e);
6327                            }
6328                            finally {
6329                                    closeSession(session);
6330                            }
6331                    }
6332    
6333                    return dlFileVersion;
6334            }
6335    
6336            /**
6337             * Returns the document library file version with the primary key or returns <code>null</code> if it could not be found.
6338             *
6339             * @param fileVersionId the primary key of the document library file version
6340             * @return the document library file version, or <code>null</code> if a document library file version with the primary key could not be found
6341             */
6342            @Override
6343            public DLFileVersion fetchByPrimaryKey(long fileVersionId) {
6344                    return fetchByPrimaryKey((Serializable)fileVersionId);
6345            }
6346    
6347            @Override
6348            public Map<Serializable, DLFileVersion> fetchByPrimaryKeys(
6349                    Set<Serializable> primaryKeys) {
6350                    if (primaryKeys.isEmpty()) {
6351                            return Collections.emptyMap();
6352                    }
6353    
6354                    Map<Serializable, DLFileVersion> map = new HashMap<Serializable, DLFileVersion>();
6355    
6356                    if (primaryKeys.size() == 1) {
6357                            Iterator<Serializable> iterator = primaryKeys.iterator();
6358    
6359                            Serializable primaryKey = iterator.next();
6360    
6361                            DLFileVersion dlFileVersion = fetchByPrimaryKey(primaryKey);
6362    
6363                            if (dlFileVersion != null) {
6364                                    map.put(primaryKey, dlFileVersion);
6365                            }
6366    
6367                            return map;
6368                    }
6369    
6370                    Set<Serializable> uncachedPrimaryKeys = null;
6371    
6372                    for (Serializable primaryKey : primaryKeys) {
6373                            DLFileVersion dlFileVersion = (DLFileVersion)entityCache.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6374                                            DLFileVersionImpl.class, primaryKey);
6375    
6376                            if (dlFileVersion == null) {
6377                                    if (uncachedPrimaryKeys == null) {
6378                                            uncachedPrimaryKeys = new HashSet<Serializable>();
6379                                    }
6380    
6381                                    uncachedPrimaryKeys.add(primaryKey);
6382                            }
6383                            else {
6384                                    map.put(primaryKey, dlFileVersion);
6385                            }
6386                    }
6387    
6388                    if (uncachedPrimaryKeys == null) {
6389                            return map;
6390                    }
6391    
6392                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
6393                                    1);
6394    
6395                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE_PKS_IN);
6396    
6397                    for (Serializable primaryKey : uncachedPrimaryKeys) {
6398                            query.append(String.valueOf(primaryKey));
6399    
6400                            query.append(StringPool.COMMA);
6401                    }
6402    
6403                    query.setIndex(query.index() - 1);
6404    
6405                    query.append(StringPool.CLOSE_PARENTHESIS);
6406    
6407                    String sql = query.toString();
6408    
6409                    Session session = null;
6410    
6411                    try {
6412                            session = openSession();
6413    
6414                            Query q = session.createQuery(sql);
6415    
6416                            for (DLFileVersion dlFileVersion : (List<DLFileVersion>)q.list()) {
6417                                    map.put(dlFileVersion.getPrimaryKeyObj(), dlFileVersion);
6418    
6419                                    cacheResult(dlFileVersion);
6420    
6421                                    uncachedPrimaryKeys.remove(dlFileVersion.getPrimaryKeyObj());
6422                            }
6423    
6424                            for (Serializable primaryKey : uncachedPrimaryKeys) {
6425                                    entityCache.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
6426                                            DLFileVersionImpl.class, primaryKey, _nullDLFileVersion);
6427                            }
6428                    }
6429                    catch (Exception e) {
6430                            throw processException(e);
6431                    }
6432                    finally {
6433                            closeSession(session);
6434                    }
6435    
6436                    return map;
6437            }
6438    
6439            /**
6440             * Returns all the document library file versions.
6441             *
6442             * @return the document library file versions
6443             */
6444            @Override
6445            public List<DLFileVersion> findAll() {
6446                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6447            }
6448    
6449            /**
6450             * Returns a range of all the document library file versions.
6451             *
6452             * <p>
6453             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6454             * </p>
6455             *
6456             * @param start the lower bound of the range of document library file versions
6457             * @param end the upper bound of the range of document library file versions (not inclusive)
6458             * @return the range of document library file versions
6459             */
6460            @Override
6461            public List<DLFileVersion> findAll(int start, int end) {
6462                    return findAll(start, end, null);
6463            }
6464    
6465            /**
6466             * Returns an ordered range of all the document library file versions.
6467             *
6468             * <p>
6469             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6470             * </p>
6471             *
6472             * @param start the lower bound of the range of document library file versions
6473             * @param end the upper bound of the range of document library file versions (not inclusive)
6474             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6475             * @return the ordered range of document library file versions
6476             */
6477            @Override
6478            public List<DLFileVersion> findAll(int start, int end,
6479                    OrderByComparator<DLFileVersion> orderByComparator) {
6480                    return findAll(start, end, orderByComparator, true);
6481            }
6482    
6483            /**
6484             * Returns an ordered range of all the document library file versions.
6485             *
6486             * <p>
6487             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DLFileVersionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6488             * </p>
6489             *
6490             * @param start the lower bound of the range of document library file versions
6491             * @param end the upper bound of the range of document library file versions (not inclusive)
6492             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6493             * @param retrieveFromCache whether to retrieve from the finder cache
6494             * @return the ordered range of document library file versions
6495             */
6496            @Override
6497            public List<DLFileVersion> findAll(int start, int end,
6498                    OrderByComparator<DLFileVersion> orderByComparator,
6499                    boolean retrieveFromCache) {
6500                    boolean pagination = true;
6501                    FinderPath finderPath = null;
6502                    Object[] finderArgs = null;
6503    
6504                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6505                                    (orderByComparator == null)) {
6506                            pagination = false;
6507                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
6508                            finderArgs = FINDER_ARGS_EMPTY;
6509                    }
6510                    else {
6511                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
6512                            finderArgs = new Object[] { start, end, orderByComparator };
6513                    }
6514    
6515                    List<DLFileVersion> list = null;
6516    
6517                    if (retrieveFromCache) {
6518                            list = (List<DLFileVersion>)finderCache.getResult(finderPath,
6519                                            finderArgs, this);
6520                    }
6521    
6522                    if (list == null) {
6523                            StringBundler query = null;
6524                            String sql = null;
6525    
6526                            if (orderByComparator != null) {
6527                                    query = new StringBundler(2 +
6528                                                    (orderByComparator.getOrderByFields().length * 3));
6529    
6530                                    query.append(_SQL_SELECT_DLFILEVERSION);
6531    
6532                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6533                                            orderByComparator);
6534    
6535                                    sql = query.toString();
6536                            }
6537                            else {
6538                                    sql = _SQL_SELECT_DLFILEVERSION;
6539    
6540                                    if (pagination) {
6541                                            sql = sql.concat(DLFileVersionModelImpl.ORDER_BY_JPQL);
6542                                    }
6543                            }
6544    
6545                            Session session = null;
6546    
6547                            try {
6548                                    session = openSession();
6549    
6550                                    Query q = session.createQuery(sql);
6551    
6552                                    if (!pagination) {
6553                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
6554                                                            start, end, false);
6555    
6556                                            Collections.sort(list);
6557    
6558                                            list = Collections.unmodifiableList(list);
6559                                    }
6560                                    else {
6561                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
6562                                                            start, end);
6563                                    }
6564    
6565                                    cacheResult(list);
6566    
6567                                    finderCache.putResult(finderPath, finderArgs, list);
6568                            }
6569                            catch (Exception e) {
6570                                    finderCache.removeResult(finderPath, finderArgs);
6571    
6572                                    throw processException(e);
6573                            }
6574                            finally {
6575                                    closeSession(session);
6576                            }
6577                    }
6578    
6579                    return list;
6580            }
6581    
6582            /**
6583             * Removes all the document library file versions from the database.
6584             *
6585             */
6586            @Override
6587            public void removeAll() {
6588                    for (DLFileVersion dlFileVersion : findAll()) {
6589                            remove(dlFileVersion);
6590                    }
6591            }
6592    
6593            /**
6594             * Returns the number of document library file versions.
6595             *
6596             * @return the number of document library file versions
6597             */
6598            @Override
6599            public int countAll() {
6600                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
6601                                    FINDER_ARGS_EMPTY, this);
6602    
6603                    if (count == null) {
6604                            Session session = null;
6605    
6606                            try {
6607                                    session = openSession();
6608    
6609                                    Query q = session.createQuery(_SQL_COUNT_DLFILEVERSION);
6610    
6611                                    count = (Long)q.uniqueResult();
6612    
6613                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
6614                                            count);
6615                            }
6616                            catch (Exception e) {
6617                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
6618                                            FINDER_ARGS_EMPTY);
6619    
6620                                    throw processException(e);
6621                            }
6622                            finally {
6623                                    closeSession(session);
6624                            }
6625                    }
6626    
6627                    return count.intValue();
6628            }
6629    
6630            @Override
6631            public Set<String> getBadColumnNames() {
6632                    return _badColumnNames;
6633            }
6634    
6635            @Override
6636            protected Map<String, Integer> getTableColumnsMap() {
6637                    return DLFileVersionModelImpl.TABLE_COLUMNS_MAP;
6638            }
6639    
6640            /**
6641             * Initializes the document library file version persistence.
6642             */
6643            public void afterPropertiesSet() {
6644            }
6645    
6646            public void destroy() {
6647                    entityCache.removeCache(DLFileVersionImpl.class.getName());
6648                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
6649                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6650                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6651            }
6652    
6653            @BeanReference(type = CompanyProviderWrapper.class)
6654            protected CompanyProvider companyProvider;
6655            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
6656            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
6657            private static final String _SQL_SELECT_DLFILEVERSION = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion";
6658            private static final String _SQL_SELECT_DLFILEVERSION_WHERE_PKS_IN = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE fileVersionId IN (";
6659            private static final String _SQL_SELECT_DLFILEVERSION_WHERE = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ";
6660            private static final String _SQL_COUNT_DLFILEVERSION = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion";
6661            private static final String _SQL_COUNT_DLFILEVERSION_WHERE = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion WHERE ";
6662            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileVersion.";
6663            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileVersion exists with the primary key ";
6664            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileVersion exists with the key {";
6665            private static final Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
6666            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
6667                                    "uuid", "size"
6668                            });
6669            private static final DLFileVersion _nullDLFileVersion = new DLFileVersionImpl() {
6670                            @Override
6671                            public Object clone() {
6672                                    return this;
6673                            }
6674    
6675                            @Override
6676                            public CacheModel<DLFileVersion> toCacheModel() {
6677                                    return _nullDLFileVersionCacheModel;
6678                            }
6679                    };
6680    
6681            private static final CacheModel<DLFileVersion> _nullDLFileVersionCacheModel = new CacheModel<DLFileVersion>() {
6682                            @Override
6683                            public DLFileVersion toEntityModel() {
6684                                    return _nullDLFileVersion;
6685                            }
6686                    };
6687    }