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