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