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_FILEENTRYID =
1463                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1464                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1465                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1466                            "findByFileEntryId",
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_FILEENTRYID =
1474                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1475                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1476                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1477                            "findByFileEntryId", new String[] { Long.class.getName() },
1478                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
1479                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
1480            public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYID = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1481                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1482                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileEntryId",
1483                            new String[] { Long.class.getName() });
1484    
1485            /**
1486             * Returns all the document library file versions where fileEntryId = &#63;.
1487             *
1488             * @param fileEntryId the file entry ID
1489             * @return the matching document library file versions
1490             * @throws SystemException if a system exception occurred
1491             */
1492            @Override
1493            public List<DLFileVersion> findByFileEntryId(long fileEntryId)
1494                    throws SystemException {
1495                    return findByFileEntryId(fileEntryId, QueryUtil.ALL_POS,
1496                            QueryUtil.ALL_POS, null);
1497            }
1498    
1499            /**
1500             * Returns a range of all the document library file versions where fileEntryId = &#63;.
1501             *
1502             * <p>
1503             * 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.
1504             * </p>
1505             *
1506             * @param fileEntryId the file entry ID
1507             * @param start the lower bound of the range of document library file versions
1508             * @param end the upper bound of the range of document library file versions (not inclusive)
1509             * @return the range of matching document library file versions
1510             * @throws SystemException if a system exception occurred
1511             */
1512            @Override
1513            public List<DLFileVersion> findByFileEntryId(long fileEntryId, int start,
1514                    int end) throws SystemException {
1515                    return findByFileEntryId(fileEntryId, start, end, null);
1516            }
1517    
1518            /**
1519             * Returns an ordered range of all the document library file versions where fileEntryId = &#63;.
1520             *
1521             * <p>
1522             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.
1523             * </p>
1524             *
1525             * @param fileEntryId the file entry ID
1526             * @param start the lower bound of the range of document library file versions
1527             * @param end the upper bound of the range of document library file versions (not inclusive)
1528             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1529             * @return the ordered range of matching document library file versions
1530             * @throws SystemException if a system exception occurred
1531             */
1532            @Override
1533            public List<DLFileVersion> findByFileEntryId(long fileEntryId, int start,
1534                    int end, OrderByComparator orderByComparator) throws SystemException {
1535                    boolean pagination = true;
1536                    FinderPath finderPath = null;
1537                    Object[] finderArgs = null;
1538    
1539                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1540                                    (orderByComparator == null)) {
1541                            pagination = false;
1542                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID;
1543                            finderArgs = new Object[] { fileEntryId };
1544                    }
1545                    else {
1546                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID;
1547                            finderArgs = new Object[] { fileEntryId, start, end, orderByComparator };
1548                    }
1549    
1550                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
1551                                    finderArgs, this);
1552    
1553                    if ((list != null) && !list.isEmpty()) {
1554                            for (DLFileVersion dlFileVersion : list) {
1555                                    if ((fileEntryId != dlFileVersion.getFileEntryId())) {
1556                                            list = null;
1557    
1558                                            break;
1559                                    }
1560                            }
1561                    }
1562    
1563                    if (list == null) {
1564                            StringBundler query = null;
1565    
1566                            if (orderByComparator != null) {
1567                                    query = new StringBundler(3 +
1568                                                    (orderByComparator.getOrderByFields().length * 3));
1569                            }
1570                            else {
1571                                    query = new StringBundler(3);
1572                            }
1573    
1574                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1575    
1576                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1577    
1578                            if (orderByComparator != null) {
1579                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1580                                            orderByComparator);
1581                            }
1582                            else
1583                             if (pagination) {
1584                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1585                            }
1586    
1587                            String sql = query.toString();
1588    
1589                            Session session = null;
1590    
1591                            try {
1592                                    session = openSession();
1593    
1594                                    Query q = session.createQuery(sql);
1595    
1596                                    QueryPos qPos = QueryPos.getInstance(q);
1597    
1598                                    qPos.add(fileEntryId);
1599    
1600                                    if (!pagination) {
1601                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1602                                                            start, end, false);
1603    
1604                                            Collections.sort(list);
1605    
1606                                            list = new UnmodifiableList<DLFileVersion>(list);
1607                                    }
1608                                    else {
1609                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1610                                                            start, end);
1611                                    }
1612    
1613                                    cacheResult(list);
1614    
1615                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1616                            }
1617                            catch (Exception e) {
1618                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1619    
1620                                    throw processException(e);
1621                            }
1622                            finally {
1623                                    closeSession(session);
1624                            }
1625                    }
1626    
1627                    return list;
1628            }
1629    
1630            /**
1631             * Returns the first document library file version in the ordered set where fileEntryId = &#63;.
1632             *
1633             * @param fileEntryId the file entry ID
1634             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1635             * @return the first matching document library file version
1636             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
1637             * @throws SystemException if a system exception occurred
1638             */
1639            @Override
1640            public DLFileVersion findByFileEntryId_First(long fileEntryId,
1641                    OrderByComparator orderByComparator)
1642                    throws NoSuchFileVersionException, SystemException {
1643                    DLFileVersion dlFileVersion = fetchByFileEntryId_First(fileEntryId,
1644                                    orderByComparator);
1645    
1646                    if (dlFileVersion != null) {
1647                            return dlFileVersion;
1648                    }
1649    
1650                    StringBundler msg = new StringBundler(4);
1651    
1652                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1653    
1654                    msg.append("fileEntryId=");
1655                    msg.append(fileEntryId);
1656    
1657                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1658    
1659                    throw new NoSuchFileVersionException(msg.toString());
1660            }
1661    
1662            /**
1663             * Returns the first document library file version in the ordered set where fileEntryId = &#63;.
1664             *
1665             * @param fileEntryId the file entry ID
1666             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1667             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
1668             * @throws SystemException if a system exception occurred
1669             */
1670            @Override
1671            public DLFileVersion fetchByFileEntryId_First(long fileEntryId,
1672                    OrderByComparator orderByComparator) throws SystemException {
1673                    List<DLFileVersion> list = findByFileEntryId(fileEntryId, 0, 1,
1674                                    orderByComparator);
1675    
1676                    if (!list.isEmpty()) {
1677                            return list.get(0);
1678                    }
1679    
1680                    return null;
1681            }
1682    
1683            /**
1684             * Returns the last document library file version in the ordered set where fileEntryId = &#63;.
1685             *
1686             * @param fileEntryId the file entry ID
1687             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1688             * @return the last matching document library file version
1689             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
1690             * @throws SystemException if a system exception occurred
1691             */
1692            @Override
1693            public DLFileVersion findByFileEntryId_Last(long fileEntryId,
1694                    OrderByComparator orderByComparator)
1695                    throws NoSuchFileVersionException, SystemException {
1696                    DLFileVersion dlFileVersion = fetchByFileEntryId_Last(fileEntryId,
1697                                    orderByComparator);
1698    
1699                    if (dlFileVersion != null) {
1700                            return dlFileVersion;
1701                    }
1702    
1703                    StringBundler msg = new StringBundler(4);
1704    
1705                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1706    
1707                    msg.append("fileEntryId=");
1708                    msg.append(fileEntryId);
1709    
1710                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1711    
1712                    throw new NoSuchFileVersionException(msg.toString());
1713            }
1714    
1715            /**
1716             * Returns the last document library file version in the ordered set where fileEntryId = &#63;.
1717             *
1718             * @param fileEntryId the file entry ID
1719             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1720             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
1721             * @throws SystemException if a system exception occurred
1722             */
1723            @Override
1724            public DLFileVersion fetchByFileEntryId_Last(long fileEntryId,
1725                    OrderByComparator orderByComparator) throws SystemException {
1726                    int count = countByFileEntryId(fileEntryId);
1727    
1728                    if (count == 0) {
1729                            return null;
1730                    }
1731    
1732                    List<DLFileVersion> list = findByFileEntryId(fileEntryId, count - 1,
1733                                    count, orderByComparator);
1734    
1735                    if (!list.isEmpty()) {
1736                            return list.get(0);
1737                    }
1738    
1739                    return null;
1740            }
1741    
1742            /**
1743             * Returns the document library file versions before and after the current document library file version in the ordered set where fileEntryId = &#63;.
1744             *
1745             * @param fileVersionId the primary key of the current document library file version
1746             * @param fileEntryId the file entry ID
1747             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1748             * @return the previous, current, and next document library file version
1749             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a document library file version with the primary key could not be found
1750             * @throws SystemException if a system exception occurred
1751             */
1752            @Override
1753            public DLFileVersion[] findByFileEntryId_PrevAndNext(long fileVersionId,
1754                    long fileEntryId, OrderByComparator orderByComparator)
1755                    throws NoSuchFileVersionException, SystemException {
1756                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1757    
1758                    Session session = null;
1759    
1760                    try {
1761                            session = openSession();
1762    
1763                            DLFileVersion[] array = new DLFileVersionImpl[3];
1764    
1765                            array[0] = getByFileEntryId_PrevAndNext(session, dlFileVersion,
1766                                            fileEntryId, orderByComparator, true);
1767    
1768                            array[1] = dlFileVersion;
1769    
1770                            array[2] = getByFileEntryId_PrevAndNext(session, dlFileVersion,
1771                                            fileEntryId, orderByComparator, false);
1772    
1773                            return array;
1774                    }
1775                    catch (Exception e) {
1776                            throw processException(e);
1777                    }
1778                    finally {
1779                            closeSession(session);
1780                    }
1781            }
1782    
1783            protected DLFileVersion getByFileEntryId_PrevAndNext(Session session,
1784                    DLFileVersion dlFileVersion, long fileEntryId,
1785                    OrderByComparator orderByComparator, boolean previous) {
1786                    StringBundler query = null;
1787    
1788                    if (orderByComparator != null) {
1789                            query = new StringBundler(6 +
1790                                            (orderByComparator.getOrderByFields().length * 6));
1791                    }
1792                    else {
1793                            query = new StringBundler(3);
1794                    }
1795    
1796                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1797    
1798                    query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1799    
1800                    if (orderByComparator != null) {
1801                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1802    
1803                            if (orderByConditionFields.length > 0) {
1804                                    query.append(WHERE_AND);
1805                            }
1806    
1807                            for (int i = 0; i < orderByConditionFields.length; i++) {
1808                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1809                                    query.append(orderByConditionFields[i]);
1810    
1811                                    if ((i + 1) < orderByConditionFields.length) {
1812                                            if (orderByComparator.isAscending() ^ previous) {
1813                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1814                                            }
1815                                            else {
1816                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1817                                            }
1818                                    }
1819                                    else {
1820                                            if (orderByComparator.isAscending() ^ previous) {
1821                                                    query.append(WHERE_GREATER_THAN);
1822                                            }
1823                                            else {
1824                                                    query.append(WHERE_LESSER_THAN);
1825                                            }
1826                                    }
1827                            }
1828    
1829                            query.append(ORDER_BY_CLAUSE);
1830    
1831                            String[] orderByFields = orderByComparator.getOrderByFields();
1832    
1833                            for (int i = 0; i < orderByFields.length; i++) {
1834                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1835                                    query.append(orderByFields[i]);
1836    
1837                                    if ((i + 1) < orderByFields.length) {
1838                                            if (orderByComparator.isAscending() ^ previous) {
1839                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1840                                            }
1841                                            else {
1842                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1843                                            }
1844                                    }
1845                                    else {
1846                                            if (orderByComparator.isAscending() ^ previous) {
1847                                                    query.append(ORDER_BY_ASC);
1848                                            }
1849                                            else {
1850                                                    query.append(ORDER_BY_DESC);
1851                                            }
1852                                    }
1853                            }
1854                    }
1855                    else {
1856                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1857                    }
1858    
1859                    String sql = query.toString();
1860    
1861                    Query q = session.createQuery(sql);
1862    
1863                    q.setFirstResult(0);
1864                    q.setMaxResults(2);
1865    
1866                    QueryPos qPos = QueryPos.getInstance(q);
1867    
1868                    qPos.add(fileEntryId);
1869    
1870                    if (orderByComparator != null) {
1871                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
1872    
1873                            for (Object value : values) {
1874                                    qPos.add(value);
1875                            }
1876                    }
1877    
1878                    List<DLFileVersion> list = q.list();
1879    
1880                    if (list.size() == 2) {
1881                            return list.get(1);
1882                    }
1883                    else {
1884                            return null;
1885                    }
1886            }
1887    
1888            /**
1889             * Removes all the document library file versions where fileEntryId = &#63; from the database.
1890             *
1891             * @param fileEntryId the file entry ID
1892             * @throws SystemException if a system exception occurred
1893             */
1894            @Override
1895            public void removeByFileEntryId(long fileEntryId) throws SystemException {
1896                    for (DLFileVersion dlFileVersion : findByFileEntryId(fileEntryId,
1897                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1898                            remove(dlFileVersion);
1899                    }
1900            }
1901    
1902            /**
1903             * Returns the number of document library file versions where fileEntryId = &#63;.
1904             *
1905             * @param fileEntryId the file entry ID
1906             * @return the number of matching document library file versions
1907             * @throws SystemException if a system exception occurred
1908             */
1909            @Override
1910            public int countByFileEntryId(long fileEntryId) throws SystemException {
1911                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEENTRYID;
1912    
1913                    Object[] finderArgs = new Object[] { fileEntryId };
1914    
1915                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1916                                    this);
1917    
1918                    if (count == null) {
1919                            StringBundler query = new StringBundler(2);
1920    
1921                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1922    
1923                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1924    
1925                            String sql = query.toString();
1926    
1927                            Session session = null;
1928    
1929                            try {
1930                                    session = openSession();
1931    
1932                                    Query q = session.createQuery(sql);
1933    
1934                                    QueryPos qPos = QueryPos.getInstance(q);
1935    
1936                                    qPos.add(fileEntryId);
1937    
1938                                    count = (Long)q.uniqueResult();
1939    
1940                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1941                            }
1942                            catch (Exception e) {
1943                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1944    
1945                                    throw processException(e);
1946                            }
1947                            finally {
1948                                    closeSession(session);
1949                            }
1950                    }
1951    
1952                    return count.intValue();
1953            }
1954    
1955            private static final String _FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ?";
1956            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_MIMETYPE = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1957                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1958                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1959                            "findByMimeType",
1960                            new String[] {
1961                                    String.class.getName(),
1962                                    
1963                            Integer.class.getName(), Integer.class.getName(),
1964                                    OrderByComparator.class.getName()
1965                            });
1966            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE =
1967                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1968                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
1969                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1970                            "findByMimeType", new String[] { String.class.getName() },
1971                            DLFileVersionModelImpl.MIMETYPE_COLUMN_BITMASK |
1972                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
1973                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
1974            public static final FinderPath FINDER_PATH_COUNT_BY_MIMETYPE = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
1975                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1976                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMimeType",
1977                            new String[] { String.class.getName() });
1978    
1979            /**
1980             * Returns all the document library file versions where mimeType = &#63;.
1981             *
1982             * @param mimeType the mime type
1983             * @return the matching document library file versions
1984             * @throws SystemException if a system exception occurred
1985             */
1986            @Override
1987            public List<DLFileVersion> findByMimeType(String mimeType)
1988                    throws SystemException {
1989                    return findByMimeType(mimeType, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1990                            null);
1991            }
1992    
1993            /**
1994             * Returns a range of all the document library file versions where mimeType = &#63;.
1995             *
1996             * <p>
1997             * 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.
1998             * </p>
1999             *
2000             * @param mimeType the mime type
2001             * @param start the lower bound of the range of document library file versions
2002             * @param end the upper bound of the range of document library file versions (not inclusive)
2003             * @return the range of matching document library file versions
2004             * @throws SystemException if a system exception occurred
2005             */
2006            @Override
2007            public List<DLFileVersion> findByMimeType(String mimeType, int start,
2008                    int end) throws SystemException {
2009                    return findByMimeType(mimeType, start, end, null);
2010            }
2011    
2012            /**
2013             * Returns an ordered range of all the document library file versions where mimeType = &#63;.
2014             *
2015             * <p>
2016             * 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.
2017             * </p>
2018             *
2019             * @param mimeType the mime type
2020             * @param start the lower bound of the range of document library file versions
2021             * @param end the upper bound of the range of document library file versions (not inclusive)
2022             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2023             * @return the ordered range of matching document library file versions
2024             * @throws SystemException if a system exception occurred
2025             */
2026            @Override
2027            public List<DLFileVersion> findByMimeType(String mimeType, int start,
2028                    int end, OrderByComparator orderByComparator) throws SystemException {
2029                    boolean pagination = true;
2030                    FinderPath finderPath = null;
2031                    Object[] finderArgs = null;
2032    
2033                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2034                                    (orderByComparator == null)) {
2035                            pagination = false;
2036                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE;
2037                            finderArgs = new Object[] { mimeType };
2038                    }
2039                    else {
2040                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_MIMETYPE;
2041                            finderArgs = new Object[] { mimeType, start, end, orderByComparator };
2042                    }
2043    
2044                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
2045                                    finderArgs, this);
2046    
2047                    if ((list != null) && !list.isEmpty()) {
2048                            for (DLFileVersion dlFileVersion : list) {
2049                                    if (!Validator.equals(mimeType, dlFileVersion.getMimeType())) {
2050                                            list = null;
2051    
2052                                            break;
2053                                    }
2054                            }
2055                    }
2056    
2057                    if (list == null) {
2058                            StringBundler query = null;
2059    
2060                            if (orderByComparator != null) {
2061                                    query = new StringBundler(3 +
2062                                                    (orderByComparator.getOrderByFields().length * 3));
2063                            }
2064                            else {
2065                                    query = new StringBundler(3);
2066                            }
2067    
2068                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2069    
2070                            boolean bindMimeType = false;
2071    
2072                            if (mimeType == null) {
2073                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
2074                            }
2075                            else if (mimeType.equals(StringPool.BLANK)) {
2076                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
2077                            }
2078                            else {
2079                                    bindMimeType = true;
2080    
2081                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
2082                            }
2083    
2084                            if (orderByComparator != null) {
2085                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2086                                            orderByComparator);
2087                            }
2088                            else
2089                             if (pagination) {
2090                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2091                            }
2092    
2093                            String sql = query.toString();
2094    
2095                            Session session = null;
2096    
2097                            try {
2098                                    session = openSession();
2099    
2100                                    Query q = session.createQuery(sql);
2101    
2102                                    QueryPos qPos = QueryPos.getInstance(q);
2103    
2104                                    if (bindMimeType) {
2105                                            qPos.add(mimeType);
2106                                    }
2107    
2108                                    if (!pagination) {
2109                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2110                                                            start, end, false);
2111    
2112                                            Collections.sort(list);
2113    
2114                                            list = new UnmodifiableList<DLFileVersion>(list);
2115                                    }
2116                                    else {
2117                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2118                                                            start, end);
2119                                    }
2120    
2121                                    cacheResult(list);
2122    
2123                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2124                            }
2125                            catch (Exception e) {
2126                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2127    
2128                                    throw processException(e);
2129                            }
2130                            finally {
2131                                    closeSession(session);
2132                            }
2133                    }
2134    
2135                    return list;
2136            }
2137    
2138            /**
2139             * Returns the first document library file version in the ordered set where mimeType = &#63;.
2140             *
2141             * @param mimeType the mime type
2142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2143             * @return the first matching document library file version
2144             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
2145             * @throws SystemException if a system exception occurred
2146             */
2147            @Override
2148            public DLFileVersion findByMimeType_First(String mimeType,
2149                    OrderByComparator orderByComparator)
2150                    throws NoSuchFileVersionException, SystemException {
2151                    DLFileVersion dlFileVersion = fetchByMimeType_First(mimeType,
2152                                    orderByComparator);
2153    
2154                    if (dlFileVersion != null) {
2155                            return dlFileVersion;
2156                    }
2157    
2158                    StringBundler msg = new StringBundler(4);
2159    
2160                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2161    
2162                    msg.append("mimeType=");
2163                    msg.append(mimeType);
2164    
2165                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2166    
2167                    throw new NoSuchFileVersionException(msg.toString());
2168            }
2169    
2170            /**
2171             * Returns the first document library file version in the ordered set where mimeType = &#63;.
2172             *
2173             * @param mimeType the mime type
2174             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2175             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
2176             * @throws SystemException if a system exception occurred
2177             */
2178            @Override
2179            public DLFileVersion fetchByMimeType_First(String mimeType,
2180                    OrderByComparator orderByComparator) throws SystemException {
2181                    List<DLFileVersion> list = findByMimeType(mimeType, 0, 1,
2182                                    orderByComparator);
2183    
2184                    if (!list.isEmpty()) {
2185                            return list.get(0);
2186                    }
2187    
2188                    return null;
2189            }
2190    
2191            /**
2192             * Returns the last document library file version in the ordered set where mimeType = &#63;.
2193             *
2194             * @param mimeType the mime type
2195             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2196             * @return the last matching document library file version
2197             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
2198             * @throws SystemException if a system exception occurred
2199             */
2200            @Override
2201            public DLFileVersion findByMimeType_Last(String mimeType,
2202                    OrderByComparator orderByComparator)
2203                    throws NoSuchFileVersionException, SystemException {
2204                    DLFileVersion dlFileVersion = fetchByMimeType_Last(mimeType,
2205                                    orderByComparator);
2206    
2207                    if (dlFileVersion != null) {
2208                            return dlFileVersion;
2209                    }
2210    
2211                    StringBundler msg = new StringBundler(4);
2212    
2213                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2214    
2215                    msg.append("mimeType=");
2216                    msg.append(mimeType);
2217    
2218                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2219    
2220                    throw new NoSuchFileVersionException(msg.toString());
2221            }
2222    
2223            /**
2224             * Returns the last document library file version in the ordered set where mimeType = &#63;.
2225             *
2226             * @param mimeType the mime type
2227             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2228             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
2229             * @throws SystemException if a system exception occurred
2230             */
2231            @Override
2232            public DLFileVersion fetchByMimeType_Last(String mimeType,
2233                    OrderByComparator orderByComparator) throws SystemException {
2234                    int count = countByMimeType(mimeType);
2235    
2236                    if (count == 0) {
2237                            return null;
2238                    }
2239    
2240                    List<DLFileVersion> list = findByMimeType(mimeType, count - 1, count,
2241                                    orderByComparator);
2242    
2243                    if (!list.isEmpty()) {
2244                            return list.get(0);
2245                    }
2246    
2247                    return null;
2248            }
2249    
2250            /**
2251             * Returns the document library file versions before and after the current document library file version in the ordered set where mimeType = &#63;.
2252             *
2253             * @param fileVersionId the primary key of the current document library file version
2254             * @param mimeType the mime type
2255             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2256             * @return the previous, current, and next document library file version
2257             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a document library file version with the primary key could not be found
2258             * @throws SystemException if a system exception occurred
2259             */
2260            @Override
2261            public DLFileVersion[] findByMimeType_PrevAndNext(long fileVersionId,
2262                    String mimeType, OrderByComparator orderByComparator)
2263                    throws NoSuchFileVersionException, SystemException {
2264                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
2265    
2266                    Session session = null;
2267    
2268                    try {
2269                            session = openSession();
2270    
2271                            DLFileVersion[] array = new DLFileVersionImpl[3];
2272    
2273                            array[0] = getByMimeType_PrevAndNext(session, dlFileVersion,
2274                                            mimeType, orderByComparator, true);
2275    
2276                            array[1] = dlFileVersion;
2277    
2278                            array[2] = getByMimeType_PrevAndNext(session, dlFileVersion,
2279                                            mimeType, orderByComparator, false);
2280    
2281                            return array;
2282                    }
2283                    catch (Exception e) {
2284                            throw processException(e);
2285                    }
2286                    finally {
2287                            closeSession(session);
2288                    }
2289            }
2290    
2291            protected DLFileVersion getByMimeType_PrevAndNext(Session session,
2292                    DLFileVersion dlFileVersion, String mimeType,
2293                    OrderByComparator orderByComparator, boolean previous) {
2294                    StringBundler query = null;
2295    
2296                    if (orderByComparator != null) {
2297                            query = new StringBundler(6 +
2298                                            (orderByComparator.getOrderByFields().length * 6));
2299                    }
2300                    else {
2301                            query = new StringBundler(3);
2302                    }
2303    
2304                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2305    
2306                    boolean bindMimeType = false;
2307    
2308                    if (mimeType == null) {
2309                            query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
2310                    }
2311                    else if (mimeType.equals(StringPool.BLANK)) {
2312                            query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
2313                    }
2314                    else {
2315                            bindMimeType = true;
2316    
2317                            query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
2318                    }
2319    
2320                    if (orderByComparator != null) {
2321                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2322    
2323                            if (orderByConditionFields.length > 0) {
2324                                    query.append(WHERE_AND);
2325                            }
2326    
2327                            for (int i = 0; i < orderByConditionFields.length; i++) {
2328                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2329                                    query.append(orderByConditionFields[i]);
2330    
2331                                    if ((i + 1) < orderByConditionFields.length) {
2332                                            if (orderByComparator.isAscending() ^ previous) {
2333                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2334                                            }
2335                                            else {
2336                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2337                                            }
2338                                    }
2339                                    else {
2340                                            if (orderByComparator.isAscending() ^ previous) {
2341                                                    query.append(WHERE_GREATER_THAN);
2342                                            }
2343                                            else {
2344                                                    query.append(WHERE_LESSER_THAN);
2345                                            }
2346                                    }
2347                            }
2348    
2349                            query.append(ORDER_BY_CLAUSE);
2350    
2351                            String[] orderByFields = orderByComparator.getOrderByFields();
2352    
2353                            for (int i = 0; i < orderByFields.length; i++) {
2354                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2355                                    query.append(orderByFields[i]);
2356    
2357                                    if ((i + 1) < orderByFields.length) {
2358                                            if (orderByComparator.isAscending() ^ previous) {
2359                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2360                                            }
2361                                            else {
2362                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2363                                            }
2364                                    }
2365                                    else {
2366                                            if (orderByComparator.isAscending() ^ previous) {
2367                                                    query.append(ORDER_BY_ASC);
2368                                            }
2369                                            else {
2370                                                    query.append(ORDER_BY_DESC);
2371                                            }
2372                                    }
2373                            }
2374                    }
2375                    else {
2376                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2377                    }
2378    
2379                    String sql = query.toString();
2380    
2381                    Query q = session.createQuery(sql);
2382    
2383                    q.setFirstResult(0);
2384                    q.setMaxResults(2);
2385    
2386                    QueryPos qPos = QueryPos.getInstance(q);
2387    
2388                    if (bindMimeType) {
2389                            qPos.add(mimeType);
2390                    }
2391    
2392                    if (orderByComparator != null) {
2393                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
2394    
2395                            for (Object value : values) {
2396                                    qPos.add(value);
2397                            }
2398                    }
2399    
2400                    List<DLFileVersion> list = q.list();
2401    
2402                    if (list.size() == 2) {
2403                            return list.get(1);
2404                    }
2405                    else {
2406                            return null;
2407                    }
2408            }
2409    
2410            /**
2411             * Removes all the document library file versions where mimeType = &#63; from the database.
2412             *
2413             * @param mimeType the mime type
2414             * @throws SystemException if a system exception occurred
2415             */
2416            @Override
2417            public void removeByMimeType(String mimeType) throws SystemException {
2418                    for (DLFileVersion dlFileVersion : findByMimeType(mimeType,
2419                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2420                            remove(dlFileVersion);
2421                    }
2422            }
2423    
2424            /**
2425             * Returns the number of document library file versions where mimeType = &#63;.
2426             *
2427             * @param mimeType the mime type
2428             * @return the number of matching document library file versions
2429             * @throws SystemException if a system exception occurred
2430             */
2431            @Override
2432            public int countByMimeType(String mimeType) throws SystemException {
2433                    FinderPath finderPath = FINDER_PATH_COUNT_BY_MIMETYPE;
2434    
2435                    Object[] finderArgs = new Object[] { mimeType };
2436    
2437                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2438                                    this);
2439    
2440                    if (count == null) {
2441                            StringBundler query = new StringBundler(2);
2442    
2443                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
2444    
2445                            boolean bindMimeType = false;
2446    
2447                            if (mimeType == null) {
2448                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_1);
2449                            }
2450                            else if (mimeType.equals(StringPool.BLANK)) {
2451                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_3);
2452                            }
2453                            else {
2454                                    bindMimeType = true;
2455    
2456                                    query.append(_FINDER_COLUMN_MIMETYPE_MIMETYPE_2);
2457                            }
2458    
2459                            String sql = query.toString();
2460    
2461                            Session session = null;
2462    
2463                            try {
2464                                    session = openSession();
2465    
2466                                    Query q = session.createQuery(sql);
2467    
2468                                    QueryPos qPos = QueryPos.getInstance(q);
2469    
2470                                    if (bindMimeType) {
2471                                            qPos.add(mimeType);
2472                                    }
2473    
2474                                    count = (Long)q.uniqueResult();
2475    
2476                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2477                            }
2478                            catch (Exception e) {
2479                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2480    
2481                                    throw processException(e);
2482                            }
2483                            finally {
2484                                    closeSession(session);
2485                            }
2486                    }
2487    
2488                    return count.intValue();
2489            }
2490    
2491            private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_1 = "dlFileVersion.mimeType IS NULL";
2492            private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_2 = "dlFileVersion.mimeType = ?";
2493            private static final String _FINDER_COLUMN_MIMETYPE_MIMETYPE_3 = "(dlFileVersion.mimeType IS NULL OR dlFileVersion.mimeType = '')";
2494            public static final FinderPath FINDER_PATH_FETCH_BY_F_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2495                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
2496                            DLFileVersionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByF_V",
2497                            new String[] { Long.class.getName(), String.class.getName() },
2498                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
2499                            DLFileVersionModelImpl.VERSION_COLUMN_BITMASK);
2500            public static final FinderPath FINDER_PATH_COUNT_BY_F_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2501                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2502                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByF_V",
2503                            new String[] { Long.class.getName(), String.class.getName() });
2504    
2505            /**
2506             * 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.
2507             *
2508             * @param fileEntryId the file entry ID
2509             * @param version the version
2510             * @return the matching document library file version
2511             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
2512             * @throws SystemException if a system exception occurred
2513             */
2514            @Override
2515            public DLFileVersion findByF_V(long fileEntryId, String version)
2516                    throws NoSuchFileVersionException, SystemException {
2517                    DLFileVersion dlFileVersion = fetchByF_V(fileEntryId, version);
2518    
2519                    if (dlFileVersion == null) {
2520                            StringBundler msg = new StringBundler(6);
2521    
2522                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2523    
2524                            msg.append("fileEntryId=");
2525                            msg.append(fileEntryId);
2526    
2527                            msg.append(", version=");
2528                            msg.append(version);
2529    
2530                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2531    
2532                            if (_log.isWarnEnabled()) {
2533                                    _log.warn(msg.toString());
2534                            }
2535    
2536                            throw new NoSuchFileVersionException(msg.toString());
2537                    }
2538    
2539                    return dlFileVersion;
2540            }
2541    
2542            /**
2543             * 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.
2544             *
2545             * @param fileEntryId the file entry ID
2546             * @param version the version
2547             * @return the matching document library file version, or <code>null</code> if a matching document library file version could not be found
2548             * @throws SystemException if a system exception occurred
2549             */
2550            @Override
2551            public DLFileVersion fetchByF_V(long fileEntryId, String version)
2552                    throws SystemException {
2553                    return fetchByF_V(fileEntryId, version, true);
2554            }
2555    
2556            /**
2557             * 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.
2558             *
2559             * @param fileEntryId the file entry ID
2560             * @param version the version
2561             * @param retrieveFromCache whether to use the finder cache
2562             * @return the matching document library file version, or <code>null</code> if a matching document library file version could not be found
2563             * @throws SystemException if a system exception occurred
2564             */
2565            @Override
2566            public DLFileVersion fetchByF_V(long fileEntryId, String version,
2567                    boolean retrieveFromCache) throws SystemException {
2568                    Object[] finderArgs = new Object[] { fileEntryId, version };
2569    
2570                    Object result = null;
2571    
2572                    if (retrieveFromCache) {
2573                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_F_V,
2574                                            finderArgs, this);
2575                    }
2576    
2577                    if (result instanceof DLFileVersion) {
2578                            DLFileVersion dlFileVersion = (DLFileVersion)result;
2579    
2580                            if ((fileEntryId != dlFileVersion.getFileEntryId()) ||
2581                                            !Validator.equals(version, dlFileVersion.getVersion())) {
2582                                    result = null;
2583                            }
2584                    }
2585    
2586                    if (result == null) {
2587                            StringBundler query = new StringBundler(4);
2588    
2589                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2590    
2591                            query.append(_FINDER_COLUMN_F_V_FILEENTRYID_2);
2592    
2593                            boolean bindVersion = false;
2594    
2595                            if (version == null) {
2596                                    query.append(_FINDER_COLUMN_F_V_VERSION_1);
2597                            }
2598                            else if (version.equals(StringPool.BLANK)) {
2599                                    query.append(_FINDER_COLUMN_F_V_VERSION_3);
2600                            }
2601                            else {
2602                                    bindVersion = true;
2603    
2604                                    query.append(_FINDER_COLUMN_F_V_VERSION_2);
2605                            }
2606    
2607                            String sql = query.toString();
2608    
2609                            Session session = null;
2610    
2611                            try {
2612                                    session = openSession();
2613    
2614                                    Query q = session.createQuery(sql);
2615    
2616                                    QueryPos qPos = QueryPos.getInstance(q);
2617    
2618                                    qPos.add(fileEntryId);
2619    
2620                                    if (bindVersion) {
2621                                            qPos.add(version);
2622                                    }
2623    
2624                                    List<DLFileVersion> list = q.list();
2625    
2626                                    if (list.isEmpty()) {
2627                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V,
2628                                                    finderArgs, list);
2629                                    }
2630                                    else {
2631                                            DLFileVersion dlFileVersion = list.get(0);
2632    
2633                                            result = dlFileVersion;
2634    
2635                                            cacheResult(dlFileVersion);
2636    
2637                                            if ((dlFileVersion.getFileEntryId() != fileEntryId) ||
2638                                                            (dlFileVersion.getVersion() == null) ||
2639                                                            !dlFileVersion.getVersion().equals(version)) {
2640                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V,
2641                                                            finderArgs, dlFileVersion);
2642                                            }
2643                                    }
2644                            }
2645                            catch (Exception e) {
2646                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_V,
2647                                            finderArgs);
2648    
2649                                    throw processException(e);
2650                            }
2651                            finally {
2652                                    closeSession(session);
2653                            }
2654                    }
2655    
2656                    if (result instanceof List<?>) {
2657                            return null;
2658                    }
2659                    else {
2660                            return (DLFileVersion)result;
2661                    }
2662            }
2663    
2664            /**
2665             * Removes the document library file version where fileEntryId = &#63; and version = &#63; from the database.
2666             *
2667             * @param fileEntryId the file entry ID
2668             * @param version the version
2669             * @return the document library file version that was removed
2670             * @throws SystemException if a system exception occurred
2671             */
2672            @Override
2673            public DLFileVersion removeByF_V(long fileEntryId, String version)
2674                    throws NoSuchFileVersionException, SystemException {
2675                    DLFileVersion dlFileVersion = findByF_V(fileEntryId, version);
2676    
2677                    return remove(dlFileVersion);
2678            }
2679    
2680            /**
2681             * Returns the number of document library file versions where fileEntryId = &#63; and version = &#63;.
2682             *
2683             * @param fileEntryId the file entry ID
2684             * @param version the version
2685             * @return the number of matching document library file versions
2686             * @throws SystemException if a system exception occurred
2687             */
2688            @Override
2689            public int countByF_V(long fileEntryId, String version)
2690                    throws SystemException {
2691                    FinderPath finderPath = FINDER_PATH_COUNT_BY_F_V;
2692    
2693                    Object[] finderArgs = new Object[] { fileEntryId, version };
2694    
2695                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2696                                    this);
2697    
2698                    if (count == null) {
2699                            StringBundler query = new StringBundler(3);
2700    
2701                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
2702    
2703                            query.append(_FINDER_COLUMN_F_V_FILEENTRYID_2);
2704    
2705                            boolean bindVersion = false;
2706    
2707                            if (version == null) {
2708                                    query.append(_FINDER_COLUMN_F_V_VERSION_1);
2709                            }
2710                            else if (version.equals(StringPool.BLANK)) {
2711                                    query.append(_FINDER_COLUMN_F_V_VERSION_3);
2712                            }
2713                            else {
2714                                    bindVersion = true;
2715    
2716                                    query.append(_FINDER_COLUMN_F_V_VERSION_2);
2717                            }
2718    
2719                            String sql = query.toString();
2720    
2721                            Session session = null;
2722    
2723                            try {
2724                                    session = openSession();
2725    
2726                                    Query q = session.createQuery(sql);
2727    
2728                                    QueryPos qPos = QueryPos.getInstance(q);
2729    
2730                                    qPos.add(fileEntryId);
2731    
2732                                    if (bindVersion) {
2733                                            qPos.add(version);
2734                                    }
2735    
2736                                    count = (Long)q.uniqueResult();
2737    
2738                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2739                            }
2740                            catch (Exception e) {
2741                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2742    
2743                                    throw processException(e);
2744                            }
2745                            finally {
2746                                    closeSession(session);
2747                            }
2748                    }
2749    
2750                    return count.intValue();
2751            }
2752    
2753            private static final String _FINDER_COLUMN_F_V_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ? AND ";
2754            private static final String _FINDER_COLUMN_F_V_VERSION_1 = "dlFileVersion.version IS NULL";
2755            private static final String _FINDER_COLUMN_F_V_VERSION_2 = "dlFileVersion.version = ?";
2756            private static final String _FINDER_COLUMN_F_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = '')";
2757            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2758                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
2759                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2760                            "findByF_S",
2761                            new String[] {
2762                                    Long.class.getName(), Integer.class.getName(),
2763                                    
2764                            Integer.class.getName(), Integer.class.getName(),
2765                                    OrderByComparator.class.getName()
2766                            });
2767            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2768                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
2769                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2770                            "findByF_S",
2771                            new String[] { Long.class.getName(), Integer.class.getName() },
2772                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
2773                            DLFileVersionModelImpl.STATUS_COLUMN_BITMASK |
2774                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
2775            public static final FinderPath FINDER_PATH_COUNT_BY_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
2776                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2777                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByF_S",
2778                            new String[] { Long.class.getName(), Integer.class.getName() });
2779    
2780            /**
2781             * Returns all the document library file versions where fileEntryId = &#63; and status = &#63;.
2782             *
2783             * @param fileEntryId the file entry ID
2784             * @param status the status
2785             * @return the matching document library file versions
2786             * @throws SystemException if a system exception occurred
2787             */
2788            @Override
2789            public List<DLFileVersion> findByF_S(long fileEntryId, int status)
2790                    throws SystemException {
2791                    return findByF_S(fileEntryId, status, QueryUtil.ALL_POS,
2792                            QueryUtil.ALL_POS, null);
2793            }
2794    
2795            /**
2796             * Returns a range of all the document library file versions where fileEntryId = &#63; and status = &#63;.
2797             *
2798             * <p>
2799             * 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.
2800             * </p>
2801             *
2802             * @param fileEntryId the file entry ID
2803             * @param status the status
2804             * @param start the lower bound of the range of document library file versions
2805             * @param end the upper bound of the range of document library file versions (not inclusive)
2806             * @return the range of matching document library file versions
2807             * @throws SystemException if a system exception occurred
2808             */
2809            @Override
2810            public List<DLFileVersion> findByF_S(long fileEntryId, int status,
2811                    int start, int end) throws SystemException {
2812                    return findByF_S(fileEntryId, status, start, end, null);
2813            }
2814    
2815            /**
2816             * Returns an ordered range of all the document library file versions where fileEntryId = &#63; and status = &#63;.
2817             *
2818             * <p>
2819             * 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.
2820             * </p>
2821             *
2822             * @param fileEntryId the file entry ID
2823             * @param status the status
2824             * @param start the lower bound of the range of document library file versions
2825             * @param end the upper bound of the range of document library file versions (not inclusive)
2826             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2827             * @return the ordered range of matching document library file versions
2828             * @throws SystemException if a system exception occurred
2829             */
2830            @Override
2831            public List<DLFileVersion> findByF_S(long fileEntryId, int status,
2832                    int start, int end, OrderByComparator orderByComparator)
2833                    throws SystemException {
2834                    boolean pagination = true;
2835                    FinderPath finderPath = null;
2836                    Object[] finderArgs = null;
2837    
2838                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2839                                    (orderByComparator == null)) {
2840                            pagination = false;
2841                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S;
2842                            finderArgs = new Object[] { fileEntryId, status };
2843                    }
2844                    else {
2845                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_F_S;
2846                            finderArgs = new Object[] {
2847                                            fileEntryId, status,
2848                                            
2849                                            start, end, orderByComparator
2850                                    };
2851                    }
2852    
2853                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
2854                                    finderArgs, this);
2855    
2856                    if ((list != null) && !list.isEmpty()) {
2857                            for (DLFileVersion dlFileVersion : list) {
2858                                    if ((fileEntryId != dlFileVersion.getFileEntryId()) ||
2859                                                    (status != dlFileVersion.getStatus())) {
2860                                            list = null;
2861    
2862                                            break;
2863                                    }
2864                            }
2865                    }
2866    
2867                    if (list == null) {
2868                            StringBundler query = null;
2869    
2870                            if (orderByComparator != null) {
2871                                    query = new StringBundler(4 +
2872                                                    (orderByComparator.getOrderByFields().length * 3));
2873                            }
2874                            else {
2875                                    query = new StringBundler(4);
2876                            }
2877    
2878                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
2879    
2880                            query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
2881    
2882                            query.append(_FINDER_COLUMN_F_S_STATUS_2);
2883    
2884                            if (orderByComparator != null) {
2885                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2886                                            orderByComparator);
2887                            }
2888                            else
2889                             if (pagination) {
2890                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
2891                            }
2892    
2893                            String sql = query.toString();
2894    
2895                            Session session = null;
2896    
2897                            try {
2898                                    session = openSession();
2899    
2900                                    Query q = session.createQuery(sql);
2901    
2902                                    QueryPos qPos = QueryPos.getInstance(q);
2903    
2904                                    qPos.add(fileEntryId);
2905    
2906                                    qPos.add(status);
2907    
2908                                    if (!pagination) {
2909                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2910                                                            start, end, false);
2911    
2912                                            Collections.sort(list);
2913    
2914                                            list = new UnmodifiableList<DLFileVersion>(list);
2915                                    }
2916                                    else {
2917                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
2918                                                            start, end);
2919                                    }
2920    
2921                                    cacheResult(list);
2922    
2923                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2924                            }
2925                            catch (Exception e) {
2926                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2927    
2928                                    throw processException(e);
2929                            }
2930                            finally {
2931                                    closeSession(session);
2932                            }
2933                    }
2934    
2935                    return list;
2936            }
2937    
2938            /**
2939             * Returns the first document library file version in the ordered set where fileEntryId = &#63; and status = &#63;.
2940             *
2941             * @param fileEntryId the file entry ID
2942             * @param status the status
2943             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2944             * @return the first matching document library file version
2945             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
2946             * @throws SystemException if a system exception occurred
2947             */
2948            @Override
2949            public DLFileVersion findByF_S_First(long fileEntryId, int status,
2950                    OrderByComparator orderByComparator)
2951                    throws NoSuchFileVersionException, SystemException {
2952                    DLFileVersion dlFileVersion = fetchByF_S_First(fileEntryId, status,
2953                                    orderByComparator);
2954    
2955                    if (dlFileVersion != null) {
2956                            return dlFileVersion;
2957                    }
2958    
2959                    StringBundler msg = new StringBundler(6);
2960    
2961                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2962    
2963                    msg.append("fileEntryId=");
2964                    msg.append(fileEntryId);
2965    
2966                    msg.append(", status=");
2967                    msg.append(status);
2968    
2969                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2970    
2971                    throw new NoSuchFileVersionException(msg.toString());
2972            }
2973    
2974            /**
2975             * Returns the first document library file version in the ordered set where fileEntryId = &#63; and status = &#63;.
2976             *
2977             * @param fileEntryId the file entry ID
2978             * @param status the status
2979             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2980             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
2981             * @throws SystemException if a system exception occurred
2982             */
2983            @Override
2984            public DLFileVersion fetchByF_S_First(long fileEntryId, int status,
2985                    OrderByComparator orderByComparator) throws SystemException {
2986                    List<DLFileVersion> list = findByF_S(fileEntryId, status, 0, 1,
2987                                    orderByComparator);
2988    
2989                    if (!list.isEmpty()) {
2990                            return list.get(0);
2991                    }
2992    
2993                    return null;
2994            }
2995    
2996            /**
2997             * Returns the last document library file version in the ordered set where fileEntryId = &#63; and status = &#63;.
2998             *
2999             * @param fileEntryId the file entry ID
3000             * @param status the status
3001             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3002             * @return the last matching document library file version
3003             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
3004             * @throws SystemException if a system exception occurred
3005             */
3006            @Override
3007            public DLFileVersion findByF_S_Last(long fileEntryId, int status,
3008                    OrderByComparator orderByComparator)
3009                    throws NoSuchFileVersionException, SystemException {
3010                    DLFileVersion dlFileVersion = fetchByF_S_Last(fileEntryId, status,
3011                                    orderByComparator);
3012    
3013                    if (dlFileVersion != null) {
3014                            return dlFileVersion;
3015                    }
3016    
3017                    StringBundler msg = new StringBundler(6);
3018    
3019                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3020    
3021                    msg.append("fileEntryId=");
3022                    msg.append(fileEntryId);
3023    
3024                    msg.append(", status=");
3025                    msg.append(status);
3026    
3027                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3028    
3029                    throw new NoSuchFileVersionException(msg.toString());
3030            }
3031    
3032            /**
3033             * Returns the last document library file version in the ordered set where fileEntryId = &#63; and status = &#63;.
3034             *
3035             * @param fileEntryId the file entry ID
3036             * @param status the status
3037             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3038             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
3039             * @throws SystemException if a system exception occurred
3040             */
3041            @Override
3042            public DLFileVersion fetchByF_S_Last(long fileEntryId, int status,
3043                    OrderByComparator orderByComparator) throws SystemException {
3044                    int count = countByF_S(fileEntryId, status);
3045    
3046                    if (count == 0) {
3047                            return null;
3048                    }
3049    
3050                    List<DLFileVersion> list = findByF_S(fileEntryId, status, count - 1,
3051                                    count, orderByComparator);
3052    
3053                    if (!list.isEmpty()) {
3054                            return list.get(0);
3055                    }
3056    
3057                    return null;
3058            }
3059    
3060            /**
3061             * 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;.
3062             *
3063             * @param fileVersionId the primary key of the current document library file version
3064             * @param fileEntryId the file entry ID
3065             * @param status the status
3066             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3067             * @return the previous, current, and next document library file version
3068             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a document library file version with the primary key could not be found
3069             * @throws SystemException if a system exception occurred
3070             */
3071            @Override
3072            public DLFileVersion[] findByF_S_PrevAndNext(long fileVersionId,
3073                    long fileEntryId, int status, OrderByComparator orderByComparator)
3074                    throws NoSuchFileVersionException, SystemException {
3075                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
3076    
3077                    Session session = null;
3078    
3079                    try {
3080                            session = openSession();
3081    
3082                            DLFileVersion[] array = new DLFileVersionImpl[3];
3083    
3084                            array[0] = getByF_S_PrevAndNext(session, dlFileVersion,
3085                                            fileEntryId, status, orderByComparator, true);
3086    
3087                            array[1] = dlFileVersion;
3088    
3089                            array[2] = getByF_S_PrevAndNext(session, dlFileVersion,
3090                                            fileEntryId, status, orderByComparator, false);
3091    
3092                            return array;
3093                    }
3094                    catch (Exception e) {
3095                            throw processException(e);
3096                    }
3097                    finally {
3098                            closeSession(session);
3099                    }
3100            }
3101    
3102            protected DLFileVersion getByF_S_PrevAndNext(Session session,
3103                    DLFileVersion dlFileVersion, long fileEntryId, int status,
3104                    OrderByComparator orderByComparator, boolean previous) {
3105                    StringBundler query = null;
3106    
3107                    if (orderByComparator != null) {
3108                            query = new StringBundler(6 +
3109                                            (orderByComparator.getOrderByFields().length * 6));
3110                    }
3111                    else {
3112                            query = new StringBundler(3);
3113                    }
3114    
3115                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3116    
3117                    query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
3118    
3119                    query.append(_FINDER_COLUMN_F_S_STATUS_2);
3120    
3121                    if (orderByComparator != null) {
3122                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3123    
3124                            if (orderByConditionFields.length > 0) {
3125                                    query.append(WHERE_AND);
3126                            }
3127    
3128                            for (int i = 0; i < orderByConditionFields.length; i++) {
3129                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3130                                    query.append(orderByConditionFields[i]);
3131    
3132                                    if ((i + 1) < orderByConditionFields.length) {
3133                                            if (orderByComparator.isAscending() ^ previous) {
3134                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3135                                            }
3136                                            else {
3137                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3138                                            }
3139                                    }
3140                                    else {
3141                                            if (orderByComparator.isAscending() ^ previous) {
3142                                                    query.append(WHERE_GREATER_THAN);
3143                                            }
3144                                            else {
3145                                                    query.append(WHERE_LESSER_THAN);
3146                                            }
3147                                    }
3148                            }
3149    
3150                            query.append(ORDER_BY_CLAUSE);
3151    
3152                            String[] orderByFields = orderByComparator.getOrderByFields();
3153    
3154                            for (int i = 0; i < orderByFields.length; i++) {
3155                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3156                                    query.append(orderByFields[i]);
3157    
3158                                    if ((i + 1) < orderByFields.length) {
3159                                            if (orderByComparator.isAscending() ^ previous) {
3160                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3161                                            }
3162                                            else {
3163                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3164                                            }
3165                                    }
3166                                    else {
3167                                            if (orderByComparator.isAscending() ^ previous) {
3168                                                    query.append(ORDER_BY_ASC);
3169                                            }
3170                                            else {
3171                                                    query.append(ORDER_BY_DESC);
3172                                            }
3173                                    }
3174                            }
3175                    }
3176                    else {
3177                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3178                    }
3179    
3180                    String sql = query.toString();
3181    
3182                    Query q = session.createQuery(sql);
3183    
3184                    q.setFirstResult(0);
3185                    q.setMaxResults(2);
3186    
3187                    QueryPos qPos = QueryPos.getInstance(q);
3188    
3189                    qPos.add(fileEntryId);
3190    
3191                    qPos.add(status);
3192    
3193                    if (orderByComparator != null) {
3194                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
3195    
3196                            for (Object value : values) {
3197                                    qPos.add(value);
3198                            }
3199                    }
3200    
3201                    List<DLFileVersion> list = q.list();
3202    
3203                    if (list.size() == 2) {
3204                            return list.get(1);
3205                    }
3206                    else {
3207                            return null;
3208                    }
3209            }
3210    
3211            /**
3212             * Removes all the document library file versions where fileEntryId = &#63; and status = &#63; from the database.
3213             *
3214             * @param fileEntryId the file entry ID
3215             * @param status the status
3216             * @throws SystemException if a system exception occurred
3217             */
3218            @Override
3219            public void removeByF_S(long fileEntryId, int status)
3220                    throws SystemException {
3221                    for (DLFileVersion dlFileVersion : findByF_S(fileEntryId, status,
3222                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3223                            remove(dlFileVersion);
3224                    }
3225            }
3226    
3227            /**
3228             * Returns the number of document library file versions where fileEntryId = &#63; and status = &#63;.
3229             *
3230             * @param fileEntryId the file entry ID
3231             * @param status the status
3232             * @return the number of matching document library file versions
3233             * @throws SystemException if a system exception occurred
3234             */
3235            @Override
3236            public int countByF_S(long fileEntryId, int status)
3237                    throws SystemException {
3238                    FinderPath finderPath = FINDER_PATH_COUNT_BY_F_S;
3239    
3240                    Object[] finderArgs = new Object[] { fileEntryId, status };
3241    
3242                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3243                                    this);
3244    
3245                    if (count == null) {
3246                            StringBundler query = new StringBundler(3);
3247    
3248                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
3249    
3250                            query.append(_FINDER_COLUMN_F_S_FILEENTRYID_2);
3251    
3252                            query.append(_FINDER_COLUMN_F_S_STATUS_2);
3253    
3254                            String sql = query.toString();
3255    
3256                            Session session = null;
3257    
3258                            try {
3259                                    session = openSession();
3260    
3261                                    Query q = session.createQuery(sql);
3262    
3263                                    QueryPos qPos = QueryPos.getInstance(q);
3264    
3265                                    qPos.add(fileEntryId);
3266    
3267                                    qPos.add(status);
3268    
3269                                    count = (Long)q.uniqueResult();
3270    
3271                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3272                            }
3273                            catch (Exception e) {
3274                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3275    
3276                                    throw processException(e);
3277                            }
3278                            finally {
3279                                    closeSession(session);
3280                            }
3281                    }
3282    
3283                    return count.intValue();
3284            }
3285    
3286            private static final String _FINDER_COLUMN_F_S_FILEENTRYID_2 = "dlFileVersion.fileEntryId = ? AND ";
3287            private static final String _FINDER_COLUMN_F_S_STATUS_2 = "dlFileVersion.status = ?";
3288            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3289                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3290                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3291                            "findByG_F_S",
3292                            new String[] {
3293                                    Long.class.getName(), Long.class.getName(),
3294                                    Integer.class.getName(),
3295                                    
3296                            Integer.class.getName(), Integer.class.getName(),
3297                                    OrderByComparator.class.getName()
3298                            });
3299            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3300                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3301                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3302                            "findByG_F_S",
3303                            new String[] {
3304                                    Long.class.getName(), Long.class.getName(),
3305                                    Integer.class.getName()
3306                            },
3307                            DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK |
3308                            DLFileVersionModelImpl.FOLDERID_COLUMN_BITMASK |
3309                            DLFileVersionModelImpl.STATUS_COLUMN_BITMASK |
3310                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
3311                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
3312            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3313                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3314                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F_S",
3315                            new String[] {
3316                                    Long.class.getName(), Long.class.getName(),
3317                                    Integer.class.getName()
3318                            });
3319    
3320            /**
3321             * Returns all the document library file versions where groupId = &#63; and folderId = &#63; and status = &#63;.
3322             *
3323             * @param groupId the group ID
3324             * @param folderId the folder ID
3325             * @param status the status
3326             * @return the matching document library file versions
3327             * @throws SystemException if a system exception occurred
3328             */
3329            @Override
3330            public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
3331                    int status) throws SystemException {
3332                    return findByG_F_S(groupId, folderId, status, QueryUtil.ALL_POS,
3333                            QueryUtil.ALL_POS, null);
3334            }
3335    
3336            /**
3337             * Returns a range of all the document library file versions where groupId = &#63; and folderId = &#63; and status = &#63;.
3338             *
3339             * <p>
3340             * 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.
3341             * </p>
3342             *
3343             * @param groupId the group ID
3344             * @param folderId the folder ID
3345             * @param status the status
3346             * @param start the lower bound of the range of document library file versions
3347             * @param end the upper bound of the range of document library file versions (not inclusive)
3348             * @return the range of matching document library file versions
3349             * @throws SystemException if a system exception occurred
3350             */
3351            @Override
3352            public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
3353                    int status, int start, int end) throws SystemException {
3354                    return findByG_F_S(groupId, folderId, status, start, end, null);
3355            }
3356    
3357            /**
3358             * Returns an ordered range of all the document library file versions where groupId = &#63; and folderId = &#63; and status = &#63;.
3359             *
3360             * <p>
3361             * 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.
3362             * </p>
3363             *
3364             * @param groupId the group ID
3365             * @param folderId the folder ID
3366             * @param status the status
3367             * @param start the lower bound of the range of document library file versions
3368             * @param end the upper bound of the range of document library file versions (not inclusive)
3369             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3370             * @return the ordered range of matching document library file versions
3371             * @throws SystemException if a system exception occurred
3372             */
3373            @Override
3374            public List<DLFileVersion> findByG_F_S(long groupId, long folderId,
3375                    int status, int start, int end, OrderByComparator orderByComparator)
3376                    throws SystemException {
3377                    boolean pagination = true;
3378                    FinderPath finderPath = null;
3379                    Object[] finderArgs = null;
3380    
3381                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3382                                    (orderByComparator == null)) {
3383                            pagination = false;
3384                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S;
3385                            finderArgs = new Object[] { groupId, folderId, status };
3386                    }
3387                    else {
3388                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_S;
3389                            finderArgs = new Object[] {
3390                                            groupId, folderId, status,
3391                                            
3392                                            start, end, orderByComparator
3393                                    };
3394                    }
3395    
3396                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
3397                                    finderArgs, this);
3398    
3399                    if ((list != null) && !list.isEmpty()) {
3400                            for (DLFileVersion dlFileVersion : list) {
3401                                    if ((groupId != dlFileVersion.getGroupId()) ||
3402                                                    (folderId != dlFileVersion.getFolderId()) ||
3403                                                    (status != dlFileVersion.getStatus())) {
3404                                            list = null;
3405    
3406                                            break;
3407                                    }
3408                            }
3409                    }
3410    
3411                    if (list == null) {
3412                            StringBundler query = null;
3413    
3414                            if (orderByComparator != null) {
3415                                    query = new StringBundler(5 +
3416                                                    (orderByComparator.getOrderByFields().length * 3));
3417                            }
3418                            else {
3419                                    query = new StringBundler(5);
3420                            }
3421    
3422                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3423    
3424                            query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
3425    
3426                            query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
3427    
3428                            query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
3429    
3430                            if (orderByComparator != null) {
3431                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3432                                            orderByComparator);
3433                            }
3434                            else
3435                             if (pagination) {
3436                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3437                            }
3438    
3439                            String sql = query.toString();
3440    
3441                            Session session = null;
3442    
3443                            try {
3444                                    session = openSession();
3445    
3446                                    Query q = session.createQuery(sql);
3447    
3448                                    QueryPos qPos = QueryPos.getInstance(q);
3449    
3450                                    qPos.add(groupId);
3451    
3452                                    qPos.add(folderId);
3453    
3454                                    qPos.add(status);
3455    
3456                                    if (!pagination) {
3457                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3458                                                            start, end, false);
3459    
3460                                            Collections.sort(list);
3461    
3462                                            list = new UnmodifiableList<DLFileVersion>(list);
3463                                    }
3464                                    else {
3465                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
3466                                                            start, end);
3467                                    }
3468    
3469                                    cacheResult(list);
3470    
3471                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3472                            }
3473                            catch (Exception e) {
3474                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3475    
3476                                    throw processException(e);
3477                            }
3478                            finally {
3479                                    closeSession(session);
3480                            }
3481                    }
3482    
3483                    return list;
3484            }
3485    
3486            /**
3487             * Returns the first document library file version in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
3488             *
3489             * @param groupId the group ID
3490             * @param folderId the folder ID
3491             * @param status the status
3492             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3493             * @return the first matching document library file version
3494             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
3495             * @throws SystemException if a system exception occurred
3496             */
3497            @Override
3498            public DLFileVersion findByG_F_S_First(long groupId, long folderId,
3499                    int status, OrderByComparator orderByComparator)
3500                    throws NoSuchFileVersionException, SystemException {
3501                    DLFileVersion dlFileVersion = fetchByG_F_S_First(groupId, folderId,
3502                                    status, orderByComparator);
3503    
3504                    if (dlFileVersion != null) {
3505                            return dlFileVersion;
3506                    }
3507    
3508                    StringBundler msg = new StringBundler(8);
3509    
3510                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3511    
3512                    msg.append("groupId=");
3513                    msg.append(groupId);
3514    
3515                    msg.append(", folderId=");
3516                    msg.append(folderId);
3517    
3518                    msg.append(", status=");
3519                    msg.append(status);
3520    
3521                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3522    
3523                    throw new NoSuchFileVersionException(msg.toString());
3524            }
3525    
3526            /**
3527             * Returns the first document library file version in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
3528             *
3529             * @param groupId the group ID
3530             * @param folderId the folder ID
3531             * @param status the status
3532             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3533             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
3534             * @throws SystemException if a system exception occurred
3535             */
3536            @Override
3537            public DLFileVersion fetchByG_F_S_First(long groupId, long folderId,
3538                    int status, OrderByComparator orderByComparator)
3539                    throws SystemException {
3540                    List<DLFileVersion> list = findByG_F_S(groupId, folderId, status, 0, 1,
3541                                    orderByComparator);
3542    
3543                    if (!list.isEmpty()) {
3544                            return list.get(0);
3545                    }
3546    
3547                    return null;
3548            }
3549    
3550            /**
3551             * Returns the last document library file version in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
3552             *
3553             * @param groupId the group ID
3554             * @param folderId the folder ID
3555             * @param status the status
3556             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3557             * @return the last matching document library file version
3558             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
3559             * @throws SystemException if a system exception occurred
3560             */
3561            @Override
3562            public DLFileVersion findByG_F_S_Last(long groupId, long folderId,
3563                    int status, OrderByComparator orderByComparator)
3564                    throws NoSuchFileVersionException, SystemException {
3565                    DLFileVersion dlFileVersion = fetchByG_F_S_Last(groupId, folderId,
3566                                    status, orderByComparator);
3567    
3568                    if (dlFileVersion != null) {
3569                            return dlFileVersion;
3570                    }
3571    
3572                    StringBundler msg = new StringBundler(8);
3573    
3574                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3575    
3576                    msg.append("groupId=");
3577                    msg.append(groupId);
3578    
3579                    msg.append(", folderId=");
3580                    msg.append(folderId);
3581    
3582                    msg.append(", status=");
3583                    msg.append(status);
3584    
3585                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3586    
3587                    throw new NoSuchFileVersionException(msg.toString());
3588            }
3589    
3590            /**
3591             * Returns the last document library file version in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
3592             *
3593             * @param groupId the group ID
3594             * @param folderId the folder ID
3595             * @param status the status
3596             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3597             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
3598             * @throws SystemException if a system exception occurred
3599             */
3600            @Override
3601            public DLFileVersion fetchByG_F_S_Last(long groupId, long folderId,
3602                    int status, OrderByComparator orderByComparator)
3603                    throws SystemException {
3604                    int count = countByG_F_S(groupId, folderId, status);
3605    
3606                    if (count == 0) {
3607                            return null;
3608                    }
3609    
3610                    List<DLFileVersion> list = findByG_F_S(groupId, folderId, status,
3611                                    count - 1, count, orderByComparator);
3612    
3613                    if (!list.isEmpty()) {
3614                            return list.get(0);
3615                    }
3616    
3617                    return null;
3618            }
3619    
3620            /**
3621             * 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;.
3622             *
3623             * @param fileVersionId the primary key of the current document library file version
3624             * @param groupId the group ID
3625             * @param folderId the folder ID
3626             * @param status the status
3627             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3628             * @return the previous, current, and next document library file version
3629             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a document library file version with the primary key could not be found
3630             * @throws SystemException if a system exception occurred
3631             */
3632            @Override
3633            public DLFileVersion[] findByG_F_S_PrevAndNext(long fileVersionId,
3634                    long groupId, long folderId, int status,
3635                    OrderByComparator orderByComparator)
3636                    throws NoSuchFileVersionException, SystemException {
3637                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
3638    
3639                    Session session = null;
3640    
3641                    try {
3642                            session = openSession();
3643    
3644                            DLFileVersion[] array = new DLFileVersionImpl[3];
3645    
3646                            array[0] = getByG_F_S_PrevAndNext(session, dlFileVersion, groupId,
3647                                            folderId, status, orderByComparator, true);
3648    
3649                            array[1] = dlFileVersion;
3650    
3651                            array[2] = getByG_F_S_PrevAndNext(session, dlFileVersion, groupId,
3652                                            folderId, status, orderByComparator, false);
3653    
3654                            return array;
3655                    }
3656                    catch (Exception e) {
3657                            throw processException(e);
3658                    }
3659                    finally {
3660                            closeSession(session);
3661                    }
3662            }
3663    
3664            protected DLFileVersion getByG_F_S_PrevAndNext(Session session,
3665                    DLFileVersion dlFileVersion, long groupId, long folderId, int status,
3666                    OrderByComparator orderByComparator, boolean previous) {
3667                    StringBundler query = null;
3668    
3669                    if (orderByComparator != null) {
3670                            query = new StringBundler(6 +
3671                                            (orderByComparator.getOrderByFields().length * 6));
3672                    }
3673                    else {
3674                            query = new StringBundler(3);
3675                    }
3676    
3677                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
3678    
3679                    query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
3680    
3681                    query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
3682    
3683                    query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
3684    
3685                    if (orderByComparator != null) {
3686                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3687    
3688                            if (orderByConditionFields.length > 0) {
3689                                    query.append(WHERE_AND);
3690                            }
3691    
3692                            for (int i = 0; i < orderByConditionFields.length; i++) {
3693                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3694                                    query.append(orderByConditionFields[i]);
3695    
3696                                    if ((i + 1) < orderByConditionFields.length) {
3697                                            if (orderByComparator.isAscending() ^ previous) {
3698                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3699                                            }
3700                                            else {
3701                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3702                                            }
3703                                    }
3704                                    else {
3705                                            if (orderByComparator.isAscending() ^ previous) {
3706                                                    query.append(WHERE_GREATER_THAN);
3707                                            }
3708                                            else {
3709                                                    query.append(WHERE_LESSER_THAN);
3710                                            }
3711                                    }
3712                            }
3713    
3714                            query.append(ORDER_BY_CLAUSE);
3715    
3716                            String[] orderByFields = orderByComparator.getOrderByFields();
3717    
3718                            for (int i = 0; i < orderByFields.length; i++) {
3719                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3720                                    query.append(orderByFields[i]);
3721    
3722                                    if ((i + 1) < orderByFields.length) {
3723                                            if (orderByComparator.isAscending() ^ previous) {
3724                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3725                                            }
3726                                            else {
3727                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3728                                            }
3729                                    }
3730                                    else {
3731                                            if (orderByComparator.isAscending() ^ previous) {
3732                                                    query.append(ORDER_BY_ASC);
3733                                            }
3734                                            else {
3735                                                    query.append(ORDER_BY_DESC);
3736                                            }
3737                                    }
3738                            }
3739                    }
3740                    else {
3741                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
3742                    }
3743    
3744                    String sql = query.toString();
3745    
3746                    Query q = session.createQuery(sql);
3747    
3748                    q.setFirstResult(0);
3749                    q.setMaxResults(2);
3750    
3751                    QueryPos qPos = QueryPos.getInstance(q);
3752    
3753                    qPos.add(groupId);
3754    
3755                    qPos.add(folderId);
3756    
3757                    qPos.add(status);
3758    
3759                    if (orderByComparator != null) {
3760                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
3761    
3762                            for (Object value : values) {
3763                                    qPos.add(value);
3764                            }
3765                    }
3766    
3767                    List<DLFileVersion> list = q.list();
3768    
3769                    if (list.size() == 2) {
3770                            return list.get(1);
3771                    }
3772                    else {
3773                            return null;
3774                    }
3775            }
3776    
3777            /**
3778             * Removes all the document library file versions where groupId = &#63; and folderId = &#63; and status = &#63; from the database.
3779             *
3780             * @param groupId the group ID
3781             * @param folderId the folder ID
3782             * @param status the status
3783             * @throws SystemException if a system exception occurred
3784             */
3785            @Override
3786            public void removeByG_F_S(long groupId, long folderId, int status)
3787                    throws SystemException {
3788                    for (DLFileVersion dlFileVersion : findByG_F_S(groupId, folderId,
3789                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3790                            remove(dlFileVersion);
3791                    }
3792            }
3793    
3794            /**
3795             * Returns the number of document library file versions where groupId = &#63; and folderId = &#63; and status = &#63;.
3796             *
3797             * @param groupId the group ID
3798             * @param folderId the folder ID
3799             * @param status the status
3800             * @return the number of matching document library file versions
3801             * @throws SystemException if a system exception occurred
3802             */
3803            @Override
3804            public int countByG_F_S(long groupId, long folderId, int status)
3805                    throws SystemException {
3806                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_F_S;
3807    
3808                    Object[] finderArgs = new Object[] { groupId, folderId, status };
3809    
3810                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3811                                    this);
3812    
3813                    if (count == null) {
3814                            StringBundler query = new StringBundler(4);
3815    
3816                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
3817    
3818                            query.append(_FINDER_COLUMN_G_F_S_GROUPID_2);
3819    
3820                            query.append(_FINDER_COLUMN_G_F_S_FOLDERID_2);
3821    
3822                            query.append(_FINDER_COLUMN_G_F_S_STATUS_2);
3823    
3824                            String sql = query.toString();
3825    
3826                            Session session = null;
3827    
3828                            try {
3829                                    session = openSession();
3830    
3831                                    Query q = session.createQuery(sql);
3832    
3833                                    QueryPos qPos = QueryPos.getInstance(q);
3834    
3835                                    qPos.add(groupId);
3836    
3837                                    qPos.add(folderId);
3838    
3839                                    qPos.add(status);
3840    
3841                                    count = (Long)q.uniqueResult();
3842    
3843                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3844                            }
3845                            catch (Exception e) {
3846                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3847    
3848                                    throw processException(e);
3849                            }
3850                            finally {
3851                                    closeSession(session);
3852                            }
3853                    }
3854    
3855                    return count.intValue();
3856            }
3857    
3858            private static final String _FINDER_COLUMN_G_F_S_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
3859            private static final String _FINDER_COLUMN_G_F_S_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
3860            private static final String _FINDER_COLUMN_G_F_S_STATUS_2 = "dlFileVersion.status = ?";
3861            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_T_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3862                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3863                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3864                            "findByG_F_T_V",
3865                            new String[] {
3866                                    Long.class.getName(), Long.class.getName(),
3867                                    String.class.getName(), String.class.getName(),
3868                                    
3869                            Integer.class.getName(), Integer.class.getName(),
3870                                    OrderByComparator.class.getName()
3871                            });
3872            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V =
3873                    new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3874                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
3875                            DLFileVersionImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3876                            "findByG_F_T_V",
3877                            new String[] {
3878                                    Long.class.getName(), Long.class.getName(),
3879                                    String.class.getName(), String.class.getName()
3880                            },
3881                            DLFileVersionModelImpl.GROUPID_COLUMN_BITMASK |
3882                            DLFileVersionModelImpl.FOLDERID_COLUMN_BITMASK |
3883                            DLFileVersionModelImpl.TITLE_COLUMN_BITMASK |
3884                            DLFileVersionModelImpl.VERSION_COLUMN_BITMASK |
3885                            DLFileVersionModelImpl.FILEENTRYID_COLUMN_BITMASK |
3886                            DLFileVersionModelImpl.CREATEDATE_COLUMN_BITMASK);
3887            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_T_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
3888                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3889                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F_T_V",
3890                            new String[] {
3891                                    Long.class.getName(), Long.class.getName(),
3892                                    String.class.getName(), String.class.getName()
3893                            });
3894    
3895            /**
3896             * Returns all the document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
3897             *
3898             * @param groupId the group ID
3899             * @param folderId the folder ID
3900             * @param title the title
3901             * @param version the version
3902             * @return the matching document library file versions
3903             * @throws SystemException if a system exception occurred
3904             */
3905            @Override
3906            public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
3907                    String title, String version) throws SystemException {
3908                    return findByG_F_T_V(groupId, folderId, title, version,
3909                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3910            }
3911    
3912            /**
3913             * Returns a range of all the document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
3914             *
3915             * <p>
3916             * 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.
3917             * </p>
3918             *
3919             * @param groupId the group ID
3920             * @param folderId the folder ID
3921             * @param title the title
3922             * @param version the version
3923             * @param start the lower bound of the range of document library file versions
3924             * @param end the upper bound of the range of document library file versions (not inclusive)
3925             * @return the range of matching document library file versions
3926             * @throws SystemException if a system exception occurred
3927             */
3928            @Override
3929            public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
3930                    String title, String version, int start, int end)
3931                    throws SystemException {
3932                    return findByG_F_T_V(groupId, folderId, title, version, start, end, null);
3933            }
3934    
3935            /**
3936             * Returns an ordered range of all the document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
3937             *
3938             * <p>
3939             * 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.
3940             * </p>
3941             *
3942             * @param groupId the group ID
3943             * @param folderId the folder ID
3944             * @param title the title
3945             * @param version the version
3946             * @param start the lower bound of the range of document library file versions
3947             * @param end the upper bound of the range of document library file versions (not inclusive)
3948             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3949             * @return the ordered range of matching document library file versions
3950             * @throws SystemException if a system exception occurred
3951             */
3952            @Override
3953            public List<DLFileVersion> findByG_F_T_V(long groupId, long folderId,
3954                    String title, String version, int start, int end,
3955                    OrderByComparator orderByComparator) throws SystemException {
3956                    boolean pagination = true;
3957                    FinderPath finderPath = null;
3958                    Object[] finderArgs = null;
3959    
3960                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3961                                    (orderByComparator == null)) {
3962                            pagination = false;
3963                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V;
3964                            finderArgs = new Object[] { groupId, folderId, title, version };
3965                    }
3966                    else {
3967                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_T_V;
3968                            finderArgs = new Object[] {
3969                                            groupId, folderId, title, version,
3970                                            
3971                                            start, end, orderByComparator
3972                                    };
3973                    }
3974    
3975                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
3976                                    finderArgs, this);
3977    
3978                    if ((list != null) && !list.isEmpty()) {
3979                            for (DLFileVersion dlFileVersion : list) {
3980                                    if ((groupId != dlFileVersion.getGroupId()) ||
3981                                                    (folderId != dlFileVersion.getFolderId()) ||
3982                                                    !Validator.equals(title, dlFileVersion.getTitle()) ||
3983                                                    !Validator.equals(version, dlFileVersion.getVersion())) {
3984                                            list = null;
3985    
3986                                            break;
3987                                    }
3988                            }
3989                    }
3990    
3991                    if (list == null) {
3992                            StringBundler query = null;
3993    
3994                            if (orderByComparator != null) {
3995                                    query = new StringBundler(6 +
3996                                                    (orderByComparator.getOrderByFields().length * 3));
3997                            }
3998                            else {
3999                                    query = new StringBundler(6);
4000                            }
4001    
4002                            query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
4003    
4004                            query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
4005    
4006                            query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
4007    
4008                            boolean bindTitle = false;
4009    
4010                            if (title == null) {
4011                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
4012                            }
4013                            else if (title.equals(StringPool.BLANK)) {
4014                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
4015                            }
4016                            else {
4017                                    bindTitle = true;
4018    
4019                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
4020                            }
4021    
4022                            boolean bindVersion = false;
4023    
4024                            if (version == null) {
4025                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
4026                            }
4027                            else if (version.equals(StringPool.BLANK)) {
4028                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
4029                            }
4030                            else {
4031                                    bindVersion = true;
4032    
4033                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
4034                            }
4035    
4036                            if (orderByComparator != null) {
4037                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4038                                            orderByComparator);
4039                            }
4040                            else
4041                             if (pagination) {
4042                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
4043                            }
4044    
4045                            String sql = query.toString();
4046    
4047                            Session session = null;
4048    
4049                            try {
4050                                    session = openSession();
4051    
4052                                    Query q = session.createQuery(sql);
4053    
4054                                    QueryPos qPos = QueryPos.getInstance(q);
4055    
4056                                    qPos.add(groupId);
4057    
4058                                    qPos.add(folderId);
4059    
4060                                    if (bindTitle) {
4061                                            qPos.add(title);
4062                                    }
4063    
4064                                    if (bindVersion) {
4065                                            qPos.add(version);
4066                                    }
4067    
4068                                    if (!pagination) {
4069                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4070                                                            start, end, false);
4071    
4072                                            Collections.sort(list);
4073    
4074                                            list = new UnmodifiableList<DLFileVersion>(list);
4075                                    }
4076                                    else {
4077                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
4078                                                            start, end);
4079                                    }
4080    
4081                                    cacheResult(list);
4082    
4083                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4084                            }
4085                            catch (Exception e) {
4086                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4087    
4088                                    throw processException(e);
4089                            }
4090                            finally {
4091                                    closeSession(session);
4092                            }
4093                    }
4094    
4095                    return list;
4096            }
4097    
4098            /**
4099             * Returns the first document library file version in the ordered set where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
4100             *
4101             * @param groupId the group ID
4102             * @param folderId the folder ID
4103             * @param title the title
4104             * @param version the version
4105             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4106             * @return the first matching document library file version
4107             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
4108             * @throws SystemException if a system exception occurred
4109             */
4110            @Override
4111            public DLFileVersion findByG_F_T_V_First(long groupId, long folderId,
4112                    String title, String version, OrderByComparator orderByComparator)
4113                    throws NoSuchFileVersionException, SystemException {
4114                    DLFileVersion dlFileVersion = fetchByG_F_T_V_First(groupId, folderId,
4115                                    title, version, orderByComparator);
4116    
4117                    if (dlFileVersion != null) {
4118                            return dlFileVersion;
4119                    }
4120    
4121                    StringBundler msg = new StringBundler(10);
4122    
4123                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4124    
4125                    msg.append("groupId=");
4126                    msg.append(groupId);
4127    
4128                    msg.append(", folderId=");
4129                    msg.append(folderId);
4130    
4131                    msg.append(", title=");
4132                    msg.append(title);
4133    
4134                    msg.append(", version=");
4135                    msg.append(version);
4136    
4137                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4138    
4139                    throw new NoSuchFileVersionException(msg.toString());
4140            }
4141    
4142            /**
4143             * Returns the first document library file version in the ordered set where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
4144             *
4145             * @param groupId the group ID
4146             * @param folderId the folder ID
4147             * @param title the title
4148             * @param version the version
4149             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4150             * @return the first matching document library file version, or <code>null</code> if a matching document library file version could not be found
4151             * @throws SystemException if a system exception occurred
4152             */
4153            @Override
4154            public DLFileVersion fetchByG_F_T_V_First(long groupId, long folderId,
4155                    String title, String version, OrderByComparator orderByComparator)
4156                    throws SystemException {
4157                    List<DLFileVersion> list = findByG_F_T_V(groupId, folderId, title,
4158                                    version, 0, 1, orderByComparator);
4159    
4160                    if (!list.isEmpty()) {
4161                            return list.get(0);
4162                    }
4163    
4164                    return null;
4165            }
4166    
4167            /**
4168             * Returns the last document library file version in the ordered set where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
4169             *
4170             * @param groupId the group ID
4171             * @param folderId the folder ID
4172             * @param title the title
4173             * @param version the version
4174             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4175             * @return the last matching document library file version
4176             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a matching document library file version could not be found
4177             * @throws SystemException if a system exception occurred
4178             */
4179            @Override
4180            public DLFileVersion findByG_F_T_V_Last(long groupId, long folderId,
4181                    String title, String version, OrderByComparator orderByComparator)
4182                    throws NoSuchFileVersionException, SystemException {
4183                    DLFileVersion dlFileVersion = fetchByG_F_T_V_Last(groupId, folderId,
4184                                    title, version, orderByComparator);
4185    
4186                    if (dlFileVersion != null) {
4187                            return dlFileVersion;
4188                    }
4189    
4190                    StringBundler msg = new StringBundler(10);
4191    
4192                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4193    
4194                    msg.append("groupId=");
4195                    msg.append(groupId);
4196    
4197                    msg.append(", folderId=");
4198                    msg.append(folderId);
4199    
4200                    msg.append(", title=");
4201                    msg.append(title);
4202    
4203                    msg.append(", version=");
4204                    msg.append(version);
4205    
4206                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4207    
4208                    throw new NoSuchFileVersionException(msg.toString());
4209            }
4210    
4211            /**
4212             * Returns the last document library file version in the ordered set where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
4213             *
4214             * @param groupId the group ID
4215             * @param folderId the folder ID
4216             * @param title the title
4217             * @param version the version
4218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4219             * @return the last matching document library file version, or <code>null</code> if a matching document library file version could not be found
4220             * @throws SystemException if a system exception occurred
4221             */
4222            @Override
4223            public DLFileVersion fetchByG_F_T_V_Last(long groupId, long folderId,
4224                    String title, String version, OrderByComparator orderByComparator)
4225                    throws SystemException {
4226                    int count = countByG_F_T_V(groupId, folderId, title, version);
4227    
4228                    if (count == 0) {
4229                            return null;
4230                    }
4231    
4232                    List<DLFileVersion> list = findByG_F_T_V(groupId, folderId, title,
4233                                    version, count - 1, count, orderByComparator);
4234    
4235                    if (!list.isEmpty()) {
4236                            return list.get(0);
4237                    }
4238    
4239                    return null;
4240            }
4241    
4242            /**
4243             * 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;.
4244             *
4245             * @param fileVersionId the primary key of the current document library file version
4246             * @param groupId the group ID
4247             * @param folderId the folder ID
4248             * @param title the title
4249             * @param version the version
4250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4251             * @return the previous, current, and next document library file version
4252             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a document library file version with the primary key could not be found
4253             * @throws SystemException if a system exception occurred
4254             */
4255            @Override
4256            public DLFileVersion[] findByG_F_T_V_PrevAndNext(long fileVersionId,
4257                    long groupId, long folderId, String title, String version,
4258                    OrderByComparator orderByComparator)
4259                    throws NoSuchFileVersionException, SystemException {
4260                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
4261    
4262                    Session session = null;
4263    
4264                    try {
4265                            session = openSession();
4266    
4267                            DLFileVersion[] array = new DLFileVersionImpl[3];
4268    
4269                            array[0] = getByG_F_T_V_PrevAndNext(session, dlFileVersion,
4270                                            groupId, folderId, title, version, orderByComparator, true);
4271    
4272                            array[1] = dlFileVersion;
4273    
4274                            array[2] = getByG_F_T_V_PrevAndNext(session, dlFileVersion,
4275                                            groupId, folderId, title, version, orderByComparator, false);
4276    
4277                            return array;
4278                    }
4279                    catch (Exception e) {
4280                            throw processException(e);
4281                    }
4282                    finally {
4283                            closeSession(session);
4284                    }
4285            }
4286    
4287            protected DLFileVersion getByG_F_T_V_PrevAndNext(Session session,
4288                    DLFileVersion dlFileVersion, long groupId, long folderId, String title,
4289                    String version, OrderByComparator orderByComparator, boolean previous) {
4290                    StringBundler query = null;
4291    
4292                    if (orderByComparator != null) {
4293                            query = new StringBundler(6 +
4294                                            (orderByComparator.getOrderByFields().length * 6));
4295                    }
4296                    else {
4297                            query = new StringBundler(3);
4298                    }
4299    
4300                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
4301    
4302                    query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
4303    
4304                    query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
4305    
4306                    boolean bindTitle = false;
4307    
4308                    if (title == null) {
4309                            query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
4310                    }
4311                    else if (title.equals(StringPool.BLANK)) {
4312                            query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
4313                    }
4314                    else {
4315                            bindTitle = true;
4316    
4317                            query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
4318                    }
4319    
4320                    boolean bindVersion = false;
4321    
4322                    if (version == null) {
4323                            query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
4324                    }
4325                    else if (version.equals(StringPool.BLANK)) {
4326                            query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
4327                    }
4328                    else {
4329                            bindVersion = true;
4330    
4331                            query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
4332                    }
4333    
4334                    if (orderByComparator != null) {
4335                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4336    
4337                            if (orderByConditionFields.length > 0) {
4338                                    query.append(WHERE_AND);
4339                            }
4340    
4341                            for (int i = 0; i < orderByConditionFields.length; i++) {
4342                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4343                                    query.append(orderByConditionFields[i]);
4344    
4345                                    if ((i + 1) < orderByConditionFields.length) {
4346                                            if (orderByComparator.isAscending() ^ previous) {
4347                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4348                                            }
4349                                            else {
4350                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4351                                            }
4352                                    }
4353                                    else {
4354                                            if (orderByComparator.isAscending() ^ previous) {
4355                                                    query.append(WHERE_GREATER_THAN);
4356                                            }
4357                                            else {
4358                                                    query.append(WHERE_LESSER_THAN);
4359                                            }
4360                                    }
4361                            }
4362    
4363                            query.append(ORDER_BY_CLAUSE);
4364    
4365                            String[] orderByFields = orderByComparator.getOrderByFields();
4366    
4367                            for (int i = 0; i < orderByFields.length; i++) {
4368                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4369                                    query.append(orderByFields[i]);
4370    
4371                                    if ((i + 1) < orderByFields.length) {
4372                                            if (orderByComparator.isAscending() ^ previous) {
4373                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4374                                            }
4375                                            else {
4376                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4377                                            }
4378                                    }
4379                                    else {
4380                                            if (orderByComparator.isAscending() ^ previous) {
4381                                                    query.append(ORDER_BY_ASC);
4382                                            }
4383                                            else {
4384                                                    query.append(ORDER_BY_DESC);
4385                                            }
4386                                    }
4387                            }
4388                    }
4389                    else {
4390                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
4391                    }
4392    
4393                    String sql = query.toString();
4394    
4395                    Query q = session.createQuery(sql);
4396    
4397                    q.setFirstResult(0);
4398                    q.setMaxResults(2);
4399    
4400                    QueryPos qPos = QueryPos.getInstance(q);
4401    
4402                    qPos.add(groupId);
4403    
4404                    qPos.add(folderId);
4405    
4406                    if (bindTitle) {
4407                            qPos.add(title);
4408                    }
4409    
4410                    if (bindVersion) {
4411                            qPos.add(version);
4412                    }
4413    
4414                    if (orderByComparator != null) {
4415                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileVersion);
4416    
4417                            for (Object value : values) {
4418                                    qPos.add(value);
4419                            }
4420                    }
4421    
4422                    List<DLFileVersion> list = q.list();
4423    
4424                    if (list.size() == 2) {
4425                            return list.get(1);
4426                    }
4427                    else {
4428                            return null;
4429                    }
4430            }
4431    
4432            /**
4433             * Removes all the document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63; from the database.
4434             *
4435             * @param groupId the group ID
4436             * @param folderId the folder ID
4437             * @param title the title
4438             * @param version the version
4439             * @throws SystemException if a system exception occurred
4440             */
4441            @Override
4442            public void removeByG_F_T_V(long groupId, long folderId, String title,
4443                    String version) throws SystemException {
4444                    for (DLFileVersion dlFileVersion : findByG_F_T_V(groupId, folderId,
4445                                    title, version, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4446                            remove(dlFileVersion);
4447                    }
4448            }
4449    
4450            /**
4451             * Returns the number of document library file versions where groupId = &#63; and folderId = &#63; and title = &#63; and version = &#63;.
4452             *
4453             * @param groupId the group ID
4454             * @param folderId the folder ID
4455             * @param title the title
4456             * @param version the version
4457             * @return the number of matching document library file versions
4458             * @throws SystemException if a system exception occurred
4459             */
4460            @Override
4461            public int countByG_F_T_V(long groupId, long folderId, String title,
4462                    String version) throws SystemException {
4463                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_F_T_V;
4464    
4465                    Object[] finderArgs = new Object[] { groupId, folderId, title, version };
4466    
4467                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4468                                    this);
4469    
4470                    if (count == null) {
4471                            StringBundler query = new StringBundler(5);
4472    
4473                            query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
4474    
4475                            query.append(_FINDER_COLUMN_G_F_T_V_GROUPID_2);
4476    
4477                            query.append(_FINDER_COLUMN_G_F_T_V_FOLDERID_2);
4478    
4479                            boolean bindTitle = false;
4480    
4481                            if (title == null) {
4482                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_1);
4483                            }
4484                            else if (title.equals(StringPool.BLANK)) {
4485                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_3);
4486                            }
4487                            else {
4488                                    bindTitle = true;
4489    
4490                                    query.append(_FINDER_COLUMN_G_F_T_V_TITLE_2);
4491                            }
4492    
4493                            boolean bindVersion = false;
4494    
4495                            if (version == null) {
4496                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_1);
4497                            }
4498                            else if (version.equals(StringPool.BLANK)) {
4499                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_3);
4500                            }
4501                            else {
4502                                    bindVersion = true;
4503    
4504                                    query.append(_FINDER_COLUMN_G_F_T_V_VERSION_2);
4505                            }
4506    
4507                            String sql = query.toString();
4508    
4509                            Session session = null;
4510    
4511                            try {
4512                                    session = openSession();
4513    
4514                                    Query q = session.createQuery(sql);
4515    
4516                                    QueryPos qPos = QueryPos.getInstance(q);
4517    
4518                                    qPos.add(groupId);
4519    
4520                                    qPos.add(folderId);
4521    
4522                                    if (bindTitle) {
4523                                            qPos.add(title);
4524                                    }
4525    
4526                                    if (bindVersion) {
4527                                            qPos.add(version);
4528                                    }
4529    
4530                                    count = (Long)q.uniqueResult();
4531    
4532                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4533                            }
4534                            catch (Exception e) {
4535                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4536    
4537                                    throw processException(e);
4538                            }
4539                            finally {
4540                                    closeSession(session);
4541                            }
4542                    }
4543    
4544                    return count.intValue();
4545            }
4546    
4547            private static final String _FINDER_COLUMN_G_F_T_V_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
4548            private static final String _FINDER_COLUMN_G_F_T_V_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
4549            private static final String _FINDER_COLUMN_G_F_T_V_TITLE_1 = "dlFileVersion.title IS NULL AND ";
4550            private static final String _FINDER_COLUMN_G_F_T_V_TITLE_2 = "dlFileVersion.title = ? AND ";
4551            private static final String _FINDER_COLUMN_G_F_T_V_TITLE_3 = "(dlFileVersion.title IS NULL OR dlFileVersion.title = '') AND ";
4552            private static final String _FINDER_COLUMN_G_F_T_V_VERSION_1 = "dlFileVersion.version IS NULL";
4553            private static final String _FINDER_COLUMN_G_F_T_V_VERSION_2 = "dlFileVersion.version = ?";
4554            private static final String _FINDER_COLUMN_G_F_T_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = '')";
4555    
4556            /**
4557             * Caches the document library file version in the entity cache if it is enabled.
4558             *
4559             * @param dlFileVersion the document library file version
4560             */
4561            @Override
4562            public void cacheResult(DLFileVersion dlFileVersion) {
4563                    EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4564                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
4565                            dlFileVersion);
4566    
4567                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
4568                            new Object[] { dlFileVersion.getUuid(), dlFileVersion.getGroupId() },
4569                            dlFileVersion);
4570    
4571                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V,
4572                            new Object[] {
4573                                    dlFileVersion.getFileEntryId(), dlFileVersion.getVersion()
4574                            }, dlFileVersion);
4575    
4576                    dlFileVersion.resetOriginalValues();
4577            }
4578    
4579            /**
4580             * Caches the document library file versions in the entity cache if it is enabled.
4581             *
4582             * @param dlFileVersions the document library file versions
4583             */
4584            @Override
4585            public void cacheResult(List<DLFileVersion> dlFileVersions) {
4586                    for (DLFileVersion dlFileVersion : dlFileVersions) {
4587                            if (EntityCacheUtil.getResult(
4588                                                    DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4589                                                    DLFileVersionImpl.class, dlFileVersion.getPrimaryKey()) == null) {
4590                                    cacheResult(dlFileVersion);
4591                            }
4592                            else {
4593                                    dlFileVersion.resetOriginalValues();
4594                            }
4595                    }
4596            }
4597    
4598            /**
4599             * Clears the cache for all document library file versions.
4600             *
4601             * <p>
4602             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4603             * </p>
4604             */
4605            @Override
4606            public void clearCache() {
4607                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4608                            CacheRegistryUtil.clear(DLFileVersionImpl.class.getName());
4609                    }
4610    
4611                    EntityCacheUtil.clearCache(DLFileVersionImpl.class.getName());
4612    
4613                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4614                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4615                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4616            }
4617    
4618            /**
4619             * Clears the cache for the document library file version.
4620             *
4621             * <p>
4622             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4623             * </p>
4624             */
4625            @Override
4626            public void clearCache(DLFileVersion dlFileVersion) {
4627                    EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4628                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
4629    
4630                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4631                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4632    
4633                    clearUniqueFindersCache(dlFileVersion);
4634            }
4635    
4636            @Override
4637            public void clearCache(List<DLFileVersion> dlFileVersions) {
4638                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4639                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4640    
4641                    for (DLFileVersion dlFileVersion : dlFileVersions) {
4642                            EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
4643                                    DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
4644    
4645                            clearUniqueFindersCache(dlFileVersion);
4646                    }
4647            }
4648    
4649            protected void cacheUniqueFindersCache(DLFileVersion dlFileVersion) {
4650                    if (dlFileVersion.isNew()) {
4651                            Object[] args = new Object[] {
4652                                            dlFileVersion.getUuid(), dlFileVersion.getGroupId()
4653                                    };
4654    
4655                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4656                                    Long.valueOf(1));
4657                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4658                                    dlFileVersion);
4659    
4660                            args = new Object[] {
4661                                            dlFileVersion.getFileEntryId(), dlFileVersion.getVersion()
4662                                    };
4663    
4664                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_V, args,
4665                                    Long.valueOf(1));
4666                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V, args,
4667                                    dlFileVersion);
4668                    }
4669                    else {
4670                            DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
4671    
4672                            if ((dlFileVersionModelImpl.getColumnBitmask() &
4673                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4674                                    Object[] args = new Object[] {
4675                                                    dlFileVersion.getUuid(), dlFileVersion.getGroupId()
4676                                            };
4677    
4678                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4679                                            Long.valueOf(1));
4680                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4681                                            dlFileVersion);
4682                            }
4683    
4684                            if ((dlFileVersionModelImpl.getColumnBitmask() &
4685                                            FINDER_PATH_FETCH_BY_F_V.getColumnBitmask()) != 0) {
4686                                    Object[] args = new Object[] {
4687                                                    dlFileVersion.getFileEntryId(),
4688                                                    dlFileVersion.getVersion()
4689                                            };
4690    
4691                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_F_V, args,
4692                                            Long.valueOf(1));
4693                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_F_V, args,
4694                                            dlFileVersion);
4695                            }
4696                    }
4697            }
4698    
4699            protected void clearUniqueFindersCache(DLFileVersion dlFileVersion) {
4700                    DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
4701    
4702                    Object[] args = new Object[] {
4703                                    dlFileVersion.getUuid(), dlFileVersion.getGroupId()
4704                            };
4705    
4706                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4707                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4708    
4709                    if ((dlFileVersionModelImpl.getColumnBitmask() &
4710                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4711                            args = new Object[] {
4712                                            dlFileVersionModelImpl.getOriginalUuid(),
4713                                            dlFileVersionModelImpl.getOriginalGroupId()
4714                                    };
4715    
4716                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4717                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4718                    }
4719    
4720                    args = new Object[] {
4721                                    dlFileVersion.getFileEntryId(), dlFileVersion.getVersion()
4722                            };
4723    
4724                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_V, args);
4725                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_V, args);
4726    
4727                    if ((dlFileVersionModelImpl.getColumnBitmask() &
4728                                    FINDER_PATH_FETCH_BY_F_V.getColumnBitmask()) != 0) {
4729                            args = new Object[] {
4730                                            dlFileVersionModelImpl.getOriginalFileEntryId(),
4731                                            dlFileVersionModelImpl.getOriginalVersion()
4732                                    };
4733    
4734                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_V, args);
4735                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_F_V, args);
4736                    }
4737            }
4738    
4739            /**
4740             * Creates a new document library file version with the primary key. Does not add the document library file version to the database.
4741             *
4742             * @param fileVersionId the primary key for the new document library file version
4743             * @return the new document library file version
4744             */
4745            @Override
4746            public DLFileVersion create(long fileVersionId) {
4747                    DLFileVersion dlFileVersion = new DLFileVersionImpl();
4748    
4749                    dlFileVersion.setNew(true);
4750                    dlFileVersion.setPrimaryKey(fileVersionId);
4751    
4752                    String uuid = PortalUUIDUtil.generate();
4753    
4754                    dlFileVersion.setUuid(uuid);
4755    
4756                    return dlFileVersion;
4757            }
4758    
4759            /**
4760             * Removes the document library file version with the primary key from the database. Also notifies the appropriate model listeners.
4761             *
4762             * @param fileVersionId the primary key of the document library file version
4763             * @return the document library file version that was removed
4764             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a document library file version with the primary key could not be found
4765             * @throws SystemException if a system exception occurred
4766             */
4767            @Override
4768            public DLFileVersion remove(long fileVersionId)
4769                    throws NoSuchFileVersionException, SystemException {
4770                    return remove((Serializable)fileVersionId);
4771            }
4772    
4773            /**
4774             * Removes the document library file version with the primary key from the database. Also notifies the appropriate model listeners.
4775             *
4776             * @param primaryKey the primary key of the document library file version
4777             * @return the document library file version that was removed
4778             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a document library file version with the primary key could not be found
4779             * @throws SystemException if a system exception occurred
4780             */
4781            @Override
4782            public DLFileVersion remove(Serializable primaryKey)
4783                    throws NoSuchFileVersionException, SystemException {
4784                    Session session = null;
4785    
4786                    try {
4787                            session = openSession();
4788    
4789                            DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
4790                                            primaryKey);
4791    
4792                            if (dlFileVersion == null) {
4793                                    if (_log.isWarnEnabled()) {
4794                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4795                                    }
4796    
4797                                    throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4798                                            primaryKey);
4799                            }
4800    
4801                            return remove(dlFileVersion);
4802                    }
4803                    catch (NoSuchFileVersionException nsee) {
4804                            throw nsee;
4805                    }
4806                    catch (Exception e) {
4807                            throw processException(e);
4808                    }
4809                    finally {
4810                            closeSession(session);
4811                    }
4812            }
4813    
4814            @Override
4815            protected DLFileVersion removeImpl(DLFileVersion dlFileVersion)
4816                    throws SystemException {
4817                    dlFileVersion = toUnwrappedModel(dlFileVersion);
4818    
4819                    Session session = null;
4820    
4821                    try {
4822                            session = openSession();
4823    
4824                            if (!session.contains(dlFileVersion)) {
4825                                    dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
4826                                                    dlFileVersion.getPrimaryKeyObj());
4827                            }
4828    
4829                            if (dlFileVersion != null) {
4830                                    session.delete(dlFileVersion);
4831                            }
4832                    }
4833                    catch (Exception e) {
4834                            throw processException(e);
4835                    }
4836                    finally {
4837                            closeSession(session);
4838                    }
4839    
4840                    if (dlFileVersion != null) {
4841                            clearCache(dlFileVersion);
4842                    }
4843    
4844                    return dlFileVersion;
4845            }
4846    
4847            @Override
4848            public DLFileVersion updateImpl(
4849                    com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion)
4850                    throws SystemException {
4851                    dlFileVersion = toUnwrappedModel(dlFileVersion);
4852    
4853                    boolean isNew = dlFileVersion.isNew();
4854    
4855                    DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
4856    
4857                    if (Validator.isNull(dlFileVersion.getUuid())) {
4858                            String uuid = PortalUUIDUtil.generate();
4859    
4860                            dlFileVersion.setUuid(uuid);
4861                    }
4862    
4863                    Session session = null;
4864    
4865                    try {
4866                            session = openSession();
4867    
4868                            if (dlFileVersion.isNew()) {
4869                                    session.save(dlFileVersion);
4870    
4871                                    dlFileVersion.setNew(false);
4872                            }
4873                            else {
4874                                    session.merge(dlFileVersion);
4875                            }
4876                    }
4877                    catch (Exception e) {
4878                            throw processException(e);
4879                    }
4880                    finally {
4881                            closeSession(session);
4882                    }
4883    
4884                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4885    
4886                    if (isNew || !DLFileVersionModelImpl.COLUMN_BITMASK_ENABLED) {
4887                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4888                    }
4889    
4890                    else {
4891                            if ((dlFileVersionModelImpl.getColumnBitmask() &
4892                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4893                                    Object[] args = new Object[] {
4894                                                    dlFileVersionModelImpl.getOriginalUuid()
4895                                            };
4896    
4897                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4898                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4899                                            args);
4900    
4901                                    args = new Object[] { dlFileVersionModelImpl.getUuid() };
4902    
4903                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4904                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4905                                            args);
4906                            }
4907    
4908                            if ((dlFileVersionModelImpl.getColumnBitmask() &
4909                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4910                                    Object[] args = new Object[] {
4911                                                    dlFileVersionModelImpl.getOriginalUuid(),
4912                                                    dlFileVersionModelImpl.getOriginalCompanyId()
4913                                            };
4914    
4915                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4916                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4917                                            args);
4918    
4919                                    args = new Object[] {
4920                                                    dlFileVersionModelImpl.getUuid(),
4921                                                    dlFileVersionModelImpl.getCompanyId()
4922                                            };
4923    
4924                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4925                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4926                                            args);
4927                            }
4928    
4929                            if ((dlFileVersionModelImpl.getColumnBitmask() &
4930                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
4931                                    Object[] args = new Object[] {
4932                                                    dlFileVersionModelImpl.getOriginalFileEntryId()
4933                                            };
4934    
4935                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
4936                                            args);
4937                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
4938                                            args);
4939    
4940                                    args = new Object[] { dlFileVersionModelImpl.getFileEntryId() };
4941    
4942                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
4943                                            args);
4944                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
4945                                            args);
4946                            }
4947    
4948                            if ((dlFileVersionModelImpl.getColumnBitmask() &
4949                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE.getColumnBitmask()) != 0) {
4950                                    Object[] args = new Object[] {
4951                                                    dlFileVersionModelImpl.getOriginalMimeType()
4952                                            };
4953    
4954                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MIMETYPE, args);
4955                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE,
4956                                            args);
4957    
4958                                    args = new Object[] { dlFileVersionModelImpl.getMimeType() };
4959    
4960                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MIMETYPE, args);
4961                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_MIMETYPE,
4962                                            args);
4963                            }
4964    
4965                            if ((dlFileVersionModelImpl.getColumnBitmask() &
4966                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S.getColumnBitmask()) != 0) {
4967                                    Object[] args = new Object[] {
4968                                                    dlFileVersionModelImpl.getOriginalFileEntryId(),
4969                                                    dlFileVersionModelImpl.getOriginalStatus()
4970                                            };
4971    
4972                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_S, args);
4973                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S,
4974                                            args);
4975    
4976                                    args = new Object[] {
4977                                                    dlFileVersionModelImpl.getFileEntryId(),
4978                                                    dlFileVersionModelImpl.getStatus()
4979                                            };
4980    
4981                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_F_S, args);
4982                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_F_S,
4983                                            args);
4984                            }
4985    
4986                            if ((dlFileVersionModelImpl.getColumnBitmask() &
4987                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S.getColumnBitmask()) != 0) {
4988                                    Object[] args = new Object[] {
4989                                                    dlFileVersionModelImpl.getOriginalGroupId(),
4990                                                    dlFileVersionModelImpl.getOriginalFolderId(),
4991                                                    dlFileVersionModelImpl.getOriginalStatus()
4992                                            };
4993    
4994                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_S, args);
4995                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S,
4996                                            args);
4997    
4998                                    args = new Object[] {
4999                                                    dlFileVersionModelImpl.getGroupId(),
5000                                                    dlFileVersionModelImpl.getFolderId(),
5001                                                    dlFileVersionModelImpl.getStatus()
5002                                            };
5003    
5004                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_S, args);
5005                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_S,
5006                                            args);
5007                            }
5008    
5009                            if ((dlFileVersionModelImpl.getColumnBitmask() &
5010                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V.getColumnBitmask()) != 0) {
5011                                    Object[] args = new Object[] {
5012                                                    dlFileVersionModelImpl.getOriginalGroupId(),
5013                                                    dlFileVersionModelImpl.getOriginalFolderId(),
5014                                                    dlFileVersionModelImpl.getOriginalTitle(),
5015                                                    dlFileVersionModelImpl.getOriginalVersion()
5016                                            };
5017    
5018                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_T_V, args);
5019                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V,
5020                                            args);
5021    
5022                                    args = new Object[] {
5023                                                    dlFileVersionModelImpl.getGroupId(),
5024                                                    dlFileVersionModelImpl.getFolderId(),
5025                                                    dlFileVersionModelImpl.getTitle(),
5026                                                    dlFileVersionModelImpl.getVersion()
5027                                            };
5028    
5029                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_T_V, args);
5030                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_T_V,
5031                                            args);
5032                            }
5033                    }
5034    
5035                    EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5036                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
5037                            dlFileVersion);
5038    
5039                    clearUniqueFindersCache(dlFileVersion);
5040                    cacheUniqueFindersCache(dlFileVersion);
5041    
5042                    return dlFileVersion;
5043            }
5044    
5045            protected DLFileVersion toUnwrappedModel(DLFileVersion dlFileVersion) {
5046                    if (dlFileVersion instanceof DLFileVersionImpl) {
5047                            return dlFileVersion;
5048                    }
5049    
5050                    DLFileVersionImpl dlFileVersionImpl = new DLFileVersionImpl();
5051    
5052                    dlFileVersionImpl.setNew(dlFileVersion.isNew());
5053                    dlFileVersionImpl.setPrimaryKey(dlFileVersion.getPrimaryKey());
5054    
5055                    dlFileVersionImpl.setUuid(dlFileVersion.getUuid());
5056                    dlFileVersionImpl.setFileVersionId(dlFileVersion.getFileVersionId());
5057                    dlFileVersionImpl.setGroupId(dlFileVersion.getGroupId());
5058                    dlFileVersionImpl.setCompanyId(dlFileVersion.getCompanyId());
5059                    dlFileVersionImpl.setUserId(dlFileVersion.getUserId());
5060                    dlFileVersionImpl.setUserName(dlFileVersion.getUserName());
5061                    dlFileVersionImpl.setCreateDate(dlFileVersion.getCreateDate());
5062                    dlFileVersionImpl.setModifiedDate(dlFileVersion.getModifiedDate());
5063                    dlFileVersionImpl.setRepositoryId(dlFileVersion.getRepositoryId());
5064                    dlFileVersionImpl.setFolderId(dlFileVersion.getFolderId());
5065                    dlFileVersionImpl.setFileEntryId(dlFileVersion.getFileEntryId());
5066                    dlFileVersionImpl.setExtension(dlFileVersion.getExtension());
5067                    dlFileVersionImpl.setMimeType(dlFileVersion.getMimeType());
5068                    dlFileVersionImpl.setTitle(dlFileVersion.getTitle());
5069                    dlFileVersionImpl.setDescription(dlFileVersion.getDescription());
5070                    dlFileVersionImpl.setChangeLog(dlFileVersion.getChangeLog());
5071                    dlFileVersionImpl.setExtraSettings(dlFileVersion.getExtraSettings());
5072                    dlFileVersionImpl.setFileEntryTypeId(dlFileVersion.getFileEntryTypeId());
5073                    dlFileVersionImpl.setVersion(dlFileVersion.getVersion());
5074                    dlFileVersionImpl.setSize(dlFileVersion.getSize());
5075                    dlFileVersionImpl.setChecksum(dlFileVersion.getChecksum());
5076                    dlFileVersionImpl.setStatus(dlFileVersion.getStatus());
5077                    dlFileVersionImpl.setStatusByUserId(dlFileVersion.getStatusByUserId());
5078                    dlFileVersionImpl.setStatusByUserName(dlFileVersion.getStatusByUserName());
5079                    dlFileVersionImpl.setStatusDate(dlFileVersion.getStatusDate());
5080    
5081                    return dlFileVersionImpl;
5082            }
5083    
5084            /**
5085             * Returns the document library file version with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
5086             *
5087             * @param primaryKey the primary key of the document library file version
5088             * @return the document library file version
5089             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a document library file version with the primary key could not be found
5090             * @throws SystemException if a system exception occurred
5091             */
5092            @Override
5093            public DLFileVersion findByPrimaryKey(Serializable primaryKey)
5094                    throws NoSuchFileVersionException, SystemException {
5095                    DLFileVersion dlFileVersion = fetchByPrimaryKey(primaryKey);
5096    
5097                    if (dlFileVersion == null) {
5098                            if (_log.isWarnEnabled()) {
5099                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5100                            }
5101    
5102                            throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5103                                    primaryKey);
5104                    }
5105    
5106                    return dlFileVersion;
5107            }
5108    
5109            /**
5110             * 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.
5111             *
5112             * @param fileVersionId the primary key of the document library file version
5113             * @return the document library file version
5114             * @throws com.liferay.portlet.documentlibrary.NoSuchFileVersionException if a document library file version with the primary key could not be found
5115             * @throws SystemException if a system exception occurred
5116             */
5117            @Override
5118            public DLFileVersion findByPrimaryKey(long fileVersionId)
5119                    throws NoSuchFileVersionException, SystemException {
5120                    return findByPrimaryKey((Serializable)fileVersionId);
5121            }
5122    
5123            /**
5124             * Returns the document library file version with the primary key or returns <code>null</code> if it could not be found.
5125             *
5126             * @param primaryKey the primary key of the document library file version
5127             * @return the document library file version, or <code>null</code> if a document library file version with the primary key could not be found
5128             * @throws SystemException if a system exception occurred
5129             */
5130            @Override
5131            public DLFileVersion fetchByPrimaryKey(Serializable primaryKey)
5132                    throws SystemException {
5133                    DLFileVersion dlFileVersion = (DLFileVersion)EntityCacheUtil.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5134                                    DLFileVersionImpl.class, primaryKey);
5135    
5136                    if (dlFileVersion == _nullDLFileVersion) {
5137                            return null;
5138                    }
5139    
5140                    if (dlFileVersion == null) {
5141                            Session session = null;
5142    
5143                            try {
5144                                    session = openSession();
5145    
5146                                    dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
5147                                                    primaryKey);
5148    
5149                                    if (dlFileVersion != null) {
5150                                            cacheResult(dlFileVersion);
5151                                    }
5152                                    else {
5153                                            EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5154                                                    DLFileVersionImpl.class, primaryKey, _nullDLFileVersion);
5155                                    }
5156                            }
5157                            catch (Exception e) {
5158                                    EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
5159                                            DLFileVersionImpl.class, primaryKey);
5160    
5161                                    throw processException(e);
5162                            }
5163                            finally {
5164                                    closeSession(session);
5165                            }
5166                    }
5167    
5168                    return dlFileVersion;
5169            }
5170    
5171            /**
5172             * Returns the document library file version with the primary key or returns <code>null</code> if it could not be found.
5173             *
5174             * @param fileVersionId the primary key of the document library file version
5175             * @return the document library file version, or <code>null</code> if a document library file version with the primary key could not be found
5176             * @throws SystemException if a system exception occurred
5177             */
5178            @Override
5179            public DLFileVersion fetchByPrimaryKey(long fileVersionId)
5180                    throws SystemException {
5181                    return fetchByPrimaryKey((Serializable)fileVersionId);
5182            }
5183    
5184            /**
5185             * Returns all the document library file versions.
5186             *
5187             * @return the document library file versions
5188             * @throws SystemException if a system exception occurred
5189             */
5190            @Override
5191            public List<DLFileVersion> findAll() throws SystemException {
5192                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5193            }
5194    
5195            /**
5196             * Returns a range of all the document library file versions.
5197             *
5198             * <p>
5199             * 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.
5200             * </p>
5201             *
5202             * @param start the lower bound of the range of document library file versions
5203             * @param end the upper bound of the range of document library file versions (not inclusive)
5204             * @return the range of document library file versions
5205             * @throws SystemException if a system exception occurred
5206             */
5207            @Override
5208            public List<DLFileVersion> findAll(int start, int end)
5209                    throws SystemException {
5210                    return findAll(start, end, null);
5211            }
5212    
5213            /**
5214             * Returns an ordered range of all the document library file versions.
5215             *
5216             * <p>
5217             * 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.
5218             * </p>
5219             *
5220             * @param start the lower bound of the range of document library file versions
5221             * @param end the upper bound of the range of document library file versions (not inclusive)
5222             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5223             * @return the ordered range of document library file versions
5224             * @throws SystemException if a system exception occurred
5225             */
5226            @Override
5227            public List<DLFileVersion> findAll(int start, int end,
5228                    OrderByComparator orderByComparator) throws SystemException {
5229                    boolean pagination = true;
5230                    FinderPath finderPath = null;
5231                    Object[] finderArgs = null;
5232    
5233                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5234                                    (orderByComparator == null)) {
5235                            pagination = false;
5236                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5237                            finderArgs = FINDER_ARGS_EMPTY;
5238                    }
5239                    else {
5240                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5241                            finderArgs = new Object[] { start, end, orderByComparator };
5242                    }
5243    
5244                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(finderPath,
5245                                    finderArgs, this);
5246    
5247                    if (list == null) {
5248                            StringBundler query = null;
5249                            String sql = null;
5250    
5251                            if (orderByComparator != null) {
5252                                    query = new StringBundler(2 +
5253                                                    (orderByComparator.getOrderByFields().length * 3));
5254    
5255                                    query.append(_SQL_SELECT_DLFILEVERSION);
5256    
5257                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5258                                            orderByComparator);
5259    
5260                                    sql = query.toString();
5261                            }
5262                            else {
5263                                    sql = _SQL_SELECT_DLFILEVERSION;
5264    
5265                                    if (pagination) {
5266                                            sql = sql.concat(DLFileVersionModelImpl.ORDER_BY_JPQL);
5267                                    }
5268                            }
5269    
5270                            Session session = null;
5271    
5272                            try {
5273                                    session = openSession();
5274    
5275                                    Query q = session.createQuery(sql);
5276    
5277                                    if (!pagination) {
5278                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
5279                                                            start, end, false);
5280    
5281                                            Collections.sort(list);
5282    
5283                                            list = new UnmodifiableList<DLFileVersion>(list);
5284                                    }
5285                                    else {
5286                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
5287                                                            start, end);
5288                                    }
5289    
5290                                    cacheResult(list);
5291    
5292                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5293                            }
5294                            catch (Exception e) {
5295                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5296    
5297                                    throw processException(e);
5298                            }
5299                            finally {
5300                                    closeSession(session);
5301                            }
5302                    }
5303    
5304                    return list;
5305            }
5306    
5307            /**
5308             * Removes all the document library file versions from the database.
5309             *
5310             * @throws SystemException if a system exception occurred
5311             */
5312            @Override
5313            public void removeAll() throws SystemException {
5314                    for (DLFileVersion dlFileVersion : findAll()) {
5315                            remove(dlFileVersion);
5316                    }
5317            }
5318    
5319            /**
5320             * Returns the number of document library file versions.
5321             *
5322             * @return the number of document library file versions
5323             * @throws SystemException if a system exception occurred
5324             */
5325            @Override
5326            public int countAll() throws SystemException {
5327                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5328                                    FINDER_ARGS_EMPTY, this);
5329    
5330                    if (count == null) {
5331                            Session session = null;
5332    
5333                            try {
5334                                    session = openSession();
5335    
5336                                    Query q = session.createQuery(_SQL_COUNT_DLFILEVERSION);
5337    
5338                                    count = (Long)q.uniqueResult();
5339    
5340                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5341                                            FINDER_ARGS_EMPTY, count);
5342                            }
5343                            catch (Exception e) {
5344                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5345                                            FINDER_ARGS_EMPTY);
5346    
5347                                    throw processException(e);
5348                            }
5349                            finally {
5350                                    closeSession(session);
5351                            }
5352                    }
5353    
5354                    return count.intValue();
5355            }
5356    
5357            @Override
5358            protected Set<String> getBadColumnNames() {
5359                    return _badColumnNames;
5360            }
5361    
5362            /**
5363             * Initializes the document library file version persistence.
5364             */
5365            public void afterPropertiesSet() {
5366                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5367                                            com.liferay.portal.util.PropsUtil.get(
5368                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileVersion")));
5369    
5370                    if (listenerClassNames.length > 0) {
5371                            try {
5372                                    List<ModelListener<DLFileVersion>> listenersList = new ArrayList<ModelListener<DLFileVersion>>();
5373    
5374                                    for (String listenerClassName : listenerClassNames) {
5375                                            listenersList.add((ModelListener<DLFileVersion>)InstanceFactory.newInstance(
5376                                                            getClassLoader(), listenerClassName));
5377                                    }
5378    
5379                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5380                            }
5381                            catch (Exception e) {
5382                                    _log.error(e);
5383                            }
5384                    }
5385            }
5386    
5387            public void destroy() {
5388                    EntityCacheUtil.removeCache(DLFileVersionImpl.class.getName());
5389                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5390                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5391                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5392            }
5393    
5394            private static final String _SQL_SELECT_DLFILEVERSION = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion";
5395            private static final String _SQL_SELECT_DLFILEVERSION_WHERE = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ";
5396            private static final String _SQL_COUNT_DLFILEVERSION = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion";
5397            private static final String _SQL_COUNT_DLFILEVERSION_WHERE = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion WHERE ";
5398            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileVersion.";
5399            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileVersion exists with the primary key ";
5400            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileVersion exists with the key {";
5401            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5402            private static Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
5403            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
5404                                    "uuid", "size"
5405                            });
5406            private static DLFileVersion _nullDLFileVersion = new DLFileVersionImpl() {
5407                            @Override
5408                            public Object clone() {
5409                                    return this;
5410                            }
5411    
5412                            @Override
5413                            public CacheModel<DLFileVersion> toCacheModel() {
5414                                    return _nullDLFileVersionCacheModel;
5415                            }
5416                    };
5417    
5418            private static CacheModel<DLFileVersion> _nullDLFileVersionCacheModel = new CacheModel<DLFileVersion>() {
5419                            @Override
5420                            public DLFileVersion toEntityModel() {
5421                                    return _nullDLFileVersion;
5422                            }
5423                    };
5424    }