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            /**
2371             * Caches the document library file entry metadata in the entity cache if it is enabled.
2372             *
2373             * @param dlFileEntryMetadata the document library file entry metadata
2374             */
2375            @Override
2376            public void cacheResult(DLFileEntryMetadata dlFileEntryMetadata) {
2377                    EntityCacheUtil.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2378                            DLFileEntryMetadataImpl.class, dlFileEntryMetadata.getPrimaryKey(),
2379                            dlFileEntryMetadata);
2380    
2381                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_D_F,
2382                            new Object[] {
2383                                    dlFileEntryMetadata.getDDMStructureId(),
2384                                    dlFileEntryMetadata.getFileVersionId()
2385                            }, dlFileEntryMetadata);
2386    
2387                    dlFileEntryMetadata.resetOriginalValues();
2388            }
2389    
2390            /**
2391             * Caches the document library file entry metadatas in the entity cache if it is enabled.
2392             *
2393             * @param dlFileEntryMetadatas the document library file entry metadatas
2394             */
2395            @Override
2396            public void cacheResult(List<DLFileEntryMetadata> dlFileEntryMetadatas) {
2397                    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
2398                            if (EntityCacheUtil.getResult(
2399                                                    DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2400                                                    DLFileEntryMetadataImpl.class,
2401                                                    dlFileEntryMetadata.getPrimaryKey()) == null) {
2402                                    cacheResult(dlFileEntryMetadata);
2403                            }
2404                            else {
2405                                    dlFileEntryMetadata.resetOriginalValues();
2406                            }
2407                    }
2408            }
2409    
2410            /**
2411             * Clears the cache for all document library file entry metadatas.
2412             *
2413             * <p>
2414             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2415             * </p>
2416             */
2417            @Override
2418            public void clearCache() {
2419                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2420                            CacheRegistryUtil.clear(DLFileEntryMetadataImpl.class.getName());
2421                    }
2422    
2423                    EntityCacheUtil.clearCache(DLFileEntryMetadataImpl.class.getName());
2424    
2425                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2426                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2427                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2428            }
2429    
2430            /**
2431             * Clears the cache for the document library file entry metadata.
2432             *
2433             * <p>
2434             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2435             * </p>
2436             */
2437            @Override
2438            public void clearCache(DLFileEntryMetadata dlFileEntryMetadata) {
2439                    EntityCacheUtil.removeResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2440                            DLFileEntryMetadataImpl.class, dlFileEntryMetadata.getPrimaryKey());
2441    
2442                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2443                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2444    
2445                    clearUniqueFindersCache(dlFileEntryMetadata);
2446            }
2447    
2448            @Override
2449            public void clearCache(List<DLFileEntryMetadata> dlFileEntryMetadatas) {
2450                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2451                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2452    
2453                    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
2454                            EntityCacheUtil.removeResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2455                                    DLFileEntryMetadataImpl.class,
2456                                    dlFileEntryMetadata.getPrimaryKey());
2457    
2458                            clearUniqueFindersCache(dlFileEntryMetadata);
2459                    }
2460            }
2461    
2462            protected void cacheUniqueFindersCache(
2463                    DLFileEntryMetadata dlFileEntryMetadata) {
2464                    if (dlFileEntryMetadata.isNew()) {
2465                            Object[] args = new Object[] {
2466                                            dlFileEntryMetadata.getDDMStructureId(),
2467                                            dlFileEntryMetadata.getFileVersionId()
2468                                    };
2469    
2470                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_D_F, args,
2471                                    Long.valueOf(1));
2472                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_D_F, args,
2473                                    dlFileEntryMetadata);
2474                    }
2475                    else {
2476                            DLFileEntryMetadataModelImpl dlFileEntryMetadataModelImpl = (DLFileEntryMetadataModelImpl)dlFileEntryMetadata;
2477    
2478                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2479                                            FINDER_PATH_FETCH_BY_D_F.getColumnBitmask()) != 0) {
2480                                    Object[] args = new Object[] {
2481                                                    dlFileEntryMetadata.getDDMStructureId(),
2482                                                    dlFileEntryMetadata.getFileVersionId()
2483                                            };
2484    
2485                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_D_F, args,
2486                                            Long.valueOf(1));
2487                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_D_F, args,
2488                                            dlFileEntryMetadata);
2489                            }
2490                    }
2491            }
2492    
2493            protected void clearUniqueFindersCache(
2494                    DLFileEntryMetadata dlFileEntryMetadata) {
2495                    DLFileEntryMetadataModelImpl dlFileEntryMetadataModelImpl = (DLFileEntryMetadataModelImpl)dlFileEntryMetadata;
2496    
2497                    Object[] args = new Object[] {
2498                                    dlFileEntryMetadata.getDDMStructureId(),
2499                                    dlFileEntryMetadata.getFileVersionId()
2500                            };
2501    
2502                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_D_F, args);
2503                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_D_F, args);
2504    
2505                    if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2506                                    FINDER_PATH_FETCH_BY_D_F.getColumnBitmask()) != 0) {
2507                            args = new Object[] {
2508                                            dlFileEntryMetadataModelImpl.getOriginalDDMStructureId(),
2509                                            dlFileEntryMetadataModelImpl.getOriginalFileVersionId()
2510                                    };
2511    
2512                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_D_F, args);
2513                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_D_F, args);
2514                    }
2515            }
2516    
2517            /**
2518             * Creates a new document library file entry metadata with the primary key. Does not add the document library file entry metadata to the database.
2519             *
2520             * @param fileEntryMetadataId the primary key for the new document library file entry metadata
2521             * @return the new document library file entry metadata
2522             */
2523            @Override
2524            public DLFileEntryMetadata create(long fileEntryMetadataId) {
2525                    DLFileEntryMetadata dlFileEntryMetadata = new DLFileEntryMetadataImpl();
2526    
2527                    dlFileEntryMetadata.setNew(true);
2528                    dlFileEntryMetadata.setPrimaryKey(fileEntryMetadataId);
2529    
2530                    String uuid = PortalUUIDUtil.generate();
2531    
2532                    dlFileEntryMetadata.setUuid(uuid);
2533    
2534                    return dlFileEntryMetadata;
2535            }
2536    
2537            /**
2538             * Removes the document library file entry metadata with the primary key from the database. Also notifies the appropriate model listeners.
2539             *
2540             * @param fileEntryMetadataId the primary key of the document library file entry metadata
2541             * @return the document library file entry metadata that was removed
2542             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2543             * @throws SystemException if a system exception occurred
2544             */
2545            @Override
2546            public DLFileEntryMetadata remove(long fileEntryMetadataId)
2547                    throws NoSuchFileEntryMetadataException, SystemException {
2548                    return remove((Serializable)fileEntryMetadataId);
2549            }
2550    
2551            /**
2552             * Removes the document library file entry metadata with the primary key from the database. Also notifies the appropriate model listeners.
2553             *
2554             * @param primaryKey the primary key of the document library file entry metadata
2555             * @return the document library file entry metadata that was removed
2556             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2557             * @throws SystemException if a system exception occurred
2558             */
2559            @Override
2560            public DLFileEntryMetadata remove(Serializable primaryKey)
2561                    throws NoSuchFileEntryMetadataException, SystemException {
2562                    Session session = null;
2563    
2564                    try {
2565                            session = openSession();
2566    
2567                            DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)session.get(DLFileEntryMetadataImpl.class,
2568                                            primaryKey);
2569    
2570                            if (dlFileEntryMetadata == null) {
2571                                    if (_log.isWarnEnabled()) {
2572                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2573                                    }
2574    
2575                                    throw new NoSuchFileEntryMetadataException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2576                                            primaryKey);
2577                            }
2578    
2579                            return remove(dlFileEntryMetadata);
2580                    }
2581                    catch (NoSuchFileEntryMetadataException nsee) {
2582                            throw nsee;
2583                    }
2584                    catch (Exception e) {
2585                            throw processException(e);
2586                    }
2587                    finally {
2588                            closeSession(session);
2589                    }
2590            }
2591    
2592            @Override
2593            protected DLFileEntryMetadata removeImpl(
2594                    DLFileEntryMetadata dlFileEntryMetadata) throws SystemException {
2595                    dlFileEntryMetadata = toUnwrappedModel(dlFileEntryMetadata);
2596    
2597                    Session session = null;
2598    
2599                    try {
2600                            session = openSession();
2601    
2602                            if (!session.contains(dlFileEntryMetadata)) {
2603                                    dlFileEntryMetadata = (DLFileEntryMetadata)session.get(DLFileEntryMetadataImpl.class,
2604                                                    dlFileEntryMetadata.getPrimaryKeyObj());
2605                            }
2606    
2607                            if (dlFileEntryMetadata != null) {
2608                                    session.delete(dlFileEntryMetadata);
2609                            }
2610                    }
2611                    catch (Exception e) {
2612                            throw processException(e);
2613                    }
2614                    finally {
2615                            closeSession(session);
2616                    }
2617    
2618                    if (dlFileEntryMetadata != null) {
2619                            clearCache(dlFileEntryMetadata);
2620                    }
2621    
2622                    return dlFileEntryMetadata;
2623            }
2624    
2625            @Override
2626            public DLFileEntryMetadata updateImpl(
2627                    com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata dlFileEntryMetadata)
2628                    throws SystemException {
2629                    dlFileEntryMetadata = toUnwrappedModel(dlFileEntryMetadata);
2630    
2631                    boolean isNew = dlFileEntryMetadata.isNew();
2632    
2633                    DLFileEntryMetadataModelImpl dlFileEntryMetadataModelImpl = (DLFileEntryMetadataModelImpl)dlFileEntryMetadata;
2634    
2635                    if (Validator.isNull(dlFileEntryMetadata.getUuid())) {
2636                            String uuid = PortalUUIDUtil.generate();
2637    
2638                            dlFileEntryMetadata.setUuid(uuid);
2639                    }
2640    
2641                    Session session = null;
2642    
2643                    try {
2644                            session = openSession();
2645    
2646                            if (dlFileEntryMetadata.isNew()) {
2647                                    session.save(dlFileEntryMetadata);
2648    
2649                                    dlFileEntryMetadata.setNew(false);
2650                            }
2651                            else {
2652                                    session.merge(dlFileEntryMetadata);
2653                            }
2654                    }
2655                    catch (Exception e) {
2656                            throw processException(e);
2657                    }
2658                    finally {
2659                            closeSession(session);
2660                    }
2661    
2662                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2663    
2664                    if (isNew || !DLFileEntryMetadataModelImpl.COLUMN_BITMASK_ENABLED) {
2665                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2666                    }
2667    
2668                    else {
2669                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2670                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2671                                    Object[] args = new Object[] {
2672                                                    dlFileEntryMetadataModelImpl.getOriginalUuid()
2673                                            };
2674    
2675                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2676                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2677                                            args);
2678    
2679                                    args = new Object[] { dlFileEntryMetadataModelImpl.getUuid() };
2680    
2681                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2682                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2683                                            args);
2684                            }
2685    
2686                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2687                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYTYPEID.getColumnBitmask()) != 0) {
2688                                    Object[] args = new Object[] {
2689                                                    dlFileEntryMetadataModelImpl.getOriginalFileEntryTypeId()
2690                                            };
2691    
2692                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYTYPEID,
2693                                            args);
2694                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYTYPEID,
2695                                            args);
2696    
2697                                    args = new Object[] {
2698                                                    dlFileEntryMetadataModelImpl.getFileEntryTypeId()
2699                                            };
2700    
2701                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYTYPEID,
2702                                            args);
2703                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYTYPEID,
2704                                            args);
2705                            }
2706    
2707                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2708                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
2709                                    Object[] args = new Object[] {
2710                                                    dlFileEntryMetadataModelImpl.getOriginalFileEntryId()
2711                                            };
2712    
2713                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
2714                                            args);
2715                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
2716                                            args);
2717    
2718                                    args = new Object[] {
2719                                                    dlFileEntryMetadataModelImpl.getFileEntryId()
2720                                            };
2721    
2722                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID,
2723                                            args);
2724                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
2725                                            args);
2726                            }
2727    
2728                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2729                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID.getColumnBitmask()) != 0) {
2730                                    Object[] args = new Object[] {
2731                                                    dlFileEntryMetadataModelImpl.getOriginalFileVersionId()
2732                                            };
2733    
2734                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEVERSIONID,
2735                                            args);
2736                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID,
2737                                            args);
2738    
2739                                    args = new Object[] {
2740                                                    dlFileEntryMetadataModelImpl.getFileVersionId()
2741                                            };
2742    
2743                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FILEVERSIONID,
2744                                            args);
2745                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID,
2746                                            args);
2747                            }
2748                    }
2749    
2750                    EntityCacheUtil.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2751                            DLFileEntryMetadataImpl.class, dlFileEntryMetadata.getPrimaryKey(),
2752                            dlFileEntryMetadata);
2753    
2754                    clearUniqueFindersCache(dlFileEntryMetadata);
2755                    cacheUniqueFindersCache(dlFileEntryMetadata);
2756    
2757                    return dlFileEntryMetadata;
2758            }
2759    
2760            protected DLFileEntryMetadata toUnwrappedModel(
2761                    DLFileEntryMetadata dlFileEntryMetadata) {
2762                    if (dlFileEntryMetadata instanceof DLFileEntryMetadataImpl) {
2763                            return dlFileEntryMetadata;
2764                    }
2765    
2766                    DLFileEntryMetadataImpl dlFileEntryMetadataImpl = new DLFileEntryMetadataImpl();
2767    
2768                    dlFileEntryMetadataImpl.setNew(dlFileEntryMetadata.isNew());
2769                    dlFileEntryMetadataImpl.setPrimaryKey(dlFileEntryMetadata.getPrimaryKey());
2770    
2771                    dlFileEntryMetadataImpl.setUuid(dlFileEntryMetadata.getUuid());
2772                    dlFileEntryMetadataImpl.setFileEntryMetadataId(dlFileEntryMetadata.getFileEntryMetadataId());
2773                    dlFileEntryMetadataImpl.setDDMStorageId(dlFileEntryMetadata.getDDMStorageId());
2774                    dlFileEntryMetadataImpl.setDDMStructureId(dlFileEntryMetadata.getDDMStructureId());
2775                    dlFileEntryMetadataImpl.setFileEntryTypeId(dlFileEntryMetadata.getFileEntryTypeId());
2776                    dlFileEntryMetadataImpl.setFileEntryId(dlFileEntryMetadata.getFileEntryId());
2777                    dlFileEntryMetadataImpl.setFileVersionId(dlFileEntryMetadata.getFileVersionId());
2778    
2779                    return dlFileEntryMetadataImpl;
2780            }
2781    
2782            /**
2783             * 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.
2784             *
2785             * @param primaryKey the primary key of the document library file entry metadata
2786             * @return the document library file entry metadata
2787             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2788             * @throws SystemException if a system exception occurred
2789             */
2790            @Override
2791            public DLFileEntryMetadata findByPrimaryKey(Serializable primaryKey)
2792                    throws NoSuchFileEntryMetadataException, SystemException {
2793                    DLFileEntryMetadata dlFileEntryMetadata = fetchByPrimaryKey(primaryKey);
2794    
2795                    if (dlFileEntryMetadata == null) {
2796                            if (_log.isWarnEnabled()) {
2797                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2798                            }
2799    
2800                            throw new NoSuchFileEntryMetadataException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2801                                    primaryKey);
2802                    }
2803    
2804                    return dlFileEntryMetadata;
2805            }
2806    
2807            /**
2808             * 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.
2809             *
2810             * @param fileEntryMetadataId the primary key of the document library file entry metadata
2811             * @return the document library file entry metadata
2812             * @throws com.liferay.portlet.documentlibrary.NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2813             * @throws SystemException if a system exception occurred
2814             */
2815            @Override
2816            public DLFileEntryMetadata findByPrimaryKey(long fileEntryMetadataId)
2817                    throws NoSuchFileEntryMetadataException, SystemException {
2818                    return findByPrimaryKey((Serializable)fileEntryMetadataId);
2819            }
2820    
2821            /**
2822             * Returns the document library file entry metadata with the primary key or returns <code>null</code> if it could not be found.
2823             *
2824             * @param primaryKey the primary key of the document library file entry metadata
2825             * @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
2826             * @throws SystemException if a system exception occurred
2827             */
2828            @Override
2829            public DLFileEntryMetadata fetchByPrimaryKey(Serializable primaryKey)
2830                    throws SystemException {
2831                    DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)EntityCacheUtil.getResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2832                                    DLFileEntryMetadataImpl.class, primaryKey);
2833    
2834                    if (dlFileEntryMetadata == _nullDLFileEntryMetadata) {
2835                            return null;
2836                    }
2837    
2838                    if (dlFileEntryMetadata == null) {
2839                            Session session = null;
2840    
2841                            try {
2842                                    session = openSession();
2843    
2844                                    dlFileEntryMetadata = (DLFileEntryMetadata)session.get(DLFileEntryMetadataImpl.class,
2845                                                    primaryKey);
2846    
2847                                    if (dlFileEntryMetadata != null) {
2848                                            cacheResult(dlFileEntryMetadata);
2849                                    }
2850                                    else {
2851                                            EntityCacheUtil.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2852                                                    DLFileEntryMetadataImpl.class, primaryKey,
2853                                                    _nullDLFileEntryMetadata);
2854                                    }
2855                            }
2856                            catch (Exception e) {
2857                                    EntityCacheUtil.removeResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2858                                            DLFileEntryMetadataImpl.class, primaryKey);
2859    
2860                                    throw processException(e);
2861                            }
2862                            finally {
2863                                    closeSession(session);
2864                            }
2865                    }
2866    
2867                    return dlFileEntryMetadata;
2868            }
2869    
2870            /**
2871             * Returns the document library file entry metadata with the primary key or returns <code>null</code> if it could not be found.
2872             *
2873             * @param fileEntryMetadataId the primary key of the document library file entry metadata
2874             * @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
2875             * @throws SystemException if a system exception occurred
2876             */
2877            @Override
2878            public DLFileEntryMetadata fetchByPrimaryKey(long fileEntryMetadataId)
2879                    throws SystemException {
2880                    return fetchByPrimaryKey((Serializable)fileEntryMetadataId);
2881            }
2882    
2883            /**
2884             * Returns all the document library file entry metadatas.
2885             *
2886             * @return the document library file entry metadatas
2887             * @throws SystemException if a system exception occurred
2888             */
2889            @Override
2890            public List<DLFileEntryMetadata> findAll() throws SystemException {
2891                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2892            }
2893    
2894            /**
2895             * Returns a range of all the document library file entry metadatas.
2896             *
2897             * <p>
2898             * 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.
2899             * </p>
2900             *
2901             * @param start the lower bound of the range of document library file entry metadatas
2902             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
2903             * @return the range of document library file entry metadatas
2904             * @throws SystemException if a system exception occurred
2905             */
2906            @Override
2907            public List<DLFileEntryMetadata> findAll(int start, int end)
2908                    throws SystemException {
2909                    return findAll(start, end, null);
2910            }
2911    
2912            /**
2913             * Returns an ordered range of all the document library file entry metadatas.
2914             *
2915             * <p>
2916             * 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.
2917             * </p>
2918             *
2919             * @param start the lower bound of the range of document library file entry metadatas
2920             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
2921             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2922             * @return the ordered range of document library file entry metadatas
2923             * @throws SystemException if a system exception occurred
2924             */
2925            @Override
2926            public List<DLFileEntryMetadata> findAll(int start, int end,
2927                    OrderByComparator orderByComparator) throws SystemException {
2928                    boolean pagination = true;
2929                    FinderPath finderPath = null;
2930                    Object[] finderArgs = null;
2931    
2932                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2933                                    (orderByComparator == null)) {
2934                            pagination = false;
2935                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2936                            finderArgs = FINDER_ARGS_EMPTY;
2937                    }
2938                    else {
2939                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2940                            finderArgs = new Object[] { start, end, orderByComparator };
2941                    }
2942    
2943                    List<DLFileEntryMetadata> list = (List<DLFileEntryMetadata>)FinderCacheUtil.getResult(finderPath,
2944                                    finderArgs, this);
2945    
2946                    if (list == null) {
2947                            StringBundler query = null;
2948                            String sql = null;
2949    
2950                            if (orderByComparator != null) {
2951                                    query = new StringBundler(2 +
2952                                                    (orderByComparator.getOrderByFields().length * 3));
2953    
2954                                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA);
2955    
2956                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2957                                            orderByComparator);
2958    
2959                                    sql = query.toString();
2960                            }
2961                            else {
2962                                    sql = _SQL_SELECT_DLFILEENTRYMETADATA;
2963    
2964                                    if (pagination) {
2965                                            sql = sql.concat(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
2966                                    }
2967                            }
2968    
2969                            Session session = null;
2970    
2971                            try {
2972                                    session = openSession();
2973    
2974                                    Query q = session.createQuery(sql);
2975    
2976                                    if (!pagination) {
2977                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
2978                                                            getDialect(), start, end, false);
2979    
2980                                            Collections.sort(list);
2981    
2982                                            list = new UnmodifiableList<DLFileEntryMetadata>(list);
2983                                    }
2984                                    else {
2985                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
2986                                                            getDialect(), start, end);
2987                                    }
2988    
2989                                    cacheResult(list);
2990    
2991                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2992                            }
2993                            catch (Exception e) {
2994                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2995    
2996                                    throw processException(e);
2997                            }
2998                            finally {
2999                                    closeSession(session);
3000                            }
3001                    }
3002    
3003                    return list;
3004            }
3005    
3006            /**
3007             * Removes all the document library file entry metadatas from the database.
3008             *
3009             * @throws SystemException if a system exception occurred
3010             */
3011            @Override
3012            public void removeAll() throws SystemException {
3013                    for (DLFileEntryMetadata dlFileEntryMetadata : findAll()) {
3014                            remove(dlFileEntryMetadata);
3015                    }
3016            }
3017    
3018            /**
3019             * Returns the number of document library file entry metadatas.
3020             *
3021             * @return the number of document library file entry metadatas
3022             * @throws SystemException if a system exception occurred
3023             */
3024            @Override
3025            public int countAll() throws SystemException {
3026                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3027                                    FINDER_ARGS_EMPTY, this);
3028    
3029                    if (count == null) {
3030                            Session session = null;
3031    
3032                            try {
3033                                    session = openSession();
3034    
3035                                    Query q = session.createQuery(_SQL_COUNT_DLFILEENTRYMETADATA);
3036    
3037                                    count = (Long)q.uniqueResult();
3038    
3039                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3040                                            FINDER_ARGS_EMPTY, count);
3041                            }
3042                            catch (Exception e) {
3043                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3044                                            FINDER_ARGS_EMPTY);
3045    
3046                                    throw processException(e);
3047                            }
3048                            finally {
3049                                    closeSession(session);
3050                            }
3051                    }
3052    
3053                    return count.intValue();
3054            }
3055    
3056            @Override
3057            protected Set<String> getBadColumnNames() {
3058                    return _badColumnNames;
3059            }
3060    
3061            /**
3062             * Initializes the document library file entry metadata persistence.
3063             */
3064            public void afterPropertiesSet() {
3065                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3066                                            com.liferay.portal.util.PropsUtil.get(
3067                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata")));
3068    
3069                    if (listenerClassNames.length > 0) {
3070                            try {
3071                                    List<ModelListener<DLFileEntryMetadata>> listenersList = new ArrayList<ModelListener<DLFileEntryMetadata>>();
3072    
3073                                    for (String listenerClassName : listenerClassNames) {
3074                                            listenersList.add((ModelListener<DLFileEntryMetadata>)InstanceFactory.newInstance(
3075                                                            getClassLoader(), listenerClassName));
3076                                    }
3077    
3078                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3079                            }
3080                            catch (Exception e) {
3081                                    _log.error(e);
3082                            }
3083                    }
3084            }
3085    
3086            public void destroy() {
3087                    EntityCacheUtil.removeCache(DLFileEntryMetadataImpl.class.getName());
3088                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3089                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3090                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3091            }
3092    
3093            private static final String _SQL_SELECT_DLFILEENTRYMETADATA = "SELECT dlFileEntryMetadata FROM DLFileEntryMetadata dlFileEntryMetadata";
3094            private static final String _SQL_SELECT_DLFILEENTRYMETADATA_WHERE = "SELECT dlFileEntryMetadata FROM DLFileEntryMetadata dlFileEntryMetadata WHERE ";
3095            private static final String _SQL_COUNT_DLFILEENTRYMETADATA = "SELECT COUNT(dlFileEntryMetadata) FROM DLFileEntryMetadata dlFileEntryMetadata";
3096            private static final String _SQL_COUNT_DLFILEENTRYMETADATA_WHERE = "SELECT COUNT(dlFileEntryMetadata) FROM DLFileEntryMetadata dlFileEntryMetadata WHERE ";
3097            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileEntryMetadata.";
3098            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileEntryMetadata exists with the primary key ";
3099            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileEntryMetadata exists with the key {";
3100            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3101            private static Log _log = LogFactoryUtil.getLog(DLFileEntryMetadataPersistenceImpl.class);
3102            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3103                                    "uuid"
3104                            });
3105            private static DLFileEntryMetadata _nullDLFileEntryMetadata = new DLFileEntryMetadataImpl() {
3106                            @Override
3107                            public Object clone() {
3108                                    return this;
3109                            }
3110    
3111                            @Override
3112                            public CacheModel<DLFileEntryMetadata> toCacheModel() {
3113                                    return _nullDLFileEntryMetadataCacheModel;
3114                            }
3115                    };
3116    
3117            private static CacheModel<DLFileEntryMetadata> _nullDLFileEntryMetadataCacheModel =
3118                    new CacheModel<DLFileEntryMetadata>() {
3119                            @Override
3120                            public DLFileEntryMetadata toEntityModel() {
3121                                    return _nullDLFileEntryMetadata;
3122                            }
3123                    };
3124    }