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