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