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