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