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