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