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