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