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