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