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