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