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