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