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.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.SetUtil;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.Validator;
034    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
035    import com.liferay.portal.model.CacheModel;
036    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
037    
038    import com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException;
039    import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata;
040    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataImpl;
041    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl;
042    import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryMetadataPersistence;
043    
044    import java.io.Serializable;
045    
046    import java.util.Collections;
047    import java.util.HashMap;
048    import java.util.HashSet;
049    import java.util.Iterator;
050    import java.util.List;
051    import java.util.Map;
052    import java.util.Set;
053    
054    /**
055     * The persistence implementation for the document library file entry metadata service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see DLFileEntryMetadataPersistence
063     * @see DLFileEntryMetadataUtil
064     * @generated
065     */
066    @ProviderType
067    public class DLFileEntryMetadataPersistenceImpl extends BasePersistenceImpl<DLFileEntryMetadata>
068            implements DLFileEntryMetadataPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * Never modify or reference this class directly. Always use {@link DLFileEntryMetadataUtil} to access the document library file entry metadata persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = DLFileEntryMetadataImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
080                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
081                            DLFileEntryMetadataImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
084                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
085                            DLFileEntryMetadataImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
088                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
091                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
092                            DLFileEntryMetadataImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
094                            new String[] {
095                                    String.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
101                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
102                            DLFileEntryMetadataImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
104                            new String[] { String.class.getName() },
105                            DLFileEntryMetadataModelImpl.UUID_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
107                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
109                            new String[] { String.class.getName() });
110    
111            /**
112             * Returns all the document library file entry metadatas where uuid = &#63;.
113             *
114             * @param uuid the uuid
115             * @return the matching document library file entry metadatas
116             */
117            @Override
118            public List<DLFileEntryMetadata> findByUuid(String uuid) {
119                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
120            }
121    
122            /**
123             * Returns a range of all the document library file entry metadatas where uuid = &#63;.
124             *
125             * <p>
126             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
127             * </p>
128             *
129             * @param uuid the uuid
130             * @param start the lower bound of the range of document library file entry metadatas
131             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
132             * @return the range of matching document library file entry metadatas
133             */
134            @Override
135            public List<DLFileEntryMetadata> findByUuid(String uuid, int start, int end) {
136                    return findByUuid(uuid, start, end, null);
137            }
138    
139            /**
140             * Returns an ordered range of all the document library file entry metadatas where uuid = &#63;.
141             *
142             * <p>
143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
144             * </p>
145             *
146             * @param uuid the uuid
147             * @param start the lower bound of the range of document library file entry metadatas
148             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
150             * @return the ordered range of matching document library file entry metadatas
151             */
152            @Override
153            public List<DLFileEntryMetadata> findByUuid(String uuid, int start,
154                    int end, OrderByComparator<DLFileEntryMetadata> orderByComparator) {
155                    boolean pagination = true;
156                    FinderPath finderPath = null;
157                    Object[] finderArgs = null;
158    
159                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160                                    (orderByComparator == null)) {
161                            pagination = false;
162                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
163                            finderArgs = new Object[] { uuid };
164                    }
165                    else {
166                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
167                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
168                    }
169    
170                    List<DLFileEntryMetadata> list = (List<DLFileEntryMetadata>)FinderCacheUtil.getResult(finderPath,
171                                    finderArgs, this);
172    
173                    if ((list != null) && !list.isEmpty()) {
174                            for (DLFileEntryMetadata dlFileEntryMetadata : list) {
175                                    if (!Validator.equals(uuid, dlFileEntryMetadata.getUuid())) {
176                                            list = null;
177    
178                                            break;
179                                    }
180                            }
181                    }
182    
183                    if (list == null) {
184                            StringBundler query = null;
185    
186                            if (orderByComparator != null) {
187                                    query = new StringBundler(3 +
188                                                    (orderByComparator.getOrderByFields().length * 3));
189                            }
190                            else {
191                                    query = new StringBundler(3);
192                            }
193    
194                            query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
195    
196                            boolean bindUuid = false;
197    
198                            if (uuid == null) {
199                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
200                            }
201                            else if (uuid.equals(StringPool.BLANK)) {
202                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
203                            }
204                            else {
205                                    bindUuid = true;
206    
207                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
208                            }
209    
210                            if (orderByComparator != null) {
211                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
212                                            orderByComparator);
213                            }
214                            else
215                             if (pagination) {
216                                    query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
217                            }
218    
219                            String sql = query.toString();
220    
221                            Session session = null;
222    
223                            try {
224                                    session = openSession();
225    
226                                    Query q = session.createQuery(sql);
227    
228                                    QueryPos qPos = QueryPos.getInstance(q);
229    
230                                    if (bindUuid) {
231                                            qPos.add(uuid);
232                                    }
233    
234                                    if (!pagination) {
235                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
236                                                            getDialect(), start, end, false);
237    
238                                            Collections.sort(list);
239    
240                                            list = Collections.unmodifiableList(list);
241                                    }
242                                    else {
243                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
244                                                            getDialect(), start, end);
245                                    }
246    
247                                    cacheResult(list);
248    
249                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
250                            }
251                            catch (Exception e) {
252                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
253    
254                                    throw processException(e);
255                            }
256                            finally {
257                                    closeSession(session);
258                            }
259                    }
260    
261                    return list;
262            }
263    
264            /**
265             * Returns the first document library file entry metadata in the ordered set where uuid = &#63;.
266             *
267             * @param uuid the uuid
268             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
269             * @return the first matching document library file entry metadata
270             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
271             */
272            @Override
273            public DLFileEntryMetadata findByUuid_First(String uuid,
274                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
275                    throws NoSuchFileEntryMetadataException {
276                    DLFileEntryMetadata dlFileEntryMetadata = fetchByUuid_First(uuid,
277                                    orderByComparator);
278    
279                    if (dlFileEntryMetadata != null) {
280                            return dlFileEntryMetadata;
281                    }
282    
283                    StringBundler msg = new StringBundler(4);
284    
285                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
286    
287                    msg.append("uuid=");
288                    msg.append(uuid);
289    
290                    msg.append(StringPool.CLOSE_CURLY_BRACE);
291    
292                    throw new NoSuchFileEntryMetadataException(msg.toString());
293            }
294    
295            /**
296             * Returns the first document library file entry metadata in the ordered set where uuid = &#63;.
297             *
298             * @param uuid the uuid
299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
300             * @return the first matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
301             */
302            @Override
303            public DLFileEntryMetadata fetchByUuid_First(String uuid,
304                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
305                    List<DLFileEntryMetadata> list = findByUuid(uuid, 0, 1,
306                                    orderByComparator);
307    
308                    if (!list.isEmpty()) {
309                            return list.get(0);
310                    }
311    
312                    return null;
313            }
314    
315            /**
316             * Returns the last document library file entry metadata in the ordered set where uuid = &#63;.
317             *
318             * @param uuid the uuid
319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
320             * @return the last matching document library file entry metadata
321             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
322             */
323            @Override
324            public DLFileEntryMetadata findByUuid_Last(String uuid,
325                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
326                    throws NoSuchFileEntryMetadataException {
327                    DLFileEntryMetadata dlFileEntryMetadata = fetchByUuid_Last(uuid,
328                                    orderByComparator);
329    
330                    if (dlFileEntryMetadata != null) {
331                            return dlFileEntryMetadata;
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 NoSuchFileEntryMetadataException(msg.toString());
344            }
345    
346            /**
347             * Returns the last document library file entry metadata 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 entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
352             */
353            @Override
354            public DLFileEntryMetadata fetchByUuid_Last(String uuid,
355                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
356                    int count = countByUuid(uuid);
357    
358                    if (count == 0) {
359                            return null;
360                    }
361    
362                    List<DLFileEntryMetadata> 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 entry metadatas before and after the current document library file entry metadata in the ordered set where uuid = &#63;.
374             *
375             * @param fileEntryMetadataId the primary key of the current document library file entry metadata
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 entry metadata
379             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
380             */
381            @Override
382            public DLFileEntryMetadata[] findByUuid_PrevAndNext(
383                    long fileEntryMetadataId, String uuid,
384                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
385                    throws NoSuchFileEntryMetadataException {
386                    DLFileEntryMetadata dlFileEntryMetadata = findByPrimaryKey(fileEntryMetadataId);
387    
388                    Session session = null;
389    
390                    try {
391                            session = openSession();
392    
393                            DLFileEntryMetadata[] array = new DLFileEntryMetadataImpl[3];
394    
395                            array[0] = getByUuid_PrevAndNext(session, dlFileEntryMetadata,
396                                            uuid, orderByComparator, true);
397    
398                            array[1] = dlFileEntryMetadata;
399    
400                            array[2] = getByUuid_PrevAndNext(session, dlFileEntryMetadata,
401                                            uuid, orderByComparator, false);
402    
403                            return array;
404                    }
405                    catch (Exception e) {
406                            throw processException(e);
407                    }
408                    finally {
409                            closeSession(session);
410                    }
411            }
412    
413            protected DLFileEntryMetadata getByUuid_PrevAndNext(Session session,
414                    DLFileEntryMetadata dlFileEntryMetadata, String uuid,
415                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
416                    boolean previous) {
417                    StringBundler query = null;
418    
419                    if (orderByComparator != null) {
420                            query = new StringBundler(6 +
421                                            (orderByComparator.getOrderByFields().length * 6));
422                    }
423                    else {
424                            query = new StringBundler(3);
425                    }
426    
427                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
428    
429                    boolean bindUuid = false;
430    
431                    if (uuid == null) {
432                            query.append(_FINDER_COLUMN_UUID_UUID_1);
433                    }
434                    else if (uuid.equals(StringPool.BLANK)) {
435                            query.append(_FINDER_COLUMN_UUID_UUID_3);
436                    }
437                    else {
438                            bindUuid = true;
439    
440                            query.append(_FINDER_COLUMN_UUID_UUID_2);
441                    }
442    
443                    if (orderByComparator != null) {
444                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
445    
446                            if (orderByConditionFields.length > 0) {
447                                    query.append(WHERE_AND);
448                            }
449    
450                            for (int i = 0; i < orderByConditionFields.length; i++) {
451                                    query.append(_ORDER_BY_ENTITY_ALIAS);
452                                    query.append(orderByConditionFields[i]);
453    
454                                    if ((i + 1) < orderByConditionFields.length) {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
457                                            }
458                                            else {
459                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
460                                            }
461                                    }
462                                    else {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(WHERE_GREATER_THAN);
465                                            }
466                                            else {
467                                                    query.append(WHERE_LESSER_THAN);
468                                            }
469                                    }
470                            }
471    
472                            query.append(ORDER_BY_CLAUSE);
473    
474                            String[] orderByFields = orderByComparator.getOrderByFields();
475    
476                            for (int i = 0; i < orderByFields.length; i++) {
477                                    query.append(_ORDER_BY_ENTITY_ALIAS);
478                                    query.append(orderByFields[i]);
479    
480                                    if ((i + 1) < orderByFields.length) {
481                                            if (orderByComparator.isAscending() ^ previous) {
482                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
483                                            }
484                                            else {
485                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
486                                            }
487                                    }
488                                    else {
489                                            if (orderByComparator.isAscending() ^ previous) {
490                                                    query.append(ORDER_BY_ASC);
491                                            }
492                                            else {
493                                                    query.append(ORDER_BY_DESC);
494                                            }
495                                    }
496                            }
497                    }
498                    else {
499                            query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
500                    }
501    
502                    String sql = query.toString();
503    
504                    Query q = session.createQuery(sql);
505    
506                    q.setFirstResult(0);
507                    q.setMaxResults(2);
508    
509                    QueryPos qPos = QueryPos.getInstance(q);
510    
511                    if (bindUuid) {
512                            qPos.add(uuid);
513                    }
514    
515                    if (orderByComparator != null) {
516                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileEntryMetadata);
517    
518                            for (Object value : values) {
519                                    qPos.add(value);
520                            }
521                    }
522    
523                    List<DLFileEntryMetadata> list = q.list();
524    
525                    if (list.size() == 2) {
526                            return list.get(1);
527                    }
528                    else {
529                            return null;
530                    }
531            }
532    
533            /**
534             * Removes all the document library file entry metadatas where uuid = &#63; from the database.
535             *
536             * @param uuid the uuid
537             */
538            @Override
539            public void removeByUuid(String uuid) {
540                    for (DLFileEntryMetadata dlFileEntryMetadata : findByUuid(uuid,
541                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
542                            remove(dlFileEntryMetadata);
543                    }
544            }
545    
546            /**
547             * Returns the number of document library file entry metadatas where uuid = &#63;.
548             *
549             * @param uuid the uuid
550             * @return the number of matching document library file entry metadatas
551             */
552            @Override
553            public int countByUuid(String uuid) {
554                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
555    
556                    Object[] finderArgs = new Object[] { uuid };
557    
558                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
559                                    this);
560    
561                    if (count == null) {
562                            StringBundler query = new StringBundler(2);
563    
564                            query.append(_SQL_COUNT_DLFILEENTRYMETADATA_WHERE);
565    
566                            boolean bindUuid = false;
567    
568                            if (uuid == null) {
569                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
570                            }
571                            else if (uuid.equals(StringPool.BLANK)) {
572                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
573                            }
574                            else {
575                                    bindUuid = true;
576    
577                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
578                            }
579    
580                            String sql = query.toString();
581    
582                            Session session = null;
583    
584                            try {
585                                    session = openSession();
586    
587                                    Query q = session.createQuery(sql);
588    
589                                    QueryPos qPos = QueryPos.getInstance(q);
590    
591                                    if (bindUuid) {
592                                            qPos.add(uuid);
593                                    }
594    
595                                    count = (Long)q.uniqueResult();
596    
597                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
598                            }
599                            catch (Exception e) {
600                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
601    
602                                    throw processException(e);
603                            }
604                            finally {
605                                    closeSession(session);
606                            }
607                    }
608    
609                    return count.intValue();
610            }
611    
612            private static final String _FINDER_COLUMN_UUID_UUID_1 = "dlFileEntryMetadata.uuid IS NULL";
613            private static final String _FINDER_COLUMN_UUID_UUID_2 = "dlFileEntryMetadata.uuid = ?";
614            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(dlFileEntryMetadata.uuid IS NULL OR dlFileEntryMetadata.uuid = '')";
615            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYTYPEID =
616                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
617                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
618                            DLFileEntryMetadataImpl.class,
619                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFileEntryTypeId",
620                            new String[] {
621                                    Long.class.getName(),
622                                    
623                            Integer.class.getName(), Integer.class.getName(),
624                                    OrderByComparator.class.getName()
625                            });
626            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYTYPEID =
627                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
628                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
629                            DLFileEntryMetadataImpl.class,
630                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFileEntryTypeId",
631                            new String[] { Long.class.getName() },
632                            DLFileEntryMetadataModelImpl.FILEENTRYTYPEID_COLUMN_BITMASK);
633            public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYTYPEID = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
634                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
635                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
636                            "countByFileEntryTypeId", new String[] { Long.class.getName() });
637    
638            /**
639             * Returns all the document library file entry metadatas where fileEntryTypeId = &#63;.
640             *
641             * @param fileEntryTypeId the file entry type ID
642             * @return the matching document library file entry metadatas
643             */
644            @Override
645            public List<DLFileEntryMetadata> findByFileEntryTypeId(long fileEntryTypeId) {
646                    return findByFileEntryTypeId(fileEntryTypeId, QueryUtil.ALL_POS,
647                            QueryUtil.ALL_POS, null);
648            }
649    
650            /**
651             * Returns a range of all the document library file entry metadatas where fileEntryTypeId = &#63;.
652             *
653             * <p>
654             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
655             * </p>
656             *
657             * @param fileEntryTypeId the file entry type ID
658             * @param start the lower bound of the range of document library file entry metadatas
659             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
660             * @return the range of matching document library file entry metadatas
661             */
662            @Override
663            public List<DLFileEntryMetadata> findByFileEntryTypeId(
664                    long fileEntryTypeId, int start, int end) {
665                    return findByFileEntryTypeId(fileEntryTypeId, start, end, null);
666            }
667    
668            /**
669             * Returns an ordered range of all the document library file entry metadatas where fileEntryTypeId = &#63;.
670             *
671             * <p>
672             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
673             * </p>
674             *
675             * @param fileEntryTypeId the file entry type ID
676             * @param start the lower bound of the range of document library file entry metadatas
677             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
678             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
679             * @return the ordered range of matching document library file entry metadatas
680             */
681            @Override
682            public List<DLFileEntryMetadata> findByFileEntryTypeId(
683                    long fileEntryTypeId, int start, int end,
684                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
685                    boolean pagination = true;
686                    FinderPath finderPath = null;
687                    Object[] finderArgs = null;
688    
689                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
690                                    (orderByComparator == null)) {
691                            pagination = false;
692                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYTYPEID;
693                            finderArgs = new Object[] { fileEntryTypeId };
694                    }
695                    else {
696                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYTYPEID;
697                            finderArgs = new Object[] {
698                                            fileEntryTypeId,
699                                            
700                                            start, end, orderByComparator
701                                    };
702                    }
703    
704                    List<DLFileEntryMetadata> list = (List<DLFileEntryMetadata>)FinderCacheUtil.getResult(finderPath,
705                                    finderArgs, this);
706    
707                    if ((list != null) && !list.isEmpty()) {
708                            for (DLFileEntryMetadata dlFileEntryMetadata : list) {
709                                    if ((fileEntryTypeId != dlFileEntryMetadata.getFileEntryTypeId())) {
710                                            list = null;
711    
712                                            break;
713                                    }
714                            }
715                    }
716    
717                    if (list == null) {
718                            StringBundler query = null;
719    
720                            if (orderByComparator != null) {
721                                    query = new StringBundler(3 +
722                                                    (orderByComparator.getOrderByFields().length * 3));
723                            }
724                            else {
725                                    query = new StringBundler(3);
726                            }
727    
728                            query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
729    
730                            query.append(_FINDER_COLUMN_FILEENTRYTYPEID_FILEENTRYTYPEID_2);
731    
732                            if (orderByComparator != null) {
733                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
734                                            orderByComparator);
735                            }
736                            else
737                             if (pagination) {
738                                    query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
739                            }
740    
741                            String sql = query.toString();
742    
743                            Session session = null;
744    
745                            try {
746                                    session = openSession();
747    
748                                    Query q = session.createQuery(sql);
749    
750                                    QueryPos qPos = QueryPos.getInstance(q);
751    
752                                    qPos.add(fileEntryTypeId);
753    
754                                    if (!pagination) {
755                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
756                                                            getDialect(), start, end, false);
757    
758                                            Collections.sort(list);
759    
760                                            list = Collections.unmodifiableList(list);
761                                    }
762                                    else {
763                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
764                                                            getDialect(), start, end);
765                                    }
766    
767                                    cacheResult(list);
768    
769                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
770                            }
771                            catch (Exception e) {
772                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
773    
774                                    throw processException(e);
775                            }
776                            finally {
777                                    closeSession(session);
778                            }
779                    }
780    
781                    return list;
782            }
783    
784            /**
785             * Returns the first document library file entry metadata in the ordered set where fileEntryTypeId = &#63;.
786             *
787             * @param fileEntryTypeId the file entry type ID
788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
789             * @return the first matching document library file entry metadata
790             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
791             */
792            @Override
793            public DLFileEntryMetadata findByFileEntryTypeId_First(
794                    long fileEntryTypeId,
795                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
796                    throws NoSuchFileEntryMetadataException {
797                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileEntryTypeId_First(fileEntryTypeId,
798                                    orderByComparator);
799    
800                    if (dlFileEntryMetadata != null) {
801                            return dlFileEntryMetadata;
802                    }
803    
804                    StringBundler msg = new StringBundler(4);
805    
806                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
807    
808                    msg.append("fileEntryTypeId=");
809                    msg.append(fileEntryTypeId);
810    
811                    msg.append(StringPool.CLOSE_CURLY_BRACE);
812    
813                    throw new NoSuchFileEntryMetadataException(msg.toString());
814            }
815    
816            /**
817             * Returns the first document library file entry metadata in the ordered set where fileEntryTypeId = &#63;.
818             *
819             * @param fileEntryTypeId the file entry type ID
820             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
821             * @return the first matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
822             */
823            @Override
824            public DLFileEntryMetadata fetchByFileEntryTypeId_First(
825                    long fileEntryTypeId,
826                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
827                    List<DLFileEntryMetadata> list = findByFileEntryTypeId(fileEntryTypeId,
828                                    0, 1, orderByComparator);
829    
830                    if (!list.isEmpty()) {
831                            return list.get(0);
832                    }
833    
834                    return null;
835            }
836    
837            /**
838             * Returns the last document library file entry metadata in the ordered set where fileEntryTypeId = &#63;.
839             *
840             * @param fileEntryTypeId the file entry type ID
841             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
842             * @return the last matching document library file entry metadata
843             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
844             */
845            @Override
846            public DLFileEntryMetadata findByFileEntryTypeId_Last(
847                    long fileEntryTypeId,
848                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
849                    throws NoSuchFileEntryMetadataException {
850                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileEntryTypeId_Last(fileEntryTypeId,
851                                    orderByComparator);
852    
853                    if (dlFileEntryMetadata != null) {
854                            return dlFileEntryMetadata;
855                    }
856    
857                    StringBundler msg = new StringBundler(4);
858    
859                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
860    
861                    msg.append("fileEntryTypeId=");
862                    msg.append(fileEntryTypeId);
863    
864                    msg.append(StringPool.CLOSE_CURLY_BRACE);
865    
866                    throw new NoSuchFileEntryMetadataException(msg.toString());
867            }
868    
869            /**
870             * Returns the last document library file entry metadata in the ordered set where fileEntryTypeId = &#63;.
871             *
872             * @param fileEntryTypeId the file entry type ID
873             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
874             * @return the last matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
875             */
876            @Override
877            public DLFileEntryMetadata fetchByFileEntryTypeId_Last(
878                    long fileEntryTypeId,
879                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
880                    int count = countByFileEntryTypeId(fileEntryTypeId);
881    
882                    if (count == 0) {
883                            return null;
884                    }
885    
886                    List<DLFileEntryMetadata> list = findByFileEntryTypeId(fileEntryTypeId,
887                                    count - 1, count, orderByComparator);
888    
889                    if (!list.isEmpty()) {
890                            return list.get(0);
891                    }
892    
893                    return null;
894            }
895    
896            /**
897             * Returns the document library file entry metadatas before and after the current document library file entry metadata in the ordered set where fileEntryTypeId = &#63;.
898             *
899             * @param fileEntryMetadataId the primary key of the current document library file entry metadata
900             * @param fileEntryTypeId the file entry type ID
901             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
902             * @return the previous, current, and next document library file entry metadata
903             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
904             */
905            @Override
906            public DLFileEntryMetadata[] findByFileEntryTypeId_PrevAndNext(
907                    long fileEntryMetadataId, long fileEntryTypeId,
908                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
909                    throws NoSuchFileEntryMetadataException {
910                    DLFileEntryMetadata dlFileEntryMetadata = findByPrimaryKey(fileEntryMetadataId);
911    
912                    Session session = null;
913    
914                    try {
915                            session = openSession();
916    
917                            DLFileEntryMetadata[] array = new DLFileEntryMetadataImpl[3];
918    
919                            array[0] = getByFileEntryTypeId_PrevAndNext(session,
920                                            dlFileEntryMetadata, fileEntryTypeId, orderByComparator,
921                                            true);
922    
923                            array[1] = dlFileEntryMetadata;
924    
925                            array[2] = getByFileEntryTypeId_PrevAndNext(session,
926                                            dlFileEntryMetadata, fileEntryTypeId, orderByComparator,
927                                            false);
928    
929                            return array;
930                    }
931                    catch (Exception e) {
932                            throw processException(e);
933                    }
934                    finally {
935                            closeSession(session);
936                    }
937            }
938    
939            protected DLFileEntryMetadata getByFileEntryTypeId_PrevAndNext(
940                    Session session, DLFileEntryMetadata dlFileEntryMetadata,
941                    long fileEntryTypeId,
942                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
943                    boolean previous) {
944                    StringBundler query = null;
945    
946                    if (orderByComparator != null) {
947                            query = new StringBundler(6 +
948                                            (orderByComparator.getOrderByFields().length * 6));
949                    }
950                    else {
951                            query = new StringBundler(3);
952                    }
953    
954                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
955    
956                    query.append(_FINDER_COLUMN_FILEENTRYTYPEID_FILEENTRYTYPEID_2);
957    
958                    if (orderByComparator != null) {
959                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
960    
961                            if (orderByConditionFields.length > 0) {
962                                    query.append(WHERE_AND);
963                            }
964    
965                            for (int i = 0; i < orderByConditionFields.length; i++) {
966                                    query.append(_ORDER_BY_ENTITY_ALIAS);
967                                    query.append(orderByConditionFields[i]);
968    
969                                    if ((i + 1) < orderByConditionFields.length) {
970                                            if (orderByComparator.isAscending() ^ previous) {
971                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
972                                            }
973                                            else {
974                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
975                                            }
976                                    }
977                                    else {
978                                            if (orderByComparator.isAscending() ^ previous) {
979                                                    query.append(WHERE_GREATER_THAN);
980                                            }
981                                            else {
982                                                    query.append(WHERE_LESSER_THAN);
983                                            }
984                                    }
985                            }
986    
987                            query.append(ORDER_BY_CLAUSE);
988    
989                            String[] orderByFields = orderByComparator.getOrderByFields();
990    
991                            for (int i = 0; i < orderByFields.length; i++) {
992                                    query.append(_ORDER_BY_ENTITY_ALIAS);
993                                    query.append(orderByFields[i]);
994    
995                                    if ((i + 1) < orderByFields.length) {
996                                            if (orderByComparator.isAscending() ^ previous) {
997                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
998                                            }
999                                            else {
1000                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1001                                            }
1002                                    }
1003                                    else {
1004                                            if (orderByComparator.isAscending() ^ previous) {
1005                                                    query.append(ORDER_BY_ASC);
1006                                            }
1007                                            else {
1008                                                    query.append(ORDER_BY_DESC);
1009                                            }
1010                                    }
1011                            }
1012                    }
1013                    else {
1014                            query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
1015                    }
1016    
1017                    String sql = query.toString();
1018    
1019                    Query q = session.createQuery(sql);
1020    
1021                    q.setFirstResult(0);
1022                    q.setMaxResults(2);
1023    
1024                    QueryPos qPos = QueryPos.getInstance(q);
1025    
1026                    qPos.add(fileEntryTypeId);
1027    
1028                    if (orderByComparator != null) {
1029                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileEntryMetadata);
1030    
1031                            for (Object value : values) {
1032                                    qPos.add(value);
1033                            }
1034                    }
1035    
1036                    List<DLFileEntryMetadata> list = q.list();
1037    
1038                    if (list.size() == 2) {
1039                            return list.get(1);
1040                    }
1041                    else {
1042                            return null;
1043                    }
1044            }
1045    
1046            /**
1047             * Removes all the document library file entry metadatas where fileEntryTypeId = &#63; from the database.
1048             *
1049             * @param fileEntryTypeId the file entry type ID
1050             */
1051            @Override
1052            public void removeByFileEntryTypeId(long fileEntryTypeId) {
1053                    for (DLFileEntryMetadata dlFileEntryMetadata : findByFileEntryTypeId(
1054                                    fileEntryTypeId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1055                            remove(dlFileEntryMetadata);
1056                    }
1057            }
1058    
1059            /**
1060             * Returns the number of document library file entry metadatas where fileEntryTypeId = &#63;.
1061             *
1062             * @param fileEntryTypeId the file entry type ID
1063             * @return the number of matching document library file entry metadatas
1064             */
1065            @Override
1066            public int countByFileEntryTypeId(long fileEntryTypeId) {
1067                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEENTRYTYPEID;
1068    
1069                    Object[] finderArgs = new Object[] { fileEntryTypeId };
1070    
1071                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1072                                    this);
1073    
1074                    if (count == null) {
1075                            StringBundler query = new StringBundler(2);
1076    
1077                            query.append(_SQL_COUNT_DLFILEENTRYMETADATA_WHERE);
1078    
1079                            query.append(_FINDER_COLUMN_FILEENTRYTYPEID_FILEENTRYTYPEID_2);
1080    
1081                            String sql = query.toString();
1082    
1083                            Session session = null;
1084    
1085                            try {
1086                                    session = openSession();
1087    
1088                                    Query q = session.createQuery(sql);
1089    
1090                                    QueryPos qPos = QueryPos.getInstance(q);
1091    
1092                                    qPos.add(fileEntryTypeId);
1093    
1094                                    count = (Long)q.uniqueResult();
1095    
1096                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1097                            }
1098                            catch (Exception e) {
1099                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1100    
1101                                    throw processException(e);
1102                            }
1103                            finally {
1104                                    closeSession(session);
1105                            }
1106                    }
1107    
1108                    return count.intValue();
1109            }
1110    
1111            private static final String _FINDER_COLUMN_FILEENTRYTYPEID_FILEENTRYTYPEID_2 =
1112                    "dlFileEntryMetadata.fileEntryTypeId = ?";
1113            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID =
1114                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1115                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
1116                            DLFileEntryMetadataImpl.class,
1117                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFileEntryId",
1118                            new String[] {
1119                                    Long.class.getName(),
1120                                    
1121                            Integer.class.getName(), Integer.class.getName(),
1122                                    OrderByComparator.class.getName()
1123                            });
1124            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID =
1125                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1126                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
1127                            DLFileEntryMetadataImpl.class,
1128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFileEntryId",
1129                            new String[] { Long.class.getName() },
1130                            DLFileEntryMetadataModelImpl.FILEENTRYID_COLUMN_BITMASK);
1131            public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYID = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1132                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
1133                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileEntryId",
1134                            new String[] { Long.class.getName() });
1135    
1136            /**
1137             * Returns all the document library file entry metadatas where fileEntryId = &#63;.
1138             *
1139             * @param fileEntryId the file entry ID
1140             * @return the matching document library file entry metadatas
1141             */
1142            @Override
1143            public List<DLFileEntryMetadata> findByFileEntryId(long fileEntryId) {
1144                    return findByFileEntryId(fileEntryId, QueryUtil.ALL_POS,
1145                            QueryUtil.ALL_POS, null);
1146            }
1147    
1148            /**
1149             * Returns a range of all the document library file entry metadatas where fileEntryId = &#63;.
1150             *
1151             * <p>
1152             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
1153             * </p>
1154             *
1155             * @param fileEntryId the file entry ID
1156             * @param start the lower bound of the range of document library file entry metadatas
1157             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1158             * @return the range of matching document library file entry metadatas
1159             */
1160            @Override
1161            public List<DLFileEntryMetadata> findByFileEntryId(long fileEntryId,
1162                    int start, int end) {
1163                    return findByFileEntryId(fileEntryId, start, end, null);
1164            }
1165    
1166            /**
1167             * Returns an ordered range of all the document library file entry metadatas where fileEntryId = &#63;.
1168             *
1169             * <p>
1170             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
1171             * </p>
1172             *
1173             * @param fileEntryId the file entry ID
1174             * @param start the lower bound of the range of document library file entry metadatas
1175             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1177             * @return the ordered range of matching document library file entry metadatas
1178             */
1179            @Override
1180            public List<DLFileEntryMetadata> findByFileEntryId(long fileEntryId,
1181                    int start, int end,
1182                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1183                    boolean pagination = true;
1184                    FinderPath finderPath = null;
1185                    Object[] finderArgs = null;
1186    
1187                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1188                                    (orderByComparator == null)) {
1189                            pagination = false;
1190                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID;
1191                            finderArgs = new Object[] { fileEntryId };
1192                    }
1193                    else {
1194                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID;
1195                            finderArgs = new Object[] { fileEntryId, start, end, orderByComparator };
1196                    }
1197    
1198                    List<DLFileEntryMetadata> list = (List<DLFileEntryMetadata>)FinderCacheUtil.getResult(finderPath,
1199                                    finderArgs, this);
1200    
1201                    if ((list != null) && !list.isEmpty()) {
1202                            for (DLFileEntryMetadata dlFileEntryMetadata : list) {
1203                                    if ((fileEntryId != dlFileEntryMetadata.getFileEntryId())) {
1204                                            list = null;
1205    
1206                                            break;
1207                                    }
1208                            }
1209                    }
1210    
1211                    if (list == null) {
1212                            StringBundler query = null;
1213    
1214                            if (orderByComparator != null) {
1215                                    query = new StringBundler(3 +
1216                                                    (orderByComparator.getOrderByFields().length * 3));
1217                            }
1218                            else {
1219                                    query = new StringBundler(3);
1220                            }
1221    
1222                            query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
1223    
1224                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1225    
1226                            if (orderByComparator != null) {
1227                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1228                                            orderByComparator);
1229                            }
1230                            else
1231                             if (pagination) {
1232                                    query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
1233                            }
1234    
1235                            String sql = query.toString();
1236    
1237                            Session session = null;
1238    
1239                            try {
1240                                    session = openSession();
1241    
1242                                    Query q = session.createQuery(sql);
1243    
1244                                    QueryPos qPos = QueryPos.getInstance(q);
1245    
1246                                    qPos.add(fileEntryId);
1247    
1248                                    if (!pagination) {
1249                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
1250                                                            getDialect(), start, end, false);
1251    
1252                                            Collections.sort(list);
1253    
1254                                            list = Collections.unmodifiableList(list);
1255                                    }
1256                                    else {
1257                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
1258                                                            getDialect(), start, end);
1259                                    }
1260    
1261                                    cacheResult(list);
1262    
1263                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1264                            }
1265                            catch (Exception e) {
1266                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1267    
1268                                    throw processException(e);
1269                            }
1270                            finally {
1271                                    closeSession(session);
1272                            }
1273                    }
1274    
1275                    return list;
1276            }
1277    
1278            /**
1279             * Returns the first document library file entry metadata in the ordered set where fileEntryId = &#63;.
1280             *
1281             * @param fileEntryId the file entry ID
1282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1283             * @return the first matching document library file entry metadata
1284             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
1285             */
1286            @Override
1287            public DLFileEntryMetadata findByFileEntryId_First(long fileEntryId,
1288                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1289                    throws NoSuchFileEntryMetadataException {
1290                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileEntryId_First(fileEntryId,
1291                                    orderByComparator);
1292    
1293                    if (dlFileEntryMetadata != null) {
1294                            return dlFileEntryMetadata;
1295                    }
1296    
1297                    StringBundler msg = new StringBundler(4);
1298    
1299                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1300    
1301                    msg.append("fileEntryId=");
1302                    msg.append(fileEntryId);
1303    
1304                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1305    
1306                    throw new NoSuchFileEntryMetadataException(msg.toString());
1307            }
1308    
1309            /**
1310             * Returns the first document library file entry metadata in the ordered set where fileEntryId = &#63;.
1311             *
1312             * @param fileEntryId the file entry ID
1313             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1314             * @return the first matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
1315             */
1316            @Override
1317            public DLFileEntryMetadata fetchByFileEntryId_First(long fileEntryId,
1318                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1319                    List<DLFileEntryMetadata> list = findByFileEntryId(fileEntryId, 0, 1,
1320                                    orderByComparator);
1321    
1322                    if (!list.isEmpty()) {
1323                            return list.get(0);
1324                    }
1325    
1326                    return null;
1327            }
1328    
1329            /**
1330             * Returns the last document library file entry metadata in the ordered set where fileEntryId = &#63;.
1331             *
1332             * @param fileEntryId the file entry ID
1333             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1334             * @return the last matching document library file entry metadata
1335             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
1336             */
1337            @Override
1338            public DLFileEntryMetadata findByFileEntryId_Last(long fileEntryId,
1339                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1340                    throws NoSuchFileEntryMetadataException {
1341                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileEntryId_Last(fileEntryId,
1342                                    orderByComparator);
1343    
1344                    if (dlFileEntryMetadata != null) {
1345                            return dlFileEntryMetadata;
1346                    }
1347    
1348                    StringBundler msg = new StringBundler(4);
1349    
1350                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1351    
1352                    msg.append("fileEntryId=");
1353                    msg.append(fileEntryId);
1354    
1355                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1356    
1357                    throw new NoSuchFileEntryMetadataException(msg.toString());
1358            }
1359    
1360            /**
1361             * Returns the last document library file entry metadata in the ordered set where fileEntryId = &#63;.
1362             *
1363             * @param fileEntryId the file entry ID
1364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1365             * @return the last matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
1366             */
1367            @Override
1368            public DLFileEntryMetadata fetchByFileEntryId_Last(long fileEntryId,
1369                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1370                    int count = countByFileEntryId(fileEntryId);
1371    
1372                    if (count == 0) {
1373                            return null;
1374                    }
1375    
1376                    List<DLFileEntryMetadata> list = findByFileEntryId(fileEntryId,
1377                                    count - 1, count, orderByComparator);
1378    
1379                    if (!list.isEmpty()) {
1380                            return list.get(0);
1381                    }
1382    
1383                    return null;
1384            }
1385    
1386            /**
1387             * Returns the document library file entry metadatas before and after the current document library file entry metadata in the ordered set where fileEntryId = &#63;.
1388             *
1389             * @param fileEntryMetadataId the primary key of the current document library file entry metadata
1390             * @param fileEntryId the file entry ID
1391             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1392             * @return the previous, current, and next document library file entry metadata
1393             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
1394             */
1395            @Override
1396            public DLFileEntryMetadata[] findByFileEntryId_PrevAndNext(
1397                    long fileEntryMetadataId, long fileEntryId,
1398                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1399                    throws NoSuchFileEntryMetadataException {
1400                    DLFileEntryMetadata dlFileEntryMetadata = findByPrimaryKey(fileEntryMetadataId);
1401    
1402                    Session session = null;
1403    
1404                    try {
1405                            session = openSession();
1406    
1407                            DLFileEntryMetadata[] array = new DLFileEntryMetadataImpl[3];
1408    
1409                            array[0] = getByFileEntryId_PrevAndNext(session,
1410                                            dlFileEntryMetadata, fileEntryId, orderByComparator, true);
1411    
1412                            array[1] = dlFileEntryMetadata;
1413    
1414                            array[2] = getByFileEntryId_PrevAndNext(session,
1415                                            dlFileEntryMetadata, fileEntryId, orderByComparator, false);
1416    
1417                            return array;
1418                    }
1419                    catch (Exception e) {
1420                            throw processException(e);
1421                    }
1422                    finally {
1423                            closeSession(session);
1424                    }
1425            }
1426    
1427            protected DLFileEntryMetadata getByFileEntryId_PrevAndNext(
1428                    Session session, DLFileEntryMetadata dlFileEntryMetadata,
1429                    long fileEntryId,
1430                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
1431                    boolean previous) {
1432                    StringBundler query = null;
1433    
1434                    if (orderByComparator != null) {
1435                            query = new StringBundler(6 +
1436                                            (orderByComparator.getOrderByFields().length * 6));
1437                    }
1438                    else {
1439                            query = new StringBundler(3);
1440                    }
1441    
1442                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
1443    
1444                    query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1445    
1446                    if (orderByComparator != null) {
1447                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1448    
1449                            if (orderByConditionFields.length > 0) {
1450                                    query.append(WHERE_AND);
1451                            }
1452    
1453                            for (int i = 0; i < orderByConditionFields.length; i++) {
1454                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1455                                    query.append(orderByConditionFields[i]);
1456    
1457                                    if ((i + 1) < orderByConditionFields.length) {
1458                                            if (orderByComparator.isAscending() ^ previous) {
1459                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1460                                            }
1461                                            else {
1462                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1463                                            }
1464                                    }
1465                                    else {
1466                                            if (orderByComparator.isAscending() ^ previous) {
1467                                                    query.append(WHERE_GREATER_THAN);
1468                                            }
1469                                            else {
1470                                                    query.append(WHERE_LESSER_THAN);
1471                                            }
1472                                    }
1473                            }
1474    
1475                            query.append(ORDER_BY_CLAUSE);
1476    
1477                            String[] orderByFields = orderByComparator.getOrderByFields();
1478    
1479                            for (int i = 0; i < orderByFields.length; i++) {
1480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1481                                    query.append(orderByFields[i]);
1482    
1483                                    if ((i + 1) < orderByFields.length) {
1484                                            if (orderByComparator.isAscending() ^ previous) {
1485                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1486                                            }
1487                                            else {
1488                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1489                                            }
1490                                    }
1491                                    else {
1492                                            if (orderByComparator.isAscending() ^ previous) {
1493                                                    query.append(ORDER_BY_ASC);
1494                                            }
1495                                            else {
1496                                                    query.append(ORDER_BY_DESC);
1497                                            }
1498                                    }
1499                            }
1500                    }
1501                    else {
1502                            query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
1503                    }
1504    
1505                    String sql = query.toString();
1506    
1507                    Query q = session.createQuery(sql);
1508    
1509                    q.setFirstResult(0);
1510                    q.setMaxResults(2);
1511    
1512                    QueryPos qPos = QueryPos.getInstance(q);
1513    
1514                    qPos.add(fileEntryId);
1515    
1516                    if (orderByComparator != null) {
1517                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileEntryMetadata);
1518    
1519                            for (Object value : values) {
1520                                    qPos.add(value);
1521                            }
1522                    }
1523    
1524                    List<DLFileEntryMetadata> list = q.list();
1525    
1526                    if (list.size() == 2) {
1527                            return list.get(1);
1528                    }
1529                    else {
1530                            return null;
1531                    }
1532            }
1533    
1534            /**
1535             * Removes all the document library file entry metadatas where fileEntryId = &#63; from the database.
1536             *
1537             * @param fileEntryId the file entry ID
1538             */
1539            @Override
1540            public void removeByFileEntryId(long fileEntryId) {
1541                    for (DLFileEntryMetadata dlFileEntryMetadata : findByFileEntryId(
1542                                    fileEntryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1543                            remove(dlFileEntryMetadata);
1544                    }
1545            }
1546    
1547            /**
1548             * Returns the number of document library file entry metadatas where fileEntryId = &#63;.
1549             *
1550             * @param fileEntryId the file entry ID
1551             * @return the number of matching document library file entry metadatas
1552             */
1553            @Override
1554            public int countByFileEntryId(long fileEntryId) {
1555                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEENTRYID;
1556    
1557                    Object[] finderArgs = new Object[] { fileEntryId };
1558    
1559                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1560                                    this);
1561    
1562                    if (count == null) {
1563                            StringBundler query = new StringBundler(2);
1564    
1565                            query.append(_SQL_COUNT_DLFILEENTRYMETADATA_WHERE);
1566    
1567                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1568    
1569                            String sql = query.toString();
1570    
1571                            Session session = null;
1572    
1573                            try {
1574                                    session = openSession();
1575    
1576                                    Query q = session.createQuery(sql);
1577    
1578                                    QueryPos qPos = QueryPos.getInstance(q);
1579    
1580                                    qPos.add(fileEntryId);
1581    
1582                                    count = (Long)q.uniqueResult();
1583    
1584                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1585                            }
1586                            catch (Exception e) {
1587                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1588    
1589                                    throw processException(e);
1590                            }
1591                            finally {
1592                                    closeSession(session);
1593                            }
1594                    }
1595    
1596                    return count.intValue();
1597            }
1598    
1599            private static final String _FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2 = "dlFileEntryMetadata.fileEntryId = ?";
1600            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEVERSIONID =
1601                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1602                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
1603                            DLFileEntryMetadataImpl.class,
1604                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFileVersionId",
1605                            new String[] {
1606                                    Long.class.getName(),
1607                                    
1608                            Integer.class.getName(), Integer.class.getName(),
1609                                    OrderByComparator.class.getName()
1610                            });
1611            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID =
1612                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1613                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
1614                            DLFileEntryMetadataImpl.class,
1615                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFileVersionId",
1616                            new String[] { Long.class.getName() },
1617                            DLFileEntryMetadataModelImpl.FILEVERSIONID_COLUMN_BITMASK);
1618            public static final FinderPath FINDER_PATH_COUNT_BY_FILEVERSIONID = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1619                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
1620                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileVersionId",
1621                            new String[] { Long.class.getName() });
1622    
1623            /**
1624             * Returns all the document library file entry metadatas where fileVersionId = &#63;.
1625             *
1626             * @param fileVersionId the file version ID
1627             * @return the matching document library file entry metadatas
1628             */
1629            @Override
1630            public List<DLFileEntryMetadata> findByFileVersionId(long fileVersionId) {
1631                    return findByFileVersionId(fileVersionId, QueryUtil.ALL_POS,
1632                            QueryUtil.ALL_POS, null);
1633            }
1634    
1635            /**
1636             * Returns a range of all the document library file entry metadatas where fileVersionId = &#63;.
1637             *
1638             * <p>
1639             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
1640             * </p>
1641             *
1642             * @param fileVersionId the file version ID
1643             * @param start the lower bound of the range of document library file entry metadatas
1644             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1645             * @return the range of matching document library file entry metadatas
1646             */
1647            @Override
1648            public List<DLFileEntryMetadata> findByFileVersionId(long fileVersionId,
1649                    int start, int end) {
1650                    return findByFileVersionId(fileVersionId, start, end, null);
1651            }
1652    
1653            /**
1654             * Returns an ordered range of all the document library file entry metadatas where fileVersionId = &#63;.
1655             *
1656             * <p>
1657             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
1658             * </p>
1659             *
1660             * @param fileVersionId the file version ID
1661             * @param start the lower bound of the range of document library file entry metadatas
1662             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1663             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1664             * @return the ordered range of matching document library file entry metadatas
1665             */
1666            @Override
1667            public List<DLFileEntryMetadata> findByFileVersionId(long fileVersionId,
1668                    int start, int end,
1669                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1670                    boolean pagination = true;
1671                    FinderPath finderPath = null;
1672                    Object[] finderArgs = null;
1673    
1674                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1675                                    (orderByComparator == null)) {
1676                            pagination = false;
1677                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID;
1678                            finderArgs = new Object[] { fileVersionId };
1679                    }
1680                    else {
1681                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEVERSIONID;
1682                            finderArgs = new Object[] {
1683                                            fileVersionId,
1684                                            
1685                                            start, end, orderByComparator
1686                                    };
1687                    }
1688    
1689                    List<DLFileEntryMetadata> list = (List<DLFileEntryMetadata>)FinderCacheUtil.getResult(finderPath,
1690                                    finderArgs, this);
1691    
1692                    if ((list != null) && !list.isEmpty()) {
1693                            for (DLFileEntryMetadata dlFileEntryMetadata : list) {
1694                                    if ((fileVersionId != dlFileEntryMetadata.getFileVersionId())) {
1695                                            list = null;
1696    
1697                                            break;
1698                                    }
1699                            }
1700                    }
1701    
1702                    if (list == null) {
1703                            StringBundler query = null;
1704    
1705                            if (orderByComparator != null) {
1706                                    query = new StringBundler(3 +
1707                                                    (orderByComparator.getOrderByFields().length * 3));
1708                            }
1709                            else {
1710                                    query = new StringBundler(3);
1711                            }
1712    
1713                            query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
1714    
1715                            query.append(_FINDER_COLUMN_FILEVERSIONID_FILEVERSIONID_2);
1716    
1717                            if (orderByComparator != null) {
1718                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1719                                            orderByComparator);
1720                            }
1721                            else
1722                             if (pagination) {
1723                                    query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
1724                            }
1725    
1726                            String sql = query.toString();
1727    
1728                            Session session = null;
1729    
1730                            try {
1731                                    session = openSession();
1732    
1733                                    Query q = session.createQuery(sql);
1734    
1735                                    QueryPos qPos = QueryPos.getInstance(q);
1736    
1737                                    qPos.add(fileVersionId);
1738    
1739                                    if (!pagination) {
1740                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
1741                                                            getDialect(), start, end, false);
1742    
1743                                            Collections.sort(list);
1744    
1745                                            list = Collections.unmodifiableList(list);
1746                                    }
1747                                    else {
1748                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
1749                                                            getDialect(), start, end);
1750                                    }
1751    
1752                                    cacheResult(list);
1753    
1754                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1755                            }
1756                            catch (Exception e) {
1757                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1758    
1759                                    throw processException(e);
1760                            }
1761                            finally {
1762                                    closeSession(session);
1763                            }
1764                    }
1765    
1766                    return list;
1767            }
1768    
1769            /**
1770             * Returns the first document library file entry metadata in the ordered set where fileVersionId = &#63;.
1771             *
1772             * @param fileVersionId the file version ID
1773             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1774             * @return the first matching document library file entry metadata
1775             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
1776             */
1777            @Override
1778            public DLFileEntryMetadata findByFileVersionId_First(long fileVersionId,
1779                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1780                    throws NoSuchFileEntryMetadataException {
1781                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileVersionId_First(fileVersionId,
1782                                    orderByComparator);
1783    
1784                    if (dlFileEntryMetadata != null) {
1785                            return dlFileEntryMetadata;
1786                    }
1787    
1788                    StringBundler msg = new StringBundler(4);
1789    
1790                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1791    
1792                    msg.append("fileVersionId=");
1793                    msg.append(fileVersionId);
1794    
1795                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1796    
1797                    throw new NoSuchFileEntryMetadataException(msg.toString());
1798            }
1799    
1800            /**
1801             * Returns the first document library file entry metadata in the ordered set where fileVersionId = &#63;.
1802             *
1803             * @param fileVersionId the file version ID
1804             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1805             * @return the first matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
1806             */
1807            @Override
1808            public DLFileEntryMetadata fetchByFileVersionId_First(long fileVersionId,
1809                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1810                    List<DLFileEntryMetadata> list = findByFileVersionId(fileVersionId, 0,
1811                                    1, orderByComparator);
1812    
1813                    if (!list.isEmpty()) {
1814                            return list.get(0);
1815                    }
1816    
1817                    return null;
1818            }
1819    
1820            /**
1821             * Returns the last document library file entry metadata in the ordered set where fileVersionId = &#63;.
1822             *
1823             * @param fileVersionId the file version ID
1824             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1825             * @return the last matching document library file entry metadata
1826             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
1827             */
1828            @Override
1829            public DLFileEntryMetadata findByFileVersionId_Last(long fileVersionId,
1830                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1831                    throws NoSuchFileEntryMetadataException {
1832                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileVersionId_Last(fileVersionId,
1833                                    orderByComparator);
1834    
1835                    if (dlFileEntryMetadata != null) {
1836                            return dlFileEntryMetadata;
1837                    }
1838    
1839                    StringBundler msg = new StringBundler(4);
1840    
1841                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1842    
1843                    msg.append("fileVersionId=");
1844                    msg.append(fileVersionId);
1845    
1846                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1847    
1848                    throw new NoSuchFileEntryMetadataException(msg.toString());
1849            }
1850    
1851            /**
1852             * Returns the last document library file entry metadata in the ordered set where fileVersionId = &#63;.
1853             *
1854             * @param fileVersionId the file version ID
1855             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1856             * @return the last matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
1857             */
1858            @Override
1859            public DLFileEntryMetadata fetchByFileVersionId_Last(long fileVersionId,
1860                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1861                    int count = countByFileVersionId(fileVersionId);
1862    
1863                    if (count == 0) {
1864                            return null;
1865                    }
1866    
1867                    List<DLFileEntryMetadata> list = findByFileVersionId(fileVersionId,
1868                                    count - 1, count, orderByComparator);
1869    
1870                    if (!list.isEmpty()) {
1871                            return list.get(0);
1872                    }
1873    
1874                    return null;
1875            }
1876    
1877            /**
1878             * Returns the document library file entry metadatas before and after the current document library file entry metadata in the ordered set where fileVersionId = &#63;.
1879             *
1880             * @param fileEntryMetadataId the primary key of the current document library file entry metadata
1881             * @param fileVersionId the file version ID
1882             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1883             * @return the previous, current, and next document library file entry metadata
1884             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
1885             */
1886            @Override
1887            public DLFileEntryMetadata[] findByFileVersionId_PrevAndNext(
1888                    long fileEntryMetadataId, long fileVersionId,
1889                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1890                    throws NoSuchFileEntryMetadataException {
1891                    DLFileEntryMetadata dlFileEntryMetadata = findByPrimaryKey(fileEntryMetadataId);
1892    
1893                    Session session = null;
1894    
1895                    try {
1896                            session = openSession();
1897    
1898                            DLFileEntryMetadata[] array = new DLFileEntryMetadataImpl[3];
1899    
1900                            array[0] = getByFileVersionId_PrevAndNext(session,
1901                                            dlFileEntryMetadata, fileVersionId, orderByComparator, true);
1902    
1903                            array[1] = dlFileEntryMetadata;
1904    
1905                            array[2] = getByFileVersionId_PrevAndNext(session,
1906                                            dlFileEntryMetadata, fileVersionId, orderByComparator, false);
1907    
1908                            return array;
1909                    }
1910                    catch (Exception e) {
1911                            throw processException(e);
1912                    }
1913                    finally {
1914                            closeSession(session);
1915                    }
1916            }
1917    
1918            protected DLFileEntryMetadata getByFileVersionId_PrevAndNext(
1919                    Session session, DLFileEntryMetadata dlFileEntryMetadata,
1920                    long fileVersionId,
1921                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
1922                    boolean previous) {
1923                    StringBundler query = null;
1924    
1925                    if (orderByComparator != null) {
1926                            query = new StringBundler(6 +
1927                                            (orderByComparator.getOrderByFields().length * 6));
1928                    }
1929                    else {
1930                            query = new StringBundler(3);
1931                    }
1932    
1933                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
1934    
1935                    query.append(_FINDER_COLUMN_FILEVERSIONID_FILEVERSIONID_2);
1936    
1937                    if (orderByComparator != null) {
1938                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1939    
1940                            if (orderByConditionFields.length > 0) {
1941                                    query.append(WHERE_AND);
1942                            }
1943    
1944                            for (int i = 0; i < orderByConditionFields.length; i++) {
1945                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1946                                    query.append(orderByConditionFields[i]);
1947    
1948                                    if ((i + 1) < orderByConditionFields.length) {
1949                                            if (orderByComparator.isAscending() ^ previous) {
1950                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1951                                            }
1952                                            else {
1953                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1954                                            }
1955                                    }
1956                                    else {
1957                                            if (orderByComparator.isAscending() ^ previous) {
1958                                                    query.append(WHERE_GREATER_THAN);
1959                                            }
1960                                            else {
1961                                                    query.append(WHERE_LESSER_THAN);
1962                                            }
1963                                    }
1964                            }
1965    
1966                            query.append(ORDER_BY_CLAUSE);
1967    
1968                            String[] orderByFields = orderByComparator.getOrderByFields();
1969    
1970                            for (int i = 0; i < orderByFields.length; i++) {
1971                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1972                                    query.append(orderByFields[i]);
1973    
1974                                    if ((i + 1) < orderByFields.length) {
1975                                            if (orderByComparator.isAscending() ^ previous) {
1976                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1977                                            }
1978                                            else {
1979                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1980                                            }
1981                                    }
1982                                    else {
1983                                            if (orderByComparator.isAscending() ^ previous) {
1984                                                    query.append(ORDER_BY_ASC);
1985                                            }
1986                                            else {
1987                                                    query.append(ORDER_BY_DESC);
1988                                            }
1989                                    }
1990                            }
1991                    }
1992                    else {
1993                            query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
1994                    }
1995    
1996                    String sql = query.toString();
1997    
1998                    Query q = session.createQuery(sql);
1999    
2000                    q.setFirstResult(0);
2001                    q.setMaxResults(2);
2002    
2003                    QueryPos qPos = QueryPos.getInstance(q);
2004    
2005                    qPos.add(fileVersionId);
2006    
2007                    if (orderByComparator != null) {
2008                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileEntryMetadata);
2009    
2010                            for (Object value : values) {
2011                                    qPos.add(value);
2012                            }
2013                    }
2014    
2015                    List<DLFileEntryMetadata> list = q.list();
2016    
2017                    if (list.size() == 2) {
2018                            return list.get(1);
2019                    }
2020                    else {
2021                            return null;
2022                    }
2023            }
2024    
2025            /**
2026             * Removes all the document library file entry metadatas where fileVersionId = &#63; from the database.
2027             *
2028             * @param fileVersionId the file version ID
2029             */
2030            @Override
2031            public void removeByFileVersionId(long fileVersionId) {
2032                    for (DLFileEntryMetadata dlFileEntryMetadata : findByFileVersionId(
2033                                    fileVersionId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2034                            remove(dlFileEntryMetadata);
2035                    }
2036            }
2037    
2038            /**
2039             * Returns the number of document library file entry metadatas where fileVersionId = &#63;.
2040             *
2041             * @param fileVersionId the file version ID
2042             * @return the number of matching document library file entry metadatas
2043             */
2044            @Override
2045            public int countByFileVersionId(long fileVersionId) {
2046                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEVERSIONID;
2047    
2048                    Object[] finderArgs = new Object[] { fileVersionId };
2049    
2050                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2051                                    this);
2052    
2053                    if (count == null) {
2054                            StringBundler query = new StringBundler(2);
2055    
2056                            query.append(_SQL_COUNT_DLFILEENTRYMETADATA_WHERE);
2057    
2058                            query.append(_FINDER_COLUMN_FILEVERSIONID_FILEVERSIONID_2);
2059    
2060                            String sql = query.toString();
2061    
2062                            Session session = null;
2063    
2064                            try {
2065                                    session = openSession();
2066    
2067                                    Query q = session.createQuery(sql);
2068    
2069                                    QueryPos qPos = QueryPos.getInstance(q);
2070    
2071                                    qPos.add(fileVersionId);
2072    
2073                                    count = (Long)q.uniqueResult();
2074    
2075                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2076                            }
2077                            catch (Exception e) {
2078                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2079    
2080                                    throw processException(e);
2081                            }
2082                            finally {
2083                                    closeSession(session);
2084                            }
2085                    }
2086    
2087                    return count.intValue();
2088            }
2089    
2090            private static final String _FINDER_COLUMN_FILEVERSIONID_FILEVERSIONID_2 = "dlFileEntryMetadata.fileVersionId = ?";
2091            public static final FinderPath FINDER_PATH_FETCH_BY_D_F = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2092                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
2093                            DLFileEntryMetadataImpl.class, FINDER_CLASS_NAME_ENTITY,
2094                            "fetchByD_F",
2095                            new String[] { Long.class.getName(), Long.class.getName() },
2096                            DLFileEntryMetadataModelImpl.DDMSTRUCTUREID_COLUMN_BITMASK |
2097                            DLFileEntryMetadataModelImpl.FILEVERSIONID_COLUMN_BITMASK);
2098            public static final FinderPath FINDER_PATH_COUNT_BY_D_F = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2099                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
2100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByD_F",
2101                            new String[] { Long.class.getName(), Long.class.getName() });
2102    
2103            /**
2104             * Returns the document library file entry metadata where DDMStructureId = &#63; and fileVersionId = &#63; or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException} if it could not be found.
2105             *
2106             * @param DDMStructureId the d d m structure ID
2107             * @param fileVersionId the file version ID
2108             * @return the matching document library file entry metadata
2109             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
2110             */
2111            @Override
2112            public DLFileEntryMetadata findByD_F(long DDMStructureId, long fileVersionId)
2113                    throws NoSuchFileEntryMetadataException {
2114                    DLFileEntryMetadata dlFileEntryMetadata = fetchByD_F(DDMStructureId,
2115                                    fileVersionId);
2116    
2117                    if (dlFileEntryMetadata == null) {
2118                            StringBundler msg = new StringBundler(6);
2119    
2120                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2121    
2122                            msg.append("DDMStructureId=");
2123                            msg.append(DDMStructureId);
2124    
2125                            msg.append(", fileVersionId=");
2126                            msg.append(fileVersionId);
2127    
2128                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2129    
2130                            if (_log.isWarnEnabled()) {
2131                                    _log.warn(msg.toString());
2132                            }
2133    
2134                            throw new NoSuchFileEntryMetadataException(msg.toString());
2135                    }
2136    
2137                    return dlFileEntryMetadata;
2138            }
2139    
2140            /**
2141             * Returns the document library file entry metadata where DDMStructureId = &#63; and fileVersionId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2142             *
2143             * @param DDMStructureId the d d m structure ID
2144             * @param fileVersionId the file version ID
2145             * @return the matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
2146             */
2147            @Override
2148            public DLFileEntryMetadata fetchByD_F(long DDMStructureId,
2149                    long fileVersionId) {
2150                    return fetchByD_F(DDMStructureId, fileVersionId, true);
2151            }
2152    
2153            /**
2154             * Returns the document library file entry metadata where DDMStructureId = &#63; and fileVersionId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2155             *
2156             * @param DDMStructureId the d d m structure ID
2157             * @param fileVersionId the file version ID
2158             * @param retrieveFromCache whether to use the finder cache
2159             * @return the matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
2160             */
2161            @Override
2162            public DLFileEntryMetadata fetchByD_F(long DDMStructureId,
2163                    long fileVersionId, boolean retrieveFromCache) {
2164                    Object[] finderArgs = new Object[] { DDMStructureId, fileVersionId };
2165    
2166                    Object result = null;
2167    
2168                    if (retrieveFromCache) {
2169                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_D_F,
2170                                            finderArgs, this);
2171                    }
2172    
2173                    if (result instanceof DLFileEntryMetadata) {
2174                            DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)result;
2175    
2176                            if ((DDMStructureId != dlFileEntryMetadata.getDDMStructureId()) ||
2177                                            (fileVersionId != dlFileEntryMetadata.getFileVersionId())) {
2178                                    result = null;
2179                            }
2180                    }
2181    
2182                    if (result == null) {
2183                            StringBundler query = new StringBundler(4);
2184    
2185                            query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
2186    
2187                            query.append(_FINDER_COLUMN_D_F_DDMSTRUCTUREID_2);
2188    
2189                            query.append(_FINDER_COLUMN_D_F_FILEVERSIONID_2);
2190    
2191                            String sql = query.toString();
2192    
2193                            Session session = null;
2194    
2195                            try {
2196                                    session = openSession();
2197    
2198                                    Query q = session.createQuery(sql);
2199    
2200                                    QueryPos qPos = QueryPos.getInstance(q);
2201    
2202                                    qPos.add(DDMStructureId);
2203    
2204                                    qPos.add(fileVersionId);
2205    
2206                                    List<DLFileEntryMetadata> list = q.list();
2207    
2208                                    if (list.isEmpty()) {
2209                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_D_F,
2210                                                    finderArgs, list);
2211                                    }
2212                                    else {
2213                                            DLFileEntryMetadata dlFileEntryMetadata = list.get(0);
2214    
2215                                            result = dlFileEntryMetadata;
2216    
2217                                            cacheResult(dlFileEntryMetadata);
2218    
2219                                            if ((dlFileEntryMetadata.getDDMStructureId() != DDMStructureId) ||
2220                                                            (dlFileEntryMetadata.getFileVersionId() != fileVersionId)) {
2221                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_D_F,
2222                                                            finderArgs, dlFileEntryMetadata);
2223                                            }
2224                                    }
2225                            }
2226                            catch (Exception e) {
2227                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_D_F,
2228                                            finderArgs);
2229    
2230                                    throw processException(e);
2231                            }
2232                            finally {
2233                                    closeSession(session);
2234                            }
2235                    }
2236    
2237                    if (result instanceof List<?>) {
2238                            return null;
2239                    }
2240                    else {
2241                            return (DLFileEntryMetadata)result;
2242                    }
2243            }
2244    
2245            /**
2246             * Removes the document library file entry metadata where DDMStructureId = &#63; and fileVersionId = &#63; from the database.
2247             *
2248             * @param DDMStructureId the d d m structure ID
2249             * @param fileVersionId the file version ID
2250             * @return the document library file entry metadata that was removed
2251             */
2252            @Override
2253            public DLFileEntryMetadata removeByD_F(long DDMStructureId,
2254                    long fileVersionId) throws NoSuchFileEntryMetadataException {
2255                    DLFileEntryMetadata dlFileEntryMetadata = findByD_F(DDMStructureId,
2256                                    fileVersionId);
2257    
2258                    return remove(dlFileEntryMetadata);
2259            }
2260    
2261            /**
2262             * Returns the number of document library file entry metadatas where DDMStructureId = &#63; and fileVersionId = &#63;.
2263             *
2264             * @param DDMStructureId the d d m structure ID
2265             * @param fileVersionId the file version ID
2266             * @return the number of matching document library file entry metadatas
2267             */
2268            @Override
2269            public int countByD_F(long DDMStructureId, long fileVersionId) {
2270                    FinderPath finderPath = FINDER_PATH_COUNT_BY_D_F;
2271    
2272                    Object[] finderArgs = new Object[] { DDMStructureId, fileVersionId };
2273    
2274                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2275                                    this);
2276    
2277                    if (count == null) {
2278                            StringBundler query = new StringBundler(3);
2279    
2280                            query.append(_SQL_COUNT_DLFILEENTRYMETADATA_WHERE);
2281    
2282                            query.append(_FINDER_COLUMN_D_F_DDMSTRUCTUREID_2);
2283    
2284                            query.append(_FINDER_COLUMN_D_F_FILEVERSIONID_2);
2285    
2286                            String sql = query.toString();
2287    
2288                            Session session = null;
2289    
2290                            try {
2291                                    session = openSession();
2292    
2293                                    Query q = session.createQuery(sql);
2294    
2295                                    QueryPos qPos = QueryPos.getInstance(q);
2296    
2297                                    qPos.add(DDMStructureId);
2298    
2299                                    qPos.add(fileVersionId);
2300    
2301                                    count = (Long)q.uniqueResult();
2302    
2303                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2304                            }
2305                            catch (Exception e) {
2306                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2307    
2308                                    throw processException(e);
2309                            }
2310                            finally {
2311                                    closeSession(session);
2312                            }
2313                    }
2314    
2315                    return count.intValue();
2316            }
2317    
2318            private static final String _FINDER_COLUMN_D_F_DDMSTRUCTUREID_2 = "dlFileEntryMetadata.DDMStructureId = ? AND ";
2319            private static final String _FINDER_COLUMN_D_F_FILEVERSIONID_2 = "dlFileEntryMetadata.fileVersionId = ?";
2320    
2321            public DLFileEntryMetadataPersistenceImpl() {
2322                    setModelClass(DLFileEntryMetadata.class);
2323            }
2324    
2325            /**
2326             * Caches the document library file entry metadata in the entity cache if it is enabled.
2327             *
2328             * @param dlFileEntryMetadata the document library file entry metadata
2329             */
2330            @Override
2331            public void cacheResult(DLFileEntryMetadata dlFileEntryMetadata) {
2332                    EntityCacheUtil.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2333                            DLFileEntryMetadataImpl.class, dlFileEntryMetadata.getPrimaryKey(),
2334                            dlFileEntryMetadata);
2335    
2336                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_D_F,
2337                            new Object[] {
2338                                    dlFileEntryMetadata.getDDMStructureId(),
2339                                    dlFileEntryMetadata.getFileVersionId()
2340                            }, dlFileEntryMetadata);
2341    
2342                    dlFileEntryMetadata.resetOriginalValues();
2343            }
2344    
2345            /**
2346             * Caches the document library file entry metadatas in the entity cache if it is enabled.
2347             *
2348             * @param dlFileEntryMetadatas the document library file entry metadatas
2349             */
2350            @Override
2351            public void cacheResult(List<DLFileEntryMetadata> dlFileEntryMetadatas) {
2352                    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
2353                            if (EntityCacheUtil.getResult(
2354                                                    DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2355                                                    DLFileEntryMetadataImpl.class,
2356                                                    dlFileEntryMetadata.getPrimaryKey()) == null) {
2357                                    cacheResult(dlFileEntryMetadata);
2358                            }
2359                            else {
2360                                    dlFileEntryMetadata.resetOriginalValues();
2361                            }
2362                    }
2363            }
2364    
2365            /**
2366             * Clears the cache for all document library file entry metadatas.
2367             *
2368             * <p>
2369             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2370             * </p>
2371             */
2372            @Override
2373            public void clearCache() {
2374                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2375                            CacheRegistryUtil.clear(DLFileEntryMetadataImpl.class.getName());
2376                    }
2377    
2378                    EntityCacheUtil.clearCache(DLFileEntryMetadataImpl.class);
2379    
2380                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2381                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2382                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2383            }
2384    
2385            /**
2386             * Clears the cache for the document library file entry metadata.
2387             *
2388             * <p>
2389             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2390             * </p>
2391             */
2392            @Override
2393            public void clearCache(DLFileEntryMetadata dlFileEntryMetadata) {
2394                    EntityCacheUtil.removeResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2395                            DLFileEntryMetadataImpl.class, dlFileEntryMetadata.getPrimaryKey());
2396    
2397                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2398                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2399    
2400                    clearUniqueFindersCache(dlFileEntryMetadata);
2401            }
2402    
2403            @Override
2404            public void clearCache(List<DLFileEntryMetadata> dlFileEntryMetadatas) {
2405                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2406                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2407    
2408                    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
2409                            EntityCacheUtil.removeResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2410                                    DLFileEntryMetadataImpl.class,
2411                                    dlFileEntryMetadata.getPrimaryKey());
2412    
2413                            clearUniqueFindersCache(dlFileEntryMetadata);
2414                    }
2415            }
2416    
2417            protected void cacheUniqueFindersCache(
2418                    DLFileEntryMetadata dlFileEntryMetadata) {
2419                    if (dlFileEntryMetadata.isNew()) {
2420                            Object[] args = new Object[] {
2421                                            dlFileEntryMetadata.getDDMStructureId(),
2422                                            dlFileEntryMetadata.getFileVersionId()
2423                                    };
2424    
2425                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_D_F, args,
2426                                    Long.valueOf(1));
2427                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_D_F, args,
2428                                    dlFileEntryMetadata);
2429                    }
2430                    else {
2431                            DLFileEntryMetadataModelImpl dlFileEntryMetadataModelImpl = (DLFileEntryMetadataModelImpl)dlFileEntryMetadata;
2432    
2433                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2434                                            FINDER_PATH_FETCH_BY_D_F.getColumnBitmask()) != 0) {
2435                                    Object[] args = new Object[] {
2436                                                    dlFileEntryMetadata.getDDMStructureId(),
2437                                                    dlFileEntryMetadata.getFileVersionId()
2438                                            };
2439    
2440                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_D_F, args,
2441                                            Long.valueOf(1));
2442                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_D_F, args,
2443                                            dlFileEntryMetadata);
2444                            }
2445                    }
2446            }
2447    
2448            protected void clearUniqueFindersCache(
2449                    DLFileEntryMetadata dlFileEntryMetadata) {
2450                    DLFileEntryMetadataModelImpl dlFileEntryMetadataModelImpl = (DLFileEntryMetadataModelImpl)dlFileEntryMetadata;
2451    
2452                    Object[] args = new Object[] {
2453                                    dlFileEntryMetadata.getDDMStructureId(),
2454                                    dlFileEntryMetadata.getFileVersionId()
2455                            };
2456    
2457                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_D_F, args);
2458                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_D_F, args);
2459    
2460                    if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2461                                    FINDER_PATH_FETCH_BY_D_F.getColumnBitmask()) != 0) {
2462                            args = new Object[] {
2463                                            dlFileEntryMetadataModelImpl.getOriginalDDMStructureId(),
2464                                            dlFileEntryMetadataModelImpl.getOriginalFileVersionId()
2465                                    };
2466    
2467                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_D_F, args);
2468                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_D_F, args);
2469                    }
2470            }
2471    
2472            /**
2473             * Creates a new document library file entry metadata with the primary key. Does not add the document library file entry metadata to the database.
2474             *
2475             * @param fileEntryMetadataId the primary key for the new document library file entry metadata
2476             * @return the new document library file entry metadata
2477             */
2478            @Override
2479            public DLFileEntryMetadata create(long fileEntryMetadataId) {
2480                    DLFileEntryMetadata dlFileEntryMetadata = new DLFileEntryMetadataImpl();
2481    
2482                    dlFileEntryMetadata.setNew(true);
2483                    dlFileEntryMetadata.setPrimaryKey(fileEntryMetadataId);
2484    
2485                    String uuid = PortalUUIDUtil.generate();
2486    
2487                    dlFileEntryMetadata.setUuid(uuid);
2488    
2489                    return dlFileEntryMetadata;
2490            }
2491    
2492            /**
2493             * Removes the document library file entry metadata with the primary key from the database. Also notifies the appropriate model listeners.
2494             *
2495             * @param fileEntryMetadataId the primary key of the document library file entry metadata
2496             * @return the document library file entry metadata that was removed
2497             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2498             */
2499            @Override
2500            public DLFileEntryMetadata remove(long fileEntryMetadataId)
2501                    throws NoSuchFileEntryMetadataException {
2502                    return remove((Serializable)fileEntryMetadataId);
2503            }
2504    
2505            /**
2506             * Removes the document library file entry metadata with the primary key from the database. Also notifies the appropriate model listeners.
2507             *
2508             * @param primaryKey the primary key of the document library file entry metadata
2509             * @return the document library file entry metadata that was removed
2510             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2511             */
2512            @Override
2513            public DLFileEntryMetadata remove(Serializable primaryKey)
2514                    throws NoSuchFileEntryMetadataException {
2515                    Session session = null;
2516    
2517                    try {
2518                            session = openSession();
2519    
2520                            DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)session.get(DLFileEntryMetadataImpl.class,
2521                                            primaryKey);
2522    
2523                            if (dlFileEntryMetadata == null) {
2524                                    if (_log.isWarnEnabled()) {
2525                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2526                                    }
2527    
2528                                    throw new NoSuchFileEntryMetadataException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2529                                            primaryKey);
2530                            }
2531    
2532                            return remove(dlFileEntryMetadata);
2533                    }
2534                    catch (NoSuchFileEntryMetadataException nsee) {
2535                            throw nsee;
2536                    }
2537                    catch (Exception e) {
2538                            throw processException(e);
2539                    }
2540                    finally {
2541                            closeSession(session);
2542                    }
2543            }
2544    
2545            @Override
2546            protected DLFileEntryMetadata removeImpl(
2547                    DLFileEntryMetadata dlFileEntryMetadata) {
2548                    dlFileEntryMetadata = toUnwrappedModel(dlFileEntryMetadata);
2549    
2550                    Session session = null;
2551    
2552                    try {
2553                            session = openSession();
2554    
2555                            if (!session.contains(dlFileEntryMetadata)) {
2556                                    dlFileEntryMetadata = (DLFileEntryMetadata)session.get(DLFileEntryMetadataImpl.class,
2557                                                    dlFileEntryMetadata.getPrimaryKeyObj());
2558                            }
2559    
2560                            if (dlFileEntryMetadata != null) {
2561                                    session.delete(dlFileEntryMetadata);
2562                            }
2563                    }
2564                    catch (Exception e) {
2565                            throw processException(e);
2566                    }
2567                    finally {
2568                            closeSession(session);
2569                    }
2570    
2571                    if (dlFileEntryMetadata != null) {
2572                            clearCache(dlFileEntryMetadata);
2573                    }
2574    
2575                    return dlFileEntryMetadata;
2576            }
2577    
2578            @Override
2579            public DLFileEntryMetadata updateImpl(
2580                    com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata dlFileEntryMetadata) {
2581                    dlFileEntryMetadata = toUnwrappedModel(dlFileEntryMetadata);
2582    
2583                    boolean isNew = dlFileEntryMetadata.isNew();
2584    
2585                    DLFileEntryMetadataModelImpl dlFileEntryMetadataModelImpl = (DLFileEntryMetadataModelImpl)dlFileEntryMetadata;
2586    
2587                    if (Validator.isNull(dlFileEntryMetadata.getUuid())) {
2588                            String uuid = PortalUUIDUtil.generate();
2589    
2590                            dlFileEntryMetadata.setUuid(uuid);
2591                    }
2592    
2593                    Session session = null;
2594    
2595                    try {
2596                            session = openSession();
2597    
2598                            if (dlFileEntryMetadata.isNew()) {
2599                                    session.save(dlFileEntryMetadata);
2600    
2601                                    dlFileEntryMetadata.setNew(false);
2602                            }
2603                            else {
2604                                    session.merge(dlFileEntryMetadata);
2605                            }
2606                    }
2607                    catch (Exception e) {
2608                            throw processException(e);
2609                    }
2610                    finally {
2611                            closeSession(session);
2612                    }
2613    
2614                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2615    
2616                    if (isNew || !DLFileEntryMetadataModelImpl.COLUMN_BITMASK_ENABLED) {
2617                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2618                    }
2619    
2620                    else {
2621                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2622                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2623                                    Object[] args = new Object[] {
2624                                                    dlFileEntryMetadataModelImpl.getOriginalUuid()
2625                                            };
2626    
2627                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2628                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2629                                            args);
2630    
2631                                    args = new Object[] { dlFileEntryMetadataModelImpl.getUuid() };
2632    
2633                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2634                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2635                                            args);
2636                            }
2637    
2638                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2639                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYTYPEID.getColumnBitmask()) != 0) {
2640                                    Object[] args = new Object[] {
2641                                                    dlFileEntryMetadataModelImpl.getOriginalFileEntryTypeId()
2642                                            };
2643    
2644                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYTYPEID,
2645                                            args);
2646                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYTYPEID,
2647                                            args);
2648    
2649                                    args = new Object[] {
2650                                                    dlFileEntryMetadataModelImpl.getFileEntryTypeId()
2651                                            };
2652    
2653                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYTYPEID,
2654                                            args);
2655                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYTYPEID,
2656                                            args);
2657                            }
2658    
2659                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2660                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
2661                                    Object[] args = new Object[] {
2662                                                    dlFileEntryMetadataModelImpl.getOriginalFileEntryId()
2663                                            };
2664    
2665                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
2666                                            args);
2667                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
2668                                            args);
2669    
2670                                    args = new Object[] {
2671                                                    dlFileEntryMetadataModelImpl.getFileEntryId()
2672                                            };
2673    
2674                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
2675                                            args);
2676                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
2677                                            args);
2678                            }
2679    
2680                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2681                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID.getColumnBitmask()) != 0) {
2682                                    Object[] args = new Object[] {
2683                                                    dlFileEntryMetadataModelImpl.getOriginalFileVersionId()
2684                                            };
2685    
2686                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEVERSIONID,
2687                                            args);
2688                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID,
2689                                            args);
2690    
2691                                    args = new Object[] {
2692                                                    dlFileEntryMetadataModelImpl.getFileVersionId()
2693                                            };
2694    
2695                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEVERSIONID,
2696                                            args);
2697                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID,
2698                                            args);
2699                            }
2700                    }
2701    
2702                    EntityCacheUtil.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2703                            DLFileEntryMetadataImpl.class, dlFileEntryMetadata.getPrimaryKey(),
2704                            dlFileEntryMetadata, false);
2705    
2706                    clearUniqueFindersCache(dlFileEntryMetadata);
2707                    cacheUniqueFindersCache(dlFileEntryMetadata);
2708    
2709                    dlFileEntryMetadata.resetOriginalValues();
2710    
2711                    return dlFileEntryMetadata;
2712            }
2713    
2714            protected DLFileEntryMetadata toUnwrappedModel(
2715                    DLFileEntryMetadata dlFileEntryMetadata) {
2716                    if (dlFileEntryMetadata instanceof DLFileEntryMetadataImpl) {
2717                            return dlFileEntryMetadata;
2718                    }
2719    
2720                    DLFileEntryMetadataImpl dlFileEntryMetadataImpl = new DLFileEntryMetadataImpl();
2721    
2722                    dlFileEntryMetadataImpl.setNew(dlFileEntryMetadata.isNew());
2723                    dlFileEntryMetadataImpl.setPrimaryKey(dlFileEntryMetadata.getPrimaryKey());
2724    
2725                    dlFileEntryMetadataImpl.setUuid(dlFileEntryMetadata.getUuid());
2726                    dlFileEntryMetadataImpl.setFileEntryMetadataId(dlFileEntryMetadata.getFileEntryMetadataId());
2727                    dlFileEntryMetadataImpl.setDDMStorageId(dlFileEntryMetadata.getDDMStorageId());
2728                    dlFileEntryMetadataImpl.setDDMStructureId(dlFileEntryMetadata.getDDMStructureId());
2729                    dlFileEntryMetadataImpl.setFileEntryTypeId(dlFileEntryMetadata.getFileEntryTypeId());
2730                    dlFileEntryMetadataImpl.setFileEntryId(dlFileEntryMetadata.getFileEntryId());
2731                    dlFileEntryMetadataImpl.setFileVersionId(dlFileEntryMetadata.getFileVersionId());
2732    
2733                    return dlFileEntryMetadataImpl;
2734            }
2735    
2736            /**
2737             * Returns the document library file entry metadata with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2738             *
2739             * @param primaryKey the primary key of the document library file entry metadata
2740             * @return the document library file entry metadata
2741             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2742             */
2743            @Override
2744            public DLFileEntryMetadata findByPrimaryKey(Serializable primaryKey)
2745                    throws NoSuchFileEntryMetadataException {
2746                    DLFileEntryMetadata dlFileEntryMetadata = fetchByPrimaryKey(primaryKey);
2747    
2748                    if (dlFileEntryMetadata == null) {
2749                            if (_log.isWarnEnabled()) {
2750                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2751                            }
2752    
2753                            throw new NoSuchFileEntryMetadataException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2754                                    primaryKey);
2755                    }
2756    
2757                    return dlFileEntryMetadata;
2758            }
2759    
2760            /**
2761             * Returns the document library file entry metadata with the primary key or throws a {@link com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException} if it could not be found.
2762             *
2763             * @param fileEntryMetadataId the primary key of the document library file entry metadata
2764             * @return the document library file entry metadata
2765             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2766             */
2767            @Override
2768            public DLFileEntryMetadata findByPrimaryKey(long fileEntryMetadataId)
2769                    throws NoSuchFileEntryMetadataException {
2770                    return findByPrimaryKey((Serializable)fileEntryMetadataId);
2771            }
2772    
2773            /**
2774             * Returns the document library file entry metadata with the primary key or returns <code>null</code> if it could not be found.
2775             *
2776             * @param primaryKey the primary key of the document library file entry metadata
2777             * @return the document library file entry metadata, or <code>null</code> if a document library file entry metadata with the primary key could not be found
2778             */
2779            @Override
2780            public DLFileEntryMetadata fetchByPrimaryKey(Serializable primaryKey) {
2781                    DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)EntityCacheUtil.getResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2782                                    DLFileEntryMetadataImpl.class, primaryKey);
2783    
2784                    if (dlFileEntryMetadata == _nullDLFileEntryMetadata) {
2785                            return null;
2786                    }
2787    
2788                    if (dlFileEntryMetadata == null) {
2789                            Session session = null;
2790    
2791                            try {
2792                                    session = openSession();
2793    
2794                                    dlFileEntryMetadata = (DLFileEntryMetadata)session.get(DLFileEntryMetadataImpl.class,
2795                                                    primaryKey);
2796    
2797                                    if (dlFileEntryMetadata != null) {
2798                                            cacheResult(dlFileEntryMetadata);
2799                                    }
2800                                    else {
2801                                            EntityCacheUtil.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2802                                                    DLFileEntryMetadataImpl.class, primaryKey,
2803                                                    _nullDLFileEntryMetadata);
2804                                    }
2805                            }
2806                            catch (Exception e) {
2807                                    EntityCacheUtil.removeResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2808                                            DLFileEntryMetadataImpl.class, primaryKey);
2809    
2810                                    throw processException(e);
2811                            }
2812                            finally {
2813                                    closeSession(session);
2814                            }
2815                    }
2816    
2817                    return dlFileEntryMetadata;
2818            }
2819    
2820            /**
2821             * Returns the document library file entry metadata with the primary key or returns <code>null</code> if it could not be found.
2822             *
2823             * @param fileEntryMetadataId the primary key of the document library file entry metadata
2824             * @return the document library file entry metadata, or <code>null</code> if a document library file entry metadata with the primary key could not be found
2825             */
2826            @Override
2827            public DLFileEntryMetadata fetchByPrimaryKey(long fileEntryMetadataId) {
2828                    return fetchByPrimaryKey((Serializable)fileEntryMetadataId);
2829            }
2830    
2831            @Override
2832            public Map<Serializable, DLFileEntryMetadata> fetchByPrimaryKeys(
2833                    Set<Serializable> primaryKeys) {
2834                    if (primaryKeys.isEmpty()) {
2835                            return Collections.emptyMap();
2836                    }
2837    
2838                    Map<Serializable, DLFileEntryMetadata> map = new HashMap<Serializable, DLFileEntryMetadata>();
2839    
2840                    if (primaryKeys.size() == 1) {
2841                            Iterator<Serializable> iterator = primaryKeys.iterator();
2842    
2843                            Serializable primaryKey = iterator.next();
2844    
2845                            DLFileEntryMetadata dlFileEntryMetadata = fetchByPrimaryKey(primaryKey);
2846    
2847                            if (dlFileEntryMetadata != null) {
2848                                    map.put(primaryKey, dlFileEntryMetadata);
2849                            }
2850    
2851                            return map;
2852                    }
2853    
2854                    Set<Serializable> uncachedPrimaryKeys = null;
2855    
2856                    for (Serializable primaryKey : primaryKeys) {
2857                            DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)EntityCacheUtil.getResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2858                                            DLFileEntryMetadataImpl.class, primaryKey);
2859    
2860                            if (dlFileEntryMetadata == null) {
2861                                    if (uncachedPrimaryKeys == null) {
2862                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2863                                    }
2864    
2865                                    uncachedPrimaryKeys.add(primaryKey);
2866                            }
2867                            else {
2868                                    map.put(primaryKey, dlFileEntryMetadata);
2869                            }
2870                    }
2871    
2872                    if (uncachedPrimaryKeys == null) {
2873                            return map;
2874                    }
2875    
2876                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2877                                    1);
2878    
2879                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE_PKS_IN);
2880    
2881                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2882                            query.append(String.valueOf(primaryKey));
2883    
2884                            query.append(StringPool.COMMA);
2885                    }
2886    
2887                    query.setIndex(query.index() - 1);
2888    
2889                    query.append(StringPool.CLOSE_PARENTHESIS);
2890    
2891                    String sql = query.toString();
2892    
2893                    Session session = null;
2894    
2895                    try {
2896                            session = openSession();
2897    
2898                            Query q = session.createQuery(sql);
2899    
2900                            for (DLFileEntryMetadata dlFileEntryMetadata : (List<DLFileEntryMetadata>)q.list()) {
2901                                    map.put(dlFileEntryMetadata.getPrimaryKeyObj(),
2902                                            dlFileEntryMetadata);
2903    
2904                                    cacheResult(dlFileEntryMetadata);
2905    
2906                                    uncachedPrimaryKeys.remove(dlFileEntryMetadata.getPrimaryKeyObj());
2907                            }
2908    
2909                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2910                                    EntityCacheUtil.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2911                                            DLFileEntryMetadataImpl.class, primaryKey,
2912                                            _nullDLFileEntryMetadata);
2913                            }
2914                    }
2915                    catch (Exception e) {
2916                            throw processException(e);
2917                    }
2918                    finally {
2919                            closeSession(session);
2920                    }
2921    
2922                    return map;
2923            }
2924    
2925            /**
2926             * Returns all the document library file entry metadatas.
2927             *
2928             * @return the document library file entry metadatas
2929             */
2930            @Override
2931            public List<DLFileEntryMetadata> findAll() {
2932                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2933            }
2934    
2935            /**
2936             * Returns a range of all the document library file entry metadatas.
2937             *
2938             * <p>
2939             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
2940             * </p>
2941             *
2942             * @param start the lower bound of the range of document library file entry metadatas
2943             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
2944             * @return the range of document library file entry metadatas
2945             */
2946            @Override
2947            public List<DLFileEntryMetadata> findAll(int start, int end) {
2948                    return findAll(start, end, null);
2949            }
2950    
2951            /**
2952             * Returns an ordered range of all the document library file entry metadatas.
2953             *
2954             * <p>
2955             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataModelImpl}. 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.
2956             * </p>
2957             *
2958             * @param start the lower bound of the range of document library file entry metadatas
2959             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
2960             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2961             * @return the ordered range of document library file entry metadatas
2962             */
2963            @Override
2964            public List<DLFileEntryMetadata> findAll(int start, int end,
2965                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
2966                    boolean pagination = true;
2967                    FinderPath finderPath = null;
2968                    Object[] finderArgs = null;
2969    
2970                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2971                                    (orderByComparator == null)) {
2972                            pagination = false;
2973                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2974                            finderArgs = FINDER_ARGS_EMPTY;
2975                    }
2976                    else {
2977                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2978                            finderArgs = new Object[] { start, end, orderByComparator };
2979                    }
2980    
2981                    List<DLFileEntryMetadata> list = (List<DLFileEntryMetadata>)FinderCacheUtil.getResult(finderPath,
2982                                    finderArgs, this);
2983    
2984                    if (list == null) {
2985                            StringBundler query = null;
2986                            String sql = null;
2987    
2988                            if (orderByComparator != null) {
2989                                    query = new StringBundler(2 +
2990                                                    (orderByComparator.getOrderByFields().length * 3));
2991    
2992                                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA);
2993    
2994                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2995                                            orderByComparator);
2996    
2997                                    sql = query.toString();
2998                            }
2999                            else {
3000                                    sql = _SQL_SELECT_DLFILEENTRYMETADATA;
3001    
3002                                    if (pagination) {
3003                                            sql = sql.concat(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
3004                                    }
3005                            }
3006    
3007                            Session session = null;
3008    
3009                            try {
3010                                    session = openSession();
3011    
3012                                    Query q = session.createQuery(sql);
3013    
3014                                    if (!pagination) {
3015                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
3016                                                            getDialect(), start, end, false);
3017    
3018                                            Collections.sort(list);
3019    
3020                                            list = Collections.unmodifiableList(list);
3021                                    }
3022                                    else {
3023                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
3024                                                            getDialect(), start, end);
3025                                    }
3026    
3027                                    cacheResult(list);
3028    
3029                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3030                            }
3031                            catch (Exception e) {
3032                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3033    
3034                                    throw processException(e);
3035                            }
3036                            finally {
3037                                    closeSession(session);
3038                            }
3039                    }
3040    
3041                    return list;
3042            }
3043    
3044            /**
3045             * Removes all the document library file entry metadatas from the database.
3046             *
3047             */
3048            @Override
3049            public void removeAll() {
3050                    for (DLFileEntryMetadata dlFileEntryMetadata : findAll()) {
3051                            remove(dlFileEntryMetadata);
3052                    }
3053            }
3054    
3055            /**
3056             * Returns the number of document library file entry metadatas.
3057             *
3058             * @return the number of document library file entry metadatas
3059             */
3060            @Override
3061            public int countAll() {
3062                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3063                                    FINDER_ARGS_EMPTY, this);
3064    
3065                    if (count == null) {
3066                            Session session = null;
3067    
3068                            try {
3069                                    session = openSession();
3070    
3071                                    Query q = session.createQuery(_SQL_COUNT_DLFILEENTRYMETADATA);
3072    
3073                                    count = (Long)q.uniqueResult();
3074    
3075                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3076                                            FINDER_ARGS_EMPTY, count);
3077                            }
3078                            catch (Exception e) {
3079                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3080                                            FINDER_ARGS_EMPTY);
3081    
3082                                    throw processException(e);
3083                            }
3084                            finally {
3085                                    closeSession(session);
3086                            }
3087                    }
3088    
3089                    return count.intValue();
3090            }
3091    
3092            @Override
3093            protected Set<String> getBadColumnNames() {
3094                    return _badColumnNames;
3095            }
3096    
3097            /**
3098             * Initializes the document library file entry metadata persistence.
3099             */
3100            public void afterPropertiesSet() {
3101            }
3102    
3103            public void destroy() {
3104                    EntityCacheUtil.removeCache(DLFileEntryMetadataImpl.class.getName());
3105                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3106                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3107                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3108            }
3109    
3110            private static final String _SQL_SELECT_DLFILEENTRYMETADATA = "SELECT dlFileEntryMetadata FROM DLFileEntryMetadata dlFileEntryMetadata";
3111            private static final String _SQL_SELECT_DLFILEENTRYMETADATA_WHERE_PKS_IN = "SELECT dlFileEntryMetadata FROM DLFileEntryMetadata dlFileEntryMetadata WHERE fileEntryMetadataId IN (";
3112            private static final String _SQL_SELECT_DLFILEENTRYMETADATA_WHERE = "SELECT dlFileEntryMetadata FROM DLFileEntryMetadata dlFileEntryMetadata WHERE ";
3113            private static final String _SQL_COUNT_DLFILEENTRYMETADATA = "SELECT COUNT(dlFileEntryMetadata) FROM DLFileEntryMetadata dlFileEntryMetadata";
3114            private static final String _SQL_COUNT_DLFILEENTRYMETADATA_WHERE = "SELECT COUNT(dlFileEntryMetadata) FROM DLFileEntryMetadata dlFileEntryMetadata WHERE ";
3115            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileEntryMetadata.";
3116            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileEntryMetadata exists with the primary key ";
3117            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileEntryMetadata exists with the key {";
3118            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3119            private static final Log _log = LogFactoryUtil.getLog(DLFileEntryMetadataPersistenceImpl.class);
3120            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3121                                    "uuid"
3122                            });
3123            private static final DLFileEntryMetadata _nullDLFileEntryMetadata = new DLFileEntryMetadataImpl() {
3124                            @Override
3125                            public Object clone() {
3126                                    return this;
3127                            }
3128    
3129                            @Override
3130                            public CacheModel<DLFileEntryMetadata> toCacheModel() {
3131                                    return _nullDLFileEntryMetadataCacheModel;
3132                            }
3133                    };
3134    
3135            private static final CacheModel<DLFileEntryMetadata> _nullDLFileEntryMetadataCacheModel =
3136                    new CacheModel<DLFileEntryMetadata>() {
3137                            @Override
3138                            public DLFileEntryMetadata toEntityModel() {
3139                                    return _nullDLFileEntryMetadata;
3140                            }
3141                    };
3142    }