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_UUID_C = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
641                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
642                            DLFileEntryMetadataImpl.class,
643                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
644                            new String[] {
645                                    String.class.getName(), Long.class.getName(),
646                                    
647                            Integer.class.getName(), Integer.class.getName(),
648                                    OrderByComparator.class.getName()
649                            });
650            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
651                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
652                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
653                            DLFileEntryMetadataImpl.class,
654                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
655                            new String[] { String.class.getName(), Long.class.getName() },
656                            DLFileEntryMetadataModelImpl.UUID_COLUMN_BITMASK |
657                            DLFileEntryMetadataModelImpl.COMPANYID_COLUMN_BITMASK);
658            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
659                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
660                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
661                            new String[] { String.class.getName(), Long.class.getName() });
662    
663            /**
664             * Returns all the document library file entry metadatas where uuid = &#63; and companyId = &#63;.
665             *
666             * @param uuid the uuid
667             * @param companyId the company ID
668             * @return the matching document library file entry metadatas
669             */
670            @Override
671            public List<DLFileEntryMetadata> findByUuid_C(String uuid, long companyId) {
672                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
673                            QueryUtil.ALL_POS, null);
674            }
675    
676            /**
677             * Returns a range of all the document library file entry metadatas where uuid = &#63; and companyId = &#63;.
678             *
679             * <p>
680             * 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.
681             * </p>
682             *
683             * @param uuid the uuid
684             * @param companyId the company ID
685             * @param start the lower bound of the range of document library file entry metadatas
686             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
687             * @return the range of matching document library file entry metadatas
688             */
689            @Override
690            public List<DLFileEntryMetadata> findByUuid_C(String uuid, long companyId,
691                    int start, int end) {
692                    return findByUuid_C(uuid, companyId, start, end, null);
693            }
694    
695            /**
696             * Returns an ordered range of all the document library file entry metadatas where uuid = &#63; and companyId = &#63;.
697             *
698             * <p>
699             * 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.
700             * </p>
701             *
702             * @param uuid the uuid
703             * @param companyId the company ID
704             * @param start the lower bound of the range of document library file entry metadatas
705             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
706             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
707             * @return the ordered range of matching document library file entry metadatas
708             */
709            @Override
710            public List<DLFileEntryMetadata> findByUuid_C(String uuid, long companyId,
711                    int start, int end,
712                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
713                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
714            }
715    
716            /**
717             * Returns an ordered range of all the document library file entry metadatas where uuid = &#63; and companyId = &#63;.
718             *
719             * <p>
720             * 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.
721             * </p>
722             *
723             * @param uuid the uuid
724             * @param companyId the company ID
725             * @param start the lower bound of the range of document library file entry metadatas
726             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
727             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
728             * @param retrieveFromCache whether to retrieve from the finder cache
729             * @return the ordered range of matching document library file entry metadatas
730             */
731            @Override
732            public List<DLFileEntryMetadata> findByUuid_C(String uuid, long companyId,
733                    int start, int end,
734                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
735                    boolean retrieveFromCache) {
736                    boolean pagination = true;
737                    FinderPath finderPath = null;
738                    Object[] finderArgs = null;
739    
740                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
741                                    (orderByComparator == null)) {
742                            pagination = false;
743                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
744                            finderArgs = new Object[] { uuid, companyId };
745                    }
746                    else {
747                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
748                            finderArgs = new Object[] {
749                                            uuid, companyId,
750                                            
751                                            start, end, orderByComparator
752                                    };
753                    }
754    
755                    List<DLFileEntryMetadata> list = null;
756    
757                    if (retrieveFromCache) {
758                            list = (List<DLFileEntryMetadata>)finderCache.getResult(finderPath,
759                                            finderArgs, this);
760    
761                            if ((list != null) && !list.isEmpty()) {
762                                    for (DLFileEntryMetadata dlFileEntryMetadata : list) {
763                                            if (!Validator.equals(uuid, dlFileEntryMetadata.getUuid()) ||
764                                                            (companyId != dlFileEntryMetadata.getCompanyId())) {
765                                                    list = null;
766    
767                                                    break;
768                                            }
769                                    }
770                            }
771                    }
772    
773                    if (list == null) {
774                            StringBundler query = null;
775    
776                            if (orderByComparator != null) {
777                                    query = new StringBundler(4 +
778                                                    (orderByComparator.getOrderByFields().length * 3));
779                            }
780                            else {
781                                    query = new StringBundler(4);
782                            }
783    
784                            query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
785    
786                            boolean bindUuid = false;
787    
788                            if (uuid == null) {
789                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
790                            }
791                            else if (uuid.equals(StringPool.BLANK)) {
792                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
793                            }
794                            else {
795                                    bindUuid = true;
796    
797                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
798                            }
799    
800                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
801    
802                            if (orderByComparator != null) {
803                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
804                                            orderByComparator);
805                            }
806                            else
807                             if (pagination) {
808                                    query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
809                            }
810    
811                            String sql = query.toString();
812    
813                            Session session = null;
814    
815                            try {
816                                    session = openSession();
817    
818                                    Query q = session.createQuery(sql);
819    
820                                    QueryPos qPos = QueryPos.getInstance(q);
821    
822                                    if (bindUuid) {
823                                            qPos.add(uuid);
824                                    }
825    
826                                    qPos.add(companyId);
827    
828                                    if (!pagination) {
829                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
830                                                            getDialect(), start, end, false);
831    
832                                            Collections.sort(list);
833    
834                                            list = Collections.unmodifiableList(list);
835                                    }
836                                    else {
837                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
838                                                            getDialect(), start, end);
839                                    }
840    
841                                    cacheResult(list);
842    
843                                    finderCache.putResult(finderPath, finderArgs, list);
844                            }
845                            catch (Exception e) {
846                                    finderCache.removeResult(finderPath, finderArgs);
847    
848                                    throw processException(e);
849                            }
850                            finally {
851                                    closeSession(session);
852                            }
853                    }
854    
855                    return list;
856            }
857    
858            /**
859             * Returns the first document library file entry metadata in the ordered set where uuid = &#63; and companyId = &#63;.
860             *
861             * @param uuid the uuid
862             * @param companyId the company ID
863             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
864             * @return the first matching document library file entry metadata
865             * @throws NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
866             */
867            @Override
868            public DLFileEntryMetadata findByUuid_C_First(String uuid, long companyId,
869                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
870                    throws NoSuchFileEntryMetadataException {
871                    DLFileEntryMetadata dlFileEntryMetadata = fetchByUuid_C_First(uuid,
872                                    companyId, orderByComparator);
873    
874                    if (dlFileEntryMetadata != null) {
875                            return dlFileEntryMetadata;
876                    }
877    
878                    StringBundler msg = new StringBundler(6);
879    
880                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
881    
882                    msg.append("uuid=");
883                    msg.append(uuid);
884    
885                    msg.append(", companyId=");
886                    msg.append(companyId);
887    
888                    msg.append(StringPool.CLOSE_CURLY_BRACE);
889    
890                    throw new NoSuchFileEntryMetadataException(msg.toString());
891            }
892    
893            /**
894             * Returns the first document library file entry metadata in the ordered set where uuid = &#63; and companyId = &#63;.
895             *
896             * @param uuid the uuid
897             * @param companyId the company ID
898             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
899             * @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
900             */
901            @Override
902            public DLFileEntryMetadata fetchByUuid_C_First(String uuid, long companyId,
903                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
904                    List<DLFileEntryMetadata> list = findByUuid_C(uuid, companyId, 0, 1,
905                                    orderByComparator);
906    
907                    if (!list.isEmpty()) {
908                            return list.get(0);
909                    }
910    
911                    return null;
912            }
913    
914            /**
915             * Returns the last document library file entry metadata in the ordered set where uuid = &#63; and companyId = &#63;.
916             *
917             * @param uuid the uuid
918             * @param companyId the company ID
919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
920             * @return the last matching document library file entry metadata
921             * @throws NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
922             */
923            @Override
924            public DLFileEntryMetadata findByUuid_C_Last(String uuid, long companyId,
925                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
926                    throws NoSuchFileEntryMetadataException {
927                    DLFileEntryMetadata dlFileEntryMetadata = fetchByUuid_C_Last(uuid,
928                                    companyId, orderByComparator);
929    
930                    if (dlFileEntryMetadata != null) {
931                            return dlFileEntryMetadata;
932                    }
933    
934                    StringBundler msg = new StringBundler(6);
935    
936                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
937    
938                    msg.append("uuid=");
939                    msg.append(uuid);
940    
941                    msg.append(", companyId=");
942                    msg.append(companyId);
943    
944                    msg.append(StringPool.CLOSE_CURLY_BRACE);
945    
946                    throw new NoSuchFileEntryMetadataException(msg.toString());
947            }
948    
949            /**
950             * Returns the last document library file entry metadata in the ordered set where uuid = &#63; and companyId = &#63;.
951             *
952             * @param uuid the uuid
953             * @param companyId the company ID
954             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
955             * @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
956             */
957            @Override
958            public DLFileEntryMetadata fetchByUuid_C_Last(String uuid, long companyId,
959                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
960                    int count = countByUuid_C(uuid, companyId);
961    
962                    if (count == 0) {
963                            return null;
964                    }
965    
966                    List<DLFileEntryMetadata> list = findByUuid_C(uuid, companyId,
967                                    count - 1, count, orderByComparator);
968    
969                    if (!list.isEmpty()) {
970                            return list.get(0);
971                    }
972    
973                    return null;
974            }
975    
976            /**
977             * Returns the document library file entry metadatas before and after the current document library file entry metadata in the ordered set where uuid = &#63; and companyId = &#63;.
978             *
979             * @param fileEntryMetadataId the primary key of the current document library file entry metadata
980             * @param uuid the uuid
981             * @param companyId the company ID
982             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
983             * @return the previous, current, and next document library file entry metadata
984             * @throws NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
985             */
986            @Override
987            public DLFileEntryMetadata[] findByUuid_C_PrevAndNext(
988                    long fileEntryMetadataId, String uuid, long companyId,
989                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
990                    throws NoSuchFileEntryMetadataException {
991                    DLFileEntryMetadata dlFileEntryMetadata = findByPrimaryKey(fileEntryMetadataId);
992    
993                    Session session = null;
994    
995                    try {
996                            session = openSession();
997    
998                            DLFileEntryMetadata[] array = new DLFileEntryMetadataImpl[3];
999    
1000                            array[0] = getByUuid_C_PrevAndNext(session, dlFileEntryMetadata,
1001                                            uuid, companyId, orderByComparator, true);
1002    
1003                            array[1] = dlFileEntryMetadata;
1004    
1005                            array[2] = getByUuid_C_PrevAndNext(session, dlFileEntryMetadata,
1006                                            uuid, companyId, orderByComparator, false);
1007    
1008                            return array;
1009                    }
1010                    catch (Exception e) {
1011                            throw processException(e);
1012                    }
1013                    finally {
1014                            closeSession(session);
1015                    }
1016            }
1017    
1018            protected DLFileEntryMetadata getByUuid_C_PrevAndNext(Session session,
1019                    DLFileEntryMetadata dlFileEntryMetadata, String uuid, long companyId,
1020                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
1021                    boolean previous) {
1022                    StringBundler query = null;
1023    
1024                    if (orderByComparator != null) {
1025                            query = new StringBundler(6 +
1026                                            (orderByComparator.getOrderByFields().length * 6));
1027                    }
1028                    else {
1029                            query = new StringBundler(3);
1030                    }
1031    
1032                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
1033    
1034                    boolean bindUuid = false;
1035    
1036                    if (uuid == null) {
1037                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1038                    }
1039                    else if (uuid.equals(StringPool.BLANK)) {
1040                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1041                    }
1042                    else {
1043                            bindUuid = true;
1044    
1045                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1046                    }
1047    
1048                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1049    
1050                    if (orderByComparator != null) {
1051                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1052    
1053                            if (orderByConditionFields.length > 0) {
1054                                    query.append(WHERE_AND);
1055                            }
1056    
1057                            for (int i = 0; i < orderByConditionFields.length; i++) {
1058                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1059                                    query.append(orderByConditionFields[i]);
1060    
1061                                    if ((i + 1) < orderByConditionFields.length) {
1062                                            if (orderByComparator.isAscending() ^ previous) {
1063                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1064                                            }
1065                                            else {
1066                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1067                                            }
1068                                    }
1069                                    else {
1070                                            if (orderByComparator.isAscending() ^ previous) {
1071                                                    query.append(WHERE_GREATER_THAN);
1072                                            }
1073                                            else {
1074                                                    query.append(WHERE_LESSER_THAN);
1075                                            }
1076                                    }
1077                            }
1078    
1079                            query.append(ORDER_BY_CLAUSE);
1080    
1081                            String[] orderByFields = orderByComparator.getOrderByFields();
1082    
1083                            for (int i = 0; i < orderByFields.length; i++) {
1084                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1085                                    query.append(orderByFields[i]);
1086    
1087                                    if ((i + 1) < orderByFields.length) {
1088                                            if (orderByComparator.isAscending() ^ previous) {
1089                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1090                                            }
1091                                            else {
1092                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1093                                            }
1094                                    }
1095                                    else {
1096                                            if (orderByComparator.isAscending() ^ previous) {
1097                                                    query.append(ORDER_BY_ASC);
1098                                            }
1099                                            else {
1100                                                    query.append(ORDER_BY_DESC);
1101                                            }
1102                                    }
1103                            }
1104                    }
1105                    else {
1106                            query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
1107                    }
1108    
1109                    String sql = query.toString();
1110    
1111                    Query q = session.createQuery(sql);
1112    
1113                    q.setFirstResult(0);
1114                    q.setMaxResults(2);
1115    
1116                    QueryPos qPos = QueryPos.getInstance(q);
1117    
1118                    if (bindUuid) {
1119                            qPos.add(uuid);
1120                    }
1121    
1122                    qPos.add(companyId);
1123    
1124                    if (orderByComparator != null) {
1125                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileEntryMetadata);
1126    
1127                            for (Object value : values) {
1128                                    qPos.add(value);
1129                            }
1130                    }
1131    
1132                    List<DLFileEntryMetadata> list = q.list();
1133    
1134                    if (list.size() == 2) {
1135                            return list.get(1);
1136                    }
1137                    else {
1138                            return null;
1139                    }
1140            }
1141    
1142            /**
1143             * Removes all the document library file entry metadatas where uuid = &#63; and companyId = &#63; from the database.
1144             *
1145             * @param uuid the uuid
1146             * @param companyId the company ID
1147             */
1148            @Override
1149            public void removeByUuid_C(String uuid, long companyId) {
1150                    for (DLFileEntryMetadata dlFileEntryMetadata : findByUuid_C(uuid,
1151                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1152                            remove(dlFileEntryMetadata);
1153                    }
1154            }
1155    
1156            /**
1157             * Returns the number of document library file entry metadatas where uuid = &#63; and companyId = &#63;.
1158             *
1159             * @param uuid the uuid
1160             * @param companyId the company ID
1161             * @return the number of matching document library file entry metadatas
1162             */
1163            @Override
1164            public int countByUuid_C(String uuid, long companyId) {
1165                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1166    
1167                    Object[] finderArgs = new Object[] { uuid, companyId };
1168    
1169                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1170    
1171                    if (count == null) {
1172                            StringBundler query = new StringBundler(3);
1173    
1174                            query.append(_SQL_COUNT_DLFILEENTRYMETADATA_WHERE);
1175    
1176                            boolean bindUuid = false;
1177    
1178                            if (uuid == null) {
1179                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1180                            }
1181                            else if (uuid.equals(StringPool.BLANK)) {
1182                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1183                            }
1184                            else {
1185                                    bindUuid = true;
1186    
1187                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1188                            }
1189    
1190                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1191    
1192                            String sql = query.toString();
1193    
1194                            Session session = null;
1195    
1196                            try {
1197                                    session = openSession();
1198    
1199                                    Query q = session.createQuery(sql);
1200    
1201                                    QueryPos qPos = QueryPos.getInstance(q);
1202    
1203                                    if (bindUuid) {
1204                                            qPos.add(uuid);
1205                                    }
1206    
1207                                    qPos.add(companyId);
1208    
1209                                    count = (Long)q.uniqueResult();
1210    
1211                                    finderCache.putResult(finderPath, finderArgs, count);
1212                            }
1213                            catch (Exception e) {
1214                                    finderCache.removeResult(finderPath, finderArgs);
1215    
1216                                    throw processException(e);
1217                            }
1218                            finally {
1219                                    closeSession(session);
1220                            }
1221                    }
1222    
1223                    return count.intValue();
1224            }
1225    
1226            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "dlFileEntryMetadata.uuid IS NULL AND ";
1227            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "dlFileEntryMetadata.uuid = ? AND ";
1228            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(dlFileEntryMetadata.uuid IS NULL OR dlFileEntryMetadata.uuid = '') AND ";
1229            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "dlFileEntryMetadata.companyId = ?";
1230            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID =
1231                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1232                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
1233                            DLFileEntryMetadataImpl.class,
1234                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFileEntryId",
1235                            new String[] {
1236                                    Long.class.getName(),
1237                                    
1238                            Integer.class.getName(), Integer.class.getName(),
1239                                    OrderByComparator.class.getName()
1240                            });
1241            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID =
1242                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1243                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
1244                            DLFileEntryMetadataImpl.class,
1245                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFileEntryId",
1246                            new String[] { Long.class.getName() },
1247                            DLFileEntryMetadataModelImpl.FILEENTRYID_COLUMN_BITMASK);
1248            public static final FinderPath FINDER_PATH_COUNT_BY_FILEENTRYID = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1249                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
1250                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileEntryId",
1251                            new String[] { Long.class.getName() });
1252    
1253            /**
1254             * Returns all the document library file entry metadatas where fileEntryId = &#63;.
1255             *
1256             * @param fileEntryId the file entry ID
1257             * @return the matching document library file entry metadatas
1258             */
1259            @Override
1260            public List<DLFileEntryMetadata> findByFileEntryId(long fileEntryId) {
1261                    return findByFileEntryId(fileEntryId, QueryUtil.ALL_POS,
1262                            QueryUtil.ALL_POS, null);
1263            }
1264    
1265            /**
1266             * Returns a range of all the document library file entry metadatas where fileEntryId = &#63;.
1267             *
1268             * <p>
1269             * 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.
1270             * </p>
1271             *
1272             * @param fileEntryId the file entry ID
1273             * @param start the lower bound of the range of document library file entry metadatas
1274             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1275             * @return the range of matching document library file entry metadatas
1276             */
1277            @Override
1278            public List<DLFileEntryMetadata> findByFileEntryId(long fileEntryId,
1279                    int start, int end) {
1280                    return findByFileEntryId(fileEntryId, start, end, null);
1281            }
1282    
1283            /**
1284             * Returns an ordered range of all the document library file entry metadatas where fileEntryId = &#63;.
1285             *
1286             * <p>
1287             * 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.
1288             * </p>
1289             *
1290             * @param fileEntryId the file entry ID
1291             * @param start the lower bound of the range of document library file entry metadatas
1292             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1293             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1294             * @return the ordered range of matching document library file entry metadatas
1295             */
1296            @Override
1297            public List<DLFileEntryMetadata> findByFileEntryId(long fileEntryId,
1298                    int start, int end,
1299                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1300                    return findByFileEntryId(fileEntryId, start, end, orderByComparator,
1301                            true);
1302            }
1303    
1304            /**
1305             * Returns an ordered range of all the document library file entry metadatas where fileEntryId = &#63;.
1306             *
1307             * <p>
1308             * 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.
1309             * </p>
1310             *
1311             * @param fileEntryId the file entry ID
1312             * @param start the lower bound of the range of document library file entry metadatas
1313             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1314             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1315             * @param retrieveFromCache whether to retrieve from the finder cache
1316             * @return the ordered range of matching document library file entry metadatas
1317             */
1318            @Override
1319            public List<DLFileEntryMetadata> findByFileEntryId(long fileEntryId,
1320                    int start, int end,
1321                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
1322                    boolean retrieveFromCache) {
1323                    boolean pagination = true;
1324                    FinderPath finderPath = null;
1325                    Object[] finderArgs = null;
1326    
1327                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1328                                    (orderByComparator == null)) {
1329                            pagination = false;
1330                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID;
1331                            finderArgs = new Object[] { fileEntryId };
1332                    }
1333                    else {
1334                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEENTRYID;
1335                            finderArgs = new Object[] { fileEntryId, start, end, orderByComparator };
1336                    }
1337    
1338                    List<DLFileEntryMetadata> list = null;
1339    
1340                    if (retrieveFromCache) {
1341                            list = (List<DLFileEntryMetadata>)finderCache.getResult(finderPath,
1342                                            finderArgs, this);
1343    
1344                            if ((list != null) && !list.isEmpty()) {
1345                                    for (DLFileEntryMetadata dlFileEntryMetadata : list) {
1346                                            if ((fileEntryId != dlFileEntryMetadata.getFileEntryId())) {
1347                                                    list = null;
1348    
1349                                                    break;
1350                                            }
1351                                    }
1352                            }
1353                    }
1354    
1355                    if (list == null) {
1356                            StringBundler query = null;
1357    
1358                            if (orderByComparator != null) {
1359                                    query = new StringBundler(3 +
1360                                                    (orderByComparator.getOrderByFields().length * 3));
1361                            }
1362                            else {
1363                                    query = new StringBundler(3);
1364                            }
1365    
1366                            query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
1367    
1368                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1369    
1370                            if (orderByComparator != null) {
1371                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1372                                            orderByComparator);
1373                            }
1374                            else
1375                             if (pagination) {
1376                                    query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
1377                            }
1378    
1379                            String sql = query.toString();
1380    
1381                            Session session = null;
1382    
1383                            try {
1384                                    session = openSession();
1385    
1386                                    Query q = session.createQuery(sql);
1387    
1388                                    QueryPos qPos = QueryPos.getInstance(q);
1389    
1390                                    qPos.add(fileEntryId);
1391    
1392                                    if (!pagination) {
1393                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
1394                                                            getDialect(), start, end, false);
1395    
1396                                            Collections.sort(list);
1397    
1398                                            list = Collections.unmodifiableList(list);
1399                                    }
1400                                    else {
1401                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
1402                                                            getDialect(), start, end);
1403                                    }
1404    
1405                                    cacheResult(list);
1406    
1407                                    finderCache.putResult(finderPath, finderArgs, list);
1408                            }
1409                            catch (Exception e) {
1410                                    finderCache.removeResult(finderPath, finderArgs);
1411    
1412                                    throw processException(e);
1413                            }
1414                            finally {
1415                                    closeSession(session);
1416                            }
1417                    }
1418    
1419                    return list;
1420            }
1421    
1422            /**
1423             * Returns the first document library file entry metadata in the ordered set where fileEntryId = &#63;.
1424             *
1425             * @param fileEntryId the file entry ID
1426             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1427             * @return the first matching document library file entry metadata
1428             * @throws NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
1429             */
1430            @Override
1431            public DLFileEntryMetadata findByFileEntryId_First(long fileEntryId,
1432                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1433                    throws NoSuchFileEntryMetadataException {
1434                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileEntryId_First(fileEntryId,
1435                                    orderByComparator);
1436    
1437                    if (dlFileEntryMetadata != null) {
1438                            return dlFileEntryMetadata;
1439                    }
1440    
1441                    StringBundler msg = new StringBundler(4);
1442    
1443                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1444    
1445                    msg.append("fileEntryId=");
1446                    msg.append(fileEntryId);
1447    
1448                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1449    
1450                    throw new NoSuchFileEntryMetadataException(msg.toString());
1451            }
1452    
1453            /**
1454             * Returns the first document library file entry metadata in the ordered set where fileEntryId = &#63;.
1455             *
1456             * @param fileEntryId the file entry ID
1457             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1458             * @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
1459             */
1460            @Override
1461            public DLFileEntryMetadata fetchByFileEntryId_First(long fileEntryId,
1462                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1463                    List<DLFileEntryMetadata> list = findByFileEntryId(fileEntryId, 0, 1,
1464                                    orderByComparator);
1465    
1466                    if (!list.isEmpty()) {
1467                            return list.get(0);
1468                    }
1469    
1470                    return null;
1471            }
1472    
1473            /**
1474             * Returns the last document library file entry metadata in the ordered set where fileEntryId = &#63;.
1475             *
1476             * @param fileEntryId the file entry ID
1477             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1478             * @return the last matching document library file entry metadata
1479             * @throws NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
1480             */
1481            @Override
1482            public DLFileEntryMetadata findByFileEntryId_Last(long fileEntryId,
1483                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1484                    throws NoSuchFileEntryMetadataException {
1485                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileEntryId_Last(fileEntryId,
1486                                    orderByComparator);
1487    
1488                    if (dlFileEntryMetadata != null) {
1489                            return dlFileEntryMetadata;
1490                    }
1491    
1492                    StringBundler msg = new StringBundler(4);
1493    
1494                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1495    
1496                    msg.append("fileEntryId=");
1497                    msg.append(fileEntryId);
1498    
1499                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1500    
1501                    throw new NoSuchFileEntryMetadataException(msg.toString());
1502            }
1503    
1504            /**
1505             * Returns the last document library file entry metadata in the ordered set where fileEntryId = &#63;.
1506             *
1507             * @param fileEntryId the file entry ID
1508             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1509             * @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
1510             */
1511            @Override
1512            public DLFileEntryMetadata fetchByFileEntryId_Last(long fileEntryId,
1513                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1514                    int count = countByFileEntryId(fileEntryId);
1515    
1516                    if (count == 0) {
1517                            return null;
1518                    }
1519    
1520                    List<DLFileEntryMetadata> list = findByFileEntryId(fileEntryId,
1521                                    count - 1, count, orderByComparator);
1522    
1523                    if (!list.isEmpty()) {
1524                            return list.get(0);
1525                    }
1526    
1527                    return null;
1528            }
1529    
1530            /**
1531             * Returns the document library file entry metadatas before and after the current document library file entry metadata in the ordered set where fileEntryId = &#63;.
1532             *
1533             * @param fileEntryMetadataId the primary key of the current document library file entry metadata
1534             * @param fileEntryId the file entry ID
1535             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1536             * @return the previous, current, and next document library file entry metadata
1537             * @throws NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
1538             */
1539            @Override
1540            public DLFileEntryMetadata[] findByFileEntryId_PrevAndNext(
1541                    long fileEntryMetadataId, long fileEntryId,
1542                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1543                    throws NoSuchFileEntryMetadataException {
1544                    DLFileEntryMetadata dlFileEntryMetadata = findByPrimaryKey(fileEntryMetadataId);
1545    
1546                    Session session = null;
1547    
1548                    try {
1549                            session = openSession();
1550    
1551                            DLFileEntryMetadata[] array = new DLFileEntryMetadataImpl[3];
1552    
1553                            array[0] = getByFileEntryId_PrevAndNext(session,
1554                                            dlFileEntryMetadata, fileEntryId, orderByComparator, true);
1555    
1556                            array[1] = dlFileEntryMetadata;
1557    
1558                            array[2] = getByFileEntryId_PrevAndNext(session,
1559                                            dlFileEntryMetadata, fileEntryId, orderByComparator, false);
1560    
1561                            return array;
1562                    }
1563                    catch (Exception e) {
1564                            throw processException(e);
1565                    }
1566                    finally {
1567                            closeSession(session);
1568                    }
1569            }
1570    
1571            protected DLFileEntryMetadata getByFileEntryId_PrevAndNext(
1572                    Session session, DLFileEntryMetadata dlFileEntryMetadata,
1573                    long fileEntryId,
1574                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
1575                    boolean previous) {
1576                    StringBundler query = null;
1577    
1578                    if (orderByComparator != null) {
1579                            query = new StringBundler(6 +
1580                                            (orderByComparator.getOrderByFields().length * 6));
1581                    }
1582                    else {
1583                            query = new StringBundler(3);
1584                    }
1585    
1586                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
1587    
1588                    query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1589    
1590                    if (orderByComparator != null) {
1591                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1592    
1593                            if (orderByConditionFields.length > 0) {
1594                                    query.append(WHERE_AND);
1595                            }
1596    
1597                            for (int i = 0; i < orderByConditionFields.length; i++) {
1598                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1599                                    query.append(orderByConditionFields[i]);
1600    
1601                                    if ((i + 1) < orderByConditionFields.length) {
1602                                            if (orderByComparator.isAscending() ^ previous) {
1603                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1604                                            }
1605                                            else {
1606                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1607                                            }
1608                                    }
1609                                    else {
1610                                            if (orderByComparator.isAscending() ^ previous) {
1611                                                    query.append(WHERE_GREATER_THAN);
1612                                            }
1613                                            else {
1614                                                    query.append(WHERE_LESSER_THAN);
1615                                            }
1616                                    }
1617                            }
1618    
1619                            query.append(ORDER_BY_CLAUSE);
1620    
1621                            String[] orderByFields = orderByComparator.getOrderByFields();
1622    
1623                            for (int i = 0; i < orderByFields.length; i++) {
1624                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1625                                    query.append(orderByFields[i]);
1626    
1627                                    if ((i + 1) < orderByFields.length) {
1628                                            if (orderByComparator.isAscending() ^ previous) {
1629                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1630                                            }
1631                                            else {
1632                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1633                                            }
1634                                    }
1635                                    else {
1636                                            if (orderByComparator.isAscending() ^ previous) {
1637                                                    query.append(ORDER_BY_ASC);
1638                                            }
1639                                            else {
1640                                                    query.append(ORDER_BY_DESC);
1641                                            }
1642                                    }
1643                            }
1644                    }
1645                    else {
1646                            query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
1647                    }
1648    
1649                    String sql = query.toString();
1650    
1651                    Query q = session.createQuery(sql);
1652    
1653                    q.setFirstResult(0);
1654                    q.setMaxResults(2);
1655    
1656                    QueryPos qPos = QueryPos.getInstance(q);
1657    
1658                    qPos.add(fileEntryId);
1659    
1660                    if (orderByComparator != null) {
1661                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileEntryMetadata);
1662    
1663                            for (Object value : values) {
1664                                    qPos.add(value);
1665                            }
1666                    }
1667    
1668                    List<DLFileEntryMetadata> list = q.list();
1669    
1670                    if (list.size() == 2) {
1671                            return list.get(1);
1672                    }
1673                    else {
1674                            return null;
1675                    }
1676            }
1677    
1678            /**
1679             * Removes all the document library file entry metadatas where fileEntryId = &#63; from the database.
1680             *
1681             * @param fileEntryId the file entry ID
1682             */
1683            @Override
1684            public void removeByFileEntryId(long fileEntryId) {
1685                    for (DLFileEntryMetadata dlFileEntryMetadata : findByFileEntryId(
1686                                    fileEntryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1687                            remove(dlFileEntryMetadata);
1688                    }
1689            }
1690    
1691            /**
1692             * Returns the number of document library file entry metadatas where fileEntryId = &#63;.
1693             *
1694             * @param fileEntryId the file entry ID
1695             * @return the number of matching document library file entry metadatas
1696             */
1697            @Override
1698            public int countByFileEntryId(long fileEntryId) {
1699                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEENTRYID;
1700    
1701                    Object[] finderArgs = new Object[] { fileEntryId };
1702    
1703                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1704    
1705                    if (count == null) {
1706                            StringBundler query = new StringBundler(2);
1707    
1708                            query.append(_SQL_COUNT_DLFILEENTRYMETADATA_WHERE);
1709    
1710                            query.append(_FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2);
1711    
1712                            String sql = query.toString();
1713    
1714                            Session session = null;
1715    
1716                            try {
1717                                    session = openSession();
1718    
1719                                    Query q = session.createQuery(sql);
1720    
1721                                    QueryPos qPos = QueryPos.getInstance(q);
1722    
1723                                    qPos.add(fileEntryId);
1724    
1725                                    count = (Long)q.uniqueResult();
1726    
1727                                    finderCache.putResult(finderPath, finderArgs, count);
1728                            }
1729                            catch (Exception e) {
1730                                    finderCache.removeResult(finderPath, finderArgs);
1731    
1732                                    throw processException(e);
1733                            }
1734                            finally {
1735                                    closeSession(session);
1736                            }
1737                    }
1738    
1739                    return count.intValue();
1740            }
1741    
1742            private static final String _FINDER_COLUMN_FILEENTRYID_FILEENTRYID_2 = "dlFileEntryMetadata.fileEntryId = ?";
1743            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEVERSIONID =
1744                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1745                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
1746                            DLFileEntryMetadataImpl.class,
1747                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByFileVersionId",
1748                            new String[] {
1749                                    Long.class.getName(),
1750                                    
1751                            Integer.class.getName(), Integer.class.getName(),
1752                                    OrderByComparator.class.getName()
1753                            });
1754            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID =
1755                    new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1756                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
1757                            DLFileEntryMetadataImpl.class,
1758                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByFileVersionId",
1759                            new String[] { Long.class.getName() },
1760                            DLFileEntryMetadataModelImpl.FILEVERSIONID_COLUMN_BITMASK);
1761            public static final FinderPath FINDER_PATH_COUNT_BY_FILEVERSIONID = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
1762                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
1763                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByFileVersionId",
1764                            new String[] { Long.class.getName() });
1765    
1766            /**
1767             * Returns all the document library file entry metadatas where fileVersionId = &#63;.
1768             *
1769             * @param fileVersionId the file version ID
1770             * @return the matching document library file entry metadatas
1771             */
1772            @Override
1773            public List<DLFileEntryMetadata> findByFileVersionId(long fileVersionId) {
1774                    return findByFileVersionId(fileVersionId, QueryUtil.ALL_POS,
1775                            QueryUtil.ALL_POS, null);
1776            }
1777    
1778            /**
1779             * Returns a range of all the document library file entry metadatas where fileVersionId = &#63;.
1780             *
1781             * <p>
1782             * 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.
1783             * </p>
1784             *
1785             * @param fileVersionId the file version ID
1786             * @param start the lower bound of the range of document library file entry metadatas
1787             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1788             * @return the range of matching document library file entry metadatas
1789             */
1790            @Override
1791            public List<DLFileEntryMetadata> findByFileVersionId(long fileVersionId,
1792                    int start, int end) {
1793                    return findByFileVersionId(fileVersionId, start, end, null);
1794            }
1795    
1796            /**
1797             * Returns an ordered range of all the document library file entry metadatas where fileVersionId = &#63;.
1798             *
1799             * <p>
1800             * 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.
1801             * </p>
1802             *
1803             * @param fileVersionId the file version ID
1804             * @param start the lower bound of the range of document library file entry metadatas
1805             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1806             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1807             * @return the ordered range of matching document library file entry metadatas
1808             */
1809            @Override
1810            public List<DLFileEntryMetadata> findByFileVersionId(long fileVersionId,
1811                    int start, int end,
1812                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1813                    return findByFileVersionId(fileVersionId, start, end,
1814                            orderByComparator, true);
1815            }
1816    
1817            /**
1818             * Returns an ordered range of all the document library file entry metadatas where fileVersionId = &#63;.
1819             *
1820             * <p>
1821             * 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.
1822             * </p>
1823             *
1824             * @param fileVersionId the file version ID
1825             * @param start the lower bound of the range of document library file entry metadatas
1826             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
1827             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1828             * @param retrieveFromCache whether to retrieve from the finder cache
1829             * @return the ordered range of matching document library file entry metadatas
1830             */
1831            @Override
1832            public List<DLFileEntryMetadata> findByFileVersionId(long fileVersionId,
1833                    int start, int end,
1834                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
1835                    boolean retrieveFromCache) {
1836                    boolean pagination = true;
1837                    FinderPath finderPath = null;
1838                    Object[] finderArgs = null;
1839    
1840                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1841                                    (orderByComparator == null)) {
1842                            pagination = false;
1843                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID;
1844                            finderArgs = new Object[] { fileVersionId };
1845                    }
1846                    else {
1847                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_FILEVERSIONID;
1848                            finderArgs = new Object[] {
1849                                            fileVersionId,
1850                                            
1851                                            start, end, orderByComparator
1852                                    };
1853                    }
1854    
1855                    List<DLFileEntryMetadata> list = null;
1856    
1857                    if (retrieveFromCache) {
1858                            list = (List<DLFileEntryMetadata>)finderCache.getResult(finderPath,
1859                                            finderArgs, this);
1860    
1861                            if ((list != null) && !list.isEmpty()) {
1862                                    for (DLFileEntryMetadata dlFileEntryMetadata : list) {
1863                                            if ((fileVersionId != dlFileEntryMetadata.getFileVersionId())) {
1864                                                    list = null;
1865    
1866                                                    break;
1867                                            }
1868                                    }
1869                            }
1870                    }
1871    
1872                    if (list == null) {
1873                            StringBundler query = null;
1874    
1875                            if (orderByComparator != null) {
1876                                    query = new StringBundler(3 +
1877                                                    (orderByComparator.getOrderByFields().length * 3));
1878                            }
1879                            else {
1880                                    query = new StringBundler(3);
1881                            }
1882    
1883                            query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
1884    
1885                            query.append(_FINDER_COLUMN_FILEVERSIONID_FILEVERSIONID_2);
1886    
1887                            if (orderByComparator != null) {
1888                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1889                                            orderByComparator);
1890                            }
1891                            else
1892                             if (pagination) {
1893                                    query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
1894                            }
1895    
1896                            String sql = query.toString();
1897    
1898                            Session session = null;
1899    
1900                            try {
1901                                    session = openSession();
1902    
1903                                    Query q = session.createQuery(sql);
1904    
1905                                    QueryPos qPos = QueryPos.getInstance(q);
1906    
1907                                    qPos.add(fileVersionId);
1908    
1909                                    if (!pagination) {
1910                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
1911                                                            getDialect(), start, end, false);
1912    
1913                                            Collections.sort(list);
1914    
1915                                            list = Collections.unmodifiableList(list);
1916                                    }
1917                                    else {
1918                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
1919                                                            getDialect(), start, end);
1920                                    }
1921    
1922                                    cacheResult(list);
1923    
1924                                    finderCache.putResult(finderPath, finderArgs, list);
1925                            }
1926                            catch (Exception e) {
1927                                    finderCache.removeResult(finderPath, finderArgs);
1928    
1929                                    throw processException(e);
1930                            }
1931                            finally {
1932                                    closeSession(session);
1933                            }
1934                    }
1935    
1936                    return list;
1937            }
1938    
1939            /**
1940             * Returns the first document library file entry metadata in the ordered set where fileVersionId = &#63;.
1941             *
1942             * @param fileVersionId the file version ID
1943             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1944             * @return the first matching document library file entry metadata
1945             * @throws NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
1946             */
1947            @Override
1948            public DLFileEntryMetadata findByFileVersionId_First(long fileVersionId,
1949                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
1950                    throws NoSuchFileEntryMetadataException {
1951                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileVersionId_First(fileVersionId,
1952                                    orderByComparator);
1953    
1954                    if (dlFileEntryMetadata != null) {
1955                            return dlFileEntryMetadata;
1956                    }
1957    
1958                    StringBundler msg = new StringBundler(4);
1959    
1960                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1961    
1962                    msg.append("fileVersionId=");
1963                    msg.append(fileVersionId);
1964    
1965                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1966    
1967                    throw new NoSuchFileEntryMetadataException(msg.toString());
1968            }
1969    
1970            /**
1971             * Returns the first document library file entry metadata in the ordered set where fileVersionId = &#63;.
1972             *
1973             * @param fileVersionId the file version ID
1974             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1975             * @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
1976             */
1977            @Override
1978            public DLFileEntryMetadata fetchByFileVersionId_First(long fileVersionId,
1979                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
1980                    List<DLFileEntryMetadata> list = findByFileVersionId(fileVersionId, 0,
1981                                    1, orderByComparator);
1982    
1983                    if (!list.isEmpty()) {
1984                            return list.get(0);
1985                    }
1986    
1987                    return null;
1988            }
1989    
1990            /**
1991             * Returns the last document library file entry metadata in the ordered set where fileVersionId = &#63;.
1992             *
1993             * @param fileVersionId the file version ID
1994             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1995             * @return the last matching document library file entry metadata
1996             * @throws NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
1997             */
1998            @Override
1999            public DLFileEntryMetadata findByFileVersionId_Last(long fileVersionId,
2000                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
2001                    throws NoSuchFileEntryMetadataException {
2002                    DLFileEntryMetadata dlFileEntryMetadata = fetchByFileVersionId_Last(fileVersionId,
2003                                    orderByComparator);
2004    
2005                    if (dlFileEntryMetadata != null) {
2006                            return dlFileEntryMetadata;
2007                    }
2008    
2009                    StringBundler msg = new StringBundler(4);
2010    
2011                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2012    
2013                    msg.append("fileVersionId=");
2014                    msg.append(fileVersionId);
2015    
2016                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2017    
2018                    throw new NoSuchFileEntryMetadataException(msg.toString());
2019            }
2020    
2021            /**
2022             * Returns the last document library file entry metadata in the ordered set where fileVersionId = &#63;.
2023             *
2024             * @param fileVersionId the file version ID
2025             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2026             * @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
2027             */
2028            @Override
2029            public DLFileEntryMetadata fetchByFileVersionId_Last(long fileVersionId,
2030                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
2031                    int count = countByFileVersionId(fileVersionId);
2032    
2033                    if (count == 0) {
2034                            return null;
2035                    }
2036    
2037                    List<DLFileEntryMetadata> list = findByFileVersionId(fileVersionId,
2038                                    count - 1, count, orderByComparator);
2039    
2040                    if (!list.isEmpty()) {
2041                            return list.get(0);
2042                    }
2043    
2044                    return null;
2045            }
2046    
2047            /**
2048             * Returns the document library file entry metadatas before and after the current document library file entry metadata in the ordered set where fileVersionId = &#63;.
2049             *
2050             * @param fileEntryMetadataId the primary key of the current document library file entry metadata
2051             * @param fileVersionId the file version ID
2052             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2053             * @return the previous, current, and next document library file entry metadata
2054             * @throws NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2055             */
2056            @Override
2057            public DLFileEntryMetadata[] findByFileVersionId_PrevAndNext(
2058                    long fileEntryMetadataId, long fileVersionId,
2059                    OrderByComparator<DLFileEntryMetadata> orderByComparator)
2060                    throws NoSuchFileEntryMetadataException {
2061                    DLFileEntryMetadata dlFileEntryMetadata = findByPrimaryKey(fileEntryMetadataId);
2062    
2063                    Session session = null;
2064    
2065                    try {
2066                            session = openSession();
2067    
2068                            DLFileEntryMetadata[] array = new DLFileEntryMetadataImpl[3];
2069    
2070                            array[0] = getByFileVersionId_PrevAndNext(session,
2071                                            dlFileEntryMetadata, fileVersionId, orderByComparator, true);
2072    
2073                            array[1] = dlFileEntryMetadata;
2074    
2075                            array[2] = getByFileVersionId_PrevAndNext(session,
2076                                            dlFileEntryMetadata, fileVersionId, orderByComparator, false);
2077    
2078                            return array;
2079                    }
2080                    catch (Exception e) {
2081                            throw processException(e);
2082                    }
2083                    finally {
2084                            closeSession(session);
2085                    }
2086            }
2087    
2088            protected DLFileEntryMetadata getByFileVersionId_PrevAndNext(
2089                    Session session, DLFileEntryMetadata dlFileEntryMetadata,
2090                    long fileVersionId,
2091                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
2092                    boolean previous) {
2093                    StringBundler query = null;
2094    
2095                    if (orderByComparator != null) {
2096                            query = new StringBundler(6 +
2097                                            (orderByComparator.getOrderByFields().length * 6));
2098                    }
2099                    else {
2100                            query = new StringBundler(3);
2101                    }
2102    
2103                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
2104    
2105                    query.append(_FINDER_COLUMN_FILEVERSIONID_FILEVERSIONID_2);
2106    
2107                    if (orderByComparator != null) {
2108                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2109    
2110                            if (orderByConditionFields.length > 0) {
2111                                    query.append(WHERE_AND);
2112                            }
2113    
2114                            for (int i = 0; i < orderByConditionFields.length; i++) {
2115                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2116                                    query.append(orderByConditionFields[i]);
2117    
2118                                    if ((i + 1) < orderByConditionFields.length) {
2119                                            if (orderByComparator.isAscending() ^ previous) {
2120                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2121                                            }
2122                                            else {
2123                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2124                                            }
2125                                    }
2126                                    else {
2127                                            if (orderByComparator.isAscending() ^ previous) {
2128                                                    query.append(WHERE_GREATER_THAN);
2129                                            }
2130                                            else {
2131                                                    query.append(WHERE_LESSER_THAN);
2132                                            }
2133                                    }
2134                            }
2135    
2136                            query.append(ORDER_BY_CLAUSE);
2137    
2138                            String[] orderByFields = orderByComparator.getOrderByFields();
2139    
2140                            for (int i = 0; i < orderByFields.length; i++) {
2141                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2142                                    query.append(orderByFields[i]);
2143    
2144                                    if ((i + 1) < orderByFields.length) {
2145                                            if (orderByComparator.isAscending() ^ previous) {
2146                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2147                                            }
2148                                            else {
2149                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2150                                            }
2151                                    }
2152                                    else {
2153                                            if (orderByComparator.isAscending() ^ previous) {
2154                                                    query.append(ORDER_BY_ASC);
2155                                            }
2156                                            else {
2157                                                    query.append(ORDER_BY_DESC);
2158                                            }
2159                                    }
2160                            }
2161                    }
2162                    else {
2163                            query.append(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
2164                    }
2165    
2166                    String sql = query.toString();
2167    
2168                    Query q = session.createQuery(sql);
2169    
2170                    q.setFirstResult(0);
2171                    q.setMaxResults(2);
2172    
2173                    QueryPos qPos = QueryPos.getInstance(q);
2174    
2175                    qPos.add(fileVersionId);
2176    
2177                    if (orderByComparator != null) {
2178                            Object[] values = orderByComparator.getOrderByConditionValues(dlFileEntryMetadata);
2179    
2180                            for (Object value : values) {
2181                                    qPos.add(value);
2182                            }
2183                    }
2184    
2185                    List<DLFileEntryMetadata> list = q.list();
2186    
2187                    if (list.size() == 2) {
2188                            return list.get(1);
2189                    }
2190                    else {
2191                            return null;
2192                    }
2193            }
2194    
2195            /**
2196             * Removes all the document library file entry metadatas where fileVersionId = &#63; from the database.
2197             *
2198             * @param fileVersionId the file version ID
2199             */
2200            @Override
2201            public void removeByFileVersionId(long fileVersionId) {
2202                    for (DLFileEntryMetadata dlFileEntryMetadata : findByFileVersionId(
2203                                    fileVersionId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2204                            remove(dlFileEntryMetadata);
2205                    }
2206            }
2207    
2208            /**
2209             * Returns the number of document library file entry metadatas where fileVersionId = &#63;.
2210             *
2211             * @param fileVersionId the file version ID
2212             * @return the number of matching document library file entry metadatas
2213             */
2214            @Override
2215            public int countByFileVersionId(long fileVersionId) {
2216                    FinderPath finderPath = FINDER_PATH_COUNT_BY_FILEVERSIONID;
2217    
2218                    Object[] finderArgs = new Object[] { fileVersionId };
2219    
2220                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2221    
2222                    if (count == null) {
2223                            StringBundler query = new StringBundler(2);
2224    
2225                            query.append(_SQL_COUNT_DLFILEENTRYMETADATA_WHERE);
2226    
2227                            query.append(_FINDER_COLUMN_FILEVERSIONID_FILEVERSIONID_2);
2228    
2229                            String sql = query.toString();
2230    
2231                            Session session = null;
2232    
2233                            try {
2234                                    session = openSession();
2235    
2236                                    Query q = session.createQuery(sql);
2237    
2238                                    QueryPos qPos = QueryPos.getInstance(q);
2239    
2240                                    qPos.add(fileVersionId);
2241    
2242                                    count = (Long)q.uniqueResult();
2243    
2244                                    finderCache.putResult(finderPath, finderArgs, count);
2245                            }
2246                            catch (Exception e) {
2247                                    finderCache.removeResult(finderPath, finderArgs);
2248    
2249                                    throw processException(e);
2250                            }
2251                            finally {
2252                                    closeSession(session);
2253                            }
2254                    }
2255    
2256                    return count.intValue();
2257            }
2258    
2259            private static final String _FINDER_COLUMN_FILEVERSIONID_FILEVERSIONID_2 = "dlFileEntryMetadata.fileVersionId = ?";
2260            public static final FinderPath FINDER_PATH_FETCH_BY_D_F = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2261                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED,
2262                            DLFileEntryMetadataImpl.class, FINDER_CLASS_NAME_ENTITY,
2263                            "fetchByD_F",
2264                            new String[] { Long.class.getName(), Long.class.getName() },
2265                            DLFileEntryMetadataModelImpl.DDMSTRUCTUREID_COLUMN_BITMASK |
2266                            DLFileEntryMetadataModelImpl.FILEVERSIONID_COLUMN_BITMASK);
2267            public static final FinderPath FINDER_PATH_COUNT_BY_D_F = new FinderPath(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2268                            DLFileEntryMetadataModelImpl.FINDER_CACHE_ENABLED, Long.class,
2269                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByD_F",
2270                            new String[] { Long.class.getName(), Long.class.getName() });
2271    
2272            /**
2273             * Returns the document library file entry metadata where DDMStructureId = &#63; and fileVersionId = &#63; or throws a {@link NoSuchFileEntryMetadataException} if it could not be found.
2274             *
2275             * @param DDMStructureId the d d m structure ID
2276             * @param fileVersionId the file version ID
2277             * @return the matching document library file entry metadata
2278             * @throws NoSuchFileEntryMetadataException if a matching document library file entry metadata could not be found
2279             */
2280            @Override
2281            public DLFileEntryMetadata findByD_F(long DDMStructureId, long fileVersionId)
2282                    throws NoSuchFileEntryMetadataException {
2283                    DLFileEntryMetadata dlFileEntryMetadata = fetchByD_F(DDMStructureId,
2284                                    fileVersionId);
2285    
2286                    if (dlFileEntryMetadata == null) {
2287                            StringBundler msg = new StringBundler(6);
2288    
2289                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2290    
2291                            msg.append("DDMStructureId=");
2292                            msg.append(DDMStructureId);
2293    
2294                            msg.append(", fileVersionId=");
2295                            msg.append(fileVersionId);
2296    
2297                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2298    
2299                            if (_log.isWarnEnabled()) {
2300                                    _log.warn(msg.toString());
2301                            }
2302    
2303                            throw new NoSuchFileEntryMetadataException(msg.toString());
2304                    }
2305    
2306                    return dlFileEntryMetadata;
2307            }
2308    
2309            /**
2310             * 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.
2311             *
2312             * @param DDMStructureId the d d m structure ID
2313             * @param fileVersionId the file version ID
2314             * @return the matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
2315             */
2316            @Override
2317            public DLFileEntryMetadata fetchByD_F(long DDMStructureId,
2318                    long fileVersionId) {
2319                    return fetchByD_F(DDMStructureId, fileVersionId, true);
2320            }
2321    
2322            /**
2323             * 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.
2324             *
2325             * @param DDMStructureId the d d m structure ID
2326             * @param fileVersionId the file version ID
2327             * @param retrieveFromCache whether to retrieve from the finder cache
2328             * @return the matching document library file entry metadata, or <code>null</code> if a matching document library file entry metadata could not be found
2329             */
2330            @Override
2331            public DLFileEntryMetadata fetchByD_F(long DDMStructureId,
2332                    long fileVersionId, boolean retrieveFromCache) {
2333                    Object[] finderArgs = new Object[] { DDMStructureId, fileVersionId };
2334    
2335                    Object result = null;
2336    
2337                    if (retrieveFromCache) {
2338                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_D_F,
2339                                            finderArgs, this);
2340                    }
2341    
2342                    if (result instanceof DLFileEntryMetadata) {
2343                            DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)result;
2344    
2345                            if ((DDMStructureId != dlFileEntryMetadata.getDDMStructureId()) ||
2346                                            (fileVersionId != dlFileEntryMetadata.getFileVersionId())) {
2347                                    result = null;
2348                            }
2349                    }
2350    
2351                    if (result == null) {
2352                            StringBundler query = new StringBundler(4);
2353    
2354                            query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE);
2355    
2356                            query.append(_FINDER_COLUMN_D_F_DDMSTRUCTUREID_2);
2357    
2358                            query.append(_FINDER_COLUMN_D_F_FILEVERSIONID_2);
2359    
2360                            String sql = query.toString();
2361    
2362                            Session session = null;
2363    
2364                            try {
2365                                    session = openSession();
2366    
2367                                    Query q = session.createQuery(sql);
2368    
2369                                    QueryPos qPos = QueryPos.getInstance(q);
2370    
2371                                    qPos.add(DDMStructureId);
2372    
2373                                    qPos.add(fileVersionId);
2374    
2375                                    List<DLFileEntryMetadata> list = q.list();
2376    
2377                                    if (list.isEmpty()) {
2378                                            finderCache.putResult(FINDER_PATH_FETCH_BY_D_F, finderArgs,
2379                                                    list);
2380                                    }
2381                                    else {
2382                                            DLFileEntryMetadata dlFileEntryMetadata = list.get(0);
2383    
2384                                            result = dlFileEntryMetadata;
2385    
2386                                            cacheResult(dlFileEntryMetadata);
2387    
2388                                            if ((dlFileEntryMetadata.getDDMStructureId() != DDMStructureId) ||
2389                                                            (dlFileEntryMetadata.getFileVersionId() != fileVersionId)) {
2390                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_D_F,
2391                                                            finderArgs, dlFileEntryMetadata);
2392                                            }
2393                                    }
2394                            }
2395                            catch (Exception e) {
2396                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_D_F, finderArgs);
2397    
2398                                    throw processException(e);
2399                            }
2400                            finally {
2401                                    closeSession(session);
2402                            }
2403                    }
2404    
2405                    if (result instanceof List<?>) {
2406                            return null;
2407                    }
2408                    else {
2409                            return (DLFileEntryMetadata)result;
2410                    }
2411            }
2412    
2413            /**
2414             * Removes the document library file entry metadata where DDMStructureId = &#63; and fileVersionId = &#63; from the database.
2415             *
2416             * @param DDMStructureId the d d m structure ID
2417             * @param fileVersionId the file version ID
2418             * @return the document library file entry metadata that was removed
2419             */
2420            @Override
2421            public DLFileEntryMetadata removeByD_F(long DDMStructureId,
2422                    long fileVersionId) throws NoSuchFileEntryMetadataException {
2423                    DLFileEntryMetadata dlFileEntryMetadata = findByD_F(DDMStructureId,
2424                                    fileVersionId);
2425    
2426                    return remove(dlFileEntryMetadata);
2427            }
2428    
2429            /**
2430             * Returns the number of document library file entry metadatas where DDMStructureId = &#63; and fileVersionId = &#63;.
2431             *
2432             * @param DDMStructureId the d d m structure ID
2433             * @param fileVersionId the file version ID
2434             * @return the number of matching document library file entry metadatas
2435             */
2436            @Override
2437            public int countByD_F(long DDMStructureId, long fileVersionId) {
2438                    FinderPath finderPath = FINDER_PATH_COUNT_BY_D_F;
2439    
2440                    Object[] finderArgs = new Object[] { DDMStructureId, fileVersionId };
2441    
2442                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2443    
2444                    if (count == null) {
2445                            StringBundler query = new StringBundler(3);
2446    
2447                            query.append(_SQL_COUNT_DLFILEENTRYMETADATA_WHERE);
2448    
2449                            query.append(_FINDER_COLUMN_D_F_DDMSTRUCTUREID_2);
2450    
2451                            query.append(_FINDER_COLUMN_D_F_FILEVERSIONID_2);
2452    
2453                            String sql = query.toString();
2454    
2455                            Session session = null;
2456    
2457                            try {
2458                                    session = openSession();
2459    
2460                                    Query q = session.createQuery(sql);
2461    
2462                                    QueryPos qPos = QueryPos.getInstance(q);
2463    
2464                                    qPos.add(DDMStructureId);
2465    
2466                                    qPos.add(fileVersionId);
2467    
2468                                    count = (Long)q.uniqueResult();
2469    
2470                                    finderCache.putResult(finderPath, finderArgs, count);
2471                            }
2472                            catch (Exception e) {
2473                                    finderCache.removeResult(finderPath, finderArgs);
2474    
2475                                    throw processException(e);
2476                            }
2477                            finally {
2478                                    closeSession(session);
2479                            }
2480                    }
2481    
2482                    return count.intValue();
2483            }
2484    
2485            private static final String _FINDER_COLUMN_D_F_DDMSTRUCTUREID_2 = "dlFileEntryMetadata.DDMStructureId = ? AND ";
2486            private static final String _FINDER_COLUMN_D_F_FILEVERSIONID_2 = "dlFileEntryMetadata.fileVersionId = ?";
2487    
2488            public DLFileEntryMetadataPersistenceImpl() {
2489                    setModelClass(DLFileEntryMetadata.class);
2490            }
2491    
2492            /**
2493             * Caches the document library file entry metadata in the entity cache if it is enabled.
2494             *
2495             * @param dlFileEntryMetadata the document library file entry metadata
2496             */
2497            @Override
2498            public void cacheResult(DLFileEntryMetadata dlFileEntryMetadata) {
2499                    entityCache.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2500                            DLFileEntryMetadataImpl.class, dlFileEntryMetadata.getPrimaryKey(),
2501                            dlFileEntryMetadata);
2502    
2503                    finderCache.putResult(FINDER_PATH_FETCH_BY_D_F,
2504                            new Object[] {
2505                                    dlFileEntryMetadata.getDDMStructureId(),
2506                                    dlFileEntryMetadata.getFileVersionId()
2507                            }, dlFileEntryMetadata);
2508    
2509                    dlFileEntryMetadata.resetOriginalValues();
2510            }
2511    
2512            /**
2513             * Caches the document library file entry metadatas in the entity cache if it is enabled.
2514             *
2515             * @param dlFileEntryMetadatas the document library file entry metadatas
2516             */
2517            @Override
2518            public void cacheResult(List<DLFileEntryMetadata> dlFileEntryMetadatas) {
2519                    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
2520                            if (entityCache.getResult(
2521                                                    DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2522                                                    DLFileEntryMetadataImpl.class,
2523                                                    dlFileEntryMetadata.getPrimaryKey()) == null) {
2524                                    cacheResult(dlFileEntryMetadata);
2525                            }
2526                            else {
2527                                    dlFileEntryMetadata.resetOriginalValues();
2528                            }
2529                    }
2530            }
2531    
2532            /**
2533             * Clears the cache for all document library file entry metadatas.
2534             *
2535             * <p>
2536             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
2537             * </p>
2538             */
2539            @Override
2540            public void clearCache() {
2541                    entityCache.clearCache(DLFileEntryMetadataImpl.class);
2542    
2543                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
2544                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2545                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2546            }
2547    
2548            /**
2549             * Clears the cache for the document library file entry metadata.
2550             *
2551             * <p>
2552             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
2553             * </p>
2554             */
2555            @Override
2556            public void clearCache(DLFileEntryMetadata dlFileEntryMetadata) {
2557                    entityCache.removeResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2558                            DLFileEntryMetadataImpl.class, dlFileEntryMetadata.getPrimaryKey());
2559    
2560                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2561                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2562    
2563                    clearUniqueFindersCache((DLFileEntryMetadataModelImpl)dlFileEntryMetadata);
2564            }
2565    
2566            @Override
2567            public void clearCache(List<DLFileEntryMetadata> dlFileEntryMetadatas) {
2568                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2569                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2570    
2571                    for (DLFileEntryMetadata dlFileEntryMetadata : dlFileEntryMetadatas) {
2572                            entityCache.removeResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2573                                    DLFileEntryMetadataImpl.class,
2574                                    dlFileEntryMetadata.getPrimaryKey());
2575    
2576                            clearUniqueFindersCache((DLFileEntryMetadataModelImpl)dlFileEntryMetadata);
2577                    }
2578            }
2579    
2580            protected void cacheUniqueFindersCache(
2581                    DLFileEntryMetadataModelImpl dlFileEntryMetadataModelImpl, boolean isNew) {
2582                    if (isNew) {
2583                            Object[] args = new Object[] {
2584                                            dlFileEntryMetadataModelImpl.getDDMStructureId(),
2585                                            dlFileEntryMetadataModelImpl.getFileVersionId()
2586                                    };
2587    
2588                            finderCache.putResult(FINDER_PATH_COUNT_BY_D_F, args,
2589                                    Long.valueOf(1));
2590                            finderCache.putResult(FINDER_PATH_FETCH_BY_D_F, args,
2591                                    dlFileEntryMetadataModelImpl);
2592                    }
2593                    else {
2594                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2595                                            FINDER_PATH_FETCH_BY_D_F.getColumnBitmask()) != 0) {
2596                                    Object[] args = new Object[] {
2597                                                    dlFileEntryMetadataModelImpl.getDDMStructureId(),
2598                                                    dlFileEntryMetadataModelImpl.getFileVersionId()
2599                                            };
2600    
2601                                    finderCache.putResult(FINDER_PATH_COUNT_BY_D_F, args,
2602                                            Long.valueOf(1));
2603                                    finderCache.putResult(FINDER_PATH_FETCH_BY_D_F, args,
2604                                            dlFileEntryMetadataModelImpl);
2605                            }
2606                    }
2607            }
2608    
2609            protected void clearUniqueFindersCache(
2610                    DLFileEntryMetadataModelImpl dlFileEntryMetadataModelImpl) {
2611                    Object[] args = new Object[] {
2612                                    dlFileEntryMetadataModelImpl.getDDMStructureId(),
2613                                    dlFileEntryMetadataModelImpl.getFileVersionId()
2614                            };
2615    
2616                    finderCache.removeResult(FINDER_PATH_COUNT_BY_D_F, args);
2617                    finderCache.removeResult(FINDER_PATH_FETCH_BY_D_F, args);
2618    
2619                    if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2620                                    FINDER_PATH_FETCH_BY_D_F.getColumnBitmask()) != 0) {
2621                            args = new Object[] {
2622                                            dlFileEntryMetadataModelImpl.getOriginalDDMStructureId(),
2623                                            dlFileEntryMetadataModelImpl.getOriginalFileVersionId()
2624                                    };
2625    
2626                            finderCache.removeResult(FINDER_PATH_COUNT_BY_D_F, args);
2627                            finderCache.removeResult(FINDER_PATH_FETCH_BY_D_F, args);
2628                    }
2629            }
2630    
2631            /**
2632             * Creates a new document library file entry metadata with the primary key. Does not add the document library file entry metadata to the database.
2633             *
2634             * @param fileEntryMetadataId the primary key for the new document library file entry metadata
2635             * @return the new document library file entry metadata
2636             */
2637            @Override
2638            public DLFileEntryMetadata create(long fileEntryMetadataId) {
2639                    DLFileEntryMetadata dlFileEntryMetadata = new DLFileEntryMetadataImpl();
2640    
2641                    dlFileEntryMetadata.setNew(true);
2642                    dlFileEntryMetadata.setPrimaryKey(fileEntryMetadataId);
2643    
2644                    String uuid = PortalUUIDUtil.generate();
2645    
2646                    dlFileEntryMetadata.setUuid(uuid);
2647    
2648                    return dlFileEntryMetadata;
2649            }
2650    
2651            /**
2652             * Removes the document library file entry metadata with the primary key from the database. Also notifies the appropriate model listeners.
2653             *
2654             * @param fileEntryMetadataId the primary key of the document library file entry metadata
2655             * @return the document library file entry metadata that was removed
2656             * @throws NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2657             */
2658            @Override
2659            public DLFileEntryMetadata remove(long fileEntryMetadataId)
2660                    throws NoSuchFileEntryMetadataException {
2661                    return remove((Serializable)fileEntryMetadataId);
2662            }
2663    
2664            /**
2665             * Removes the document library file entry metadata with the primary key from the database. Also notifies the appropriate model listeners.
2666             *
2667             * @param primaryKey the primary key of the document library file entry metadata
2668             * @return the document library file entry metadata that was removed
2669             * @throws NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2670             */
2671            @Override
2672            public DLFileEntryMetadata remove(Serializable primaryKey)
2673                    throws NoSuchFileEntryMetadataException {
2674                    Session session = null;
2675    
2676                    try {
2677                            session = openSession();
2678    
2679                            DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)session.get(DLFileEntryMetadataImpl.class,
2680                                            primaryKey);
2681    
2682                            if (dlFileEntryMetadata == null) {
2683                                    if (_log.isWarnEnabled()) {
2684                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2685                                    }
2686    
2687                                    throw new NoSuchFileEntryMetadataException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2688                                            primaryKey);
2689                            }
2690    
2691                            return remove(dlFileEntryMetadata);
2692                    }
2693                    catch (NoSuchFileEntryMetadataException nsee) {
2694                            throw nsee;
2695                    }
2696                    catch (Exception e) {
2697                            throw processException(e);
2698                    }
2699                    finally {
2700                            closeSession(session);
2701                    }
2702            }
2703    
2704            @Override
2705            protected DLFileEntryMetadata removeImpl(
2706                    DLFileEntryMetadata dlFileEntryMetadata) {
2707                    dlFileEntryMetadata = toUnwrappedModel(dlFileEntryMetadata);
2708    
2709                    Session session = null;
2710    
2711                    try {
2712                            session = openSession();
2713    
2714                            if (!session.contains(dlFileEntryMetadata)) {
2715                                    dlFileEntryMetadata = (DLFileEntryMetadata)session.get(DLFileEntryMetadataImpl.class,
2716                                                    dlFileEntryMetadata.getPrimaryKeyObj());
2717                            }
2718    
2719                            if (dlFileEntryMetadata != null) {
2720                                    session.delete(dlFileEntryMetadata);
2721                            }
2722                    }
2723                    catch (Exception e) {
2724                            throw processException(e);
2725                    }
2726                    finally {
2727                            closeSession(session);
2728                    }
2729    
2730                    if (dlFileEntryMetadata != null) {
2731                            clearCache(dlFileEntryMetadata);
2732                    }
2733    
2734                    return dlFileEntryMetadata;
2735            }
2736    
2737            @Override
2738            public DLFileEntryMetadata updateImpl(
2739                    DLFileEntryMetadata dlFileEntryMetadata) {
2740                    dlFileEntryMetadata = toUnwrappedModel(dlFileEntryMetadata);
2741    
2742                    boolean isNew = dlFileEntryMetadata.isNew();
2743    
2744                    DLFileEntryMetadataModelImpl dlFileEntryMetadataModelImpl = (DLFileEntryMetadataModelImpl)dlFileEntryMetadata;
2745    
2746                    if (Validator.isNull(dlFileEntryMetadata.getUuid())) {
2747                            String uuid = PortalUUIDUtil.generate();
2748    
2749                            dlFileEntryMetadata.setUuid(uuid);
2750                    }
2751    
2752                    Session session = null;
2753    
2754                    try {
2755                            session = openSession();
2756    
2757                            if (dlFileEntryMetadata.isNew()) {
2758                                    session.save(dlFileEntryMetadata);
2759    
2760                                    dlFileEntryMetadata.setNew(false);
2761                            }
2762                            else {
2763                                    dlFileEntryMetadata = (DLFileEntryMetadata)session.merge(dlFileEntryMetadata);
2764                            }
2765                    }
2766                    catch (Exception e) {
2767                            throw processException(e);
2768                    }
2769                    finally {
2770                            closeSession(session);
2771                    }
2772    
2773                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2774    
2775                    if (isNew || !DLFileEntryMetadataModelImpl.COLUMN_BITMASK_ENABLED) {
2776                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2777                    }
2778    
2779                    else {
2780                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2781                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2782                                    Object[] args = new Object[] {
2783                                                    dlFileEntryMetadataModelImpl.getOriginalUuid()
2784                                            };
2785    
2786                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2787                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2788                                            args);
2789    
2790                                    args = new Object[] { dlFileEntryMetadataModelImpl.getUuid() };
2791    
2792                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2793                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2794                                            args);
2795                            }
2796    
2797                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2798                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2799                                    Object[] args = new Object[] {
2800                                                    dlFileEntryMetadataModelImpl.getOriginalUuid(),
2801                                                    dlFileEntryMetadataModelImpl.getOriginalCompanyId()
2802                                            };
2803    
2804                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2805                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2806                                            args);
2807    
2808                                    args = new Object[] {
2809                                                    dlFileEntryMetadataModelImpl.getUuid(),
2810                                                    dlFileEntryMetadataModelImpl.getCompanyId()
2811                                            };
2812    
2813                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2814                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2815                                            args);
2816                            }
2817    
2818                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2819                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID.getColumnBitmask()) != 0) {
2820                                    Object[] args = new Object[] {
2821                                                    dlFileEntryMetadataModelImpl.getOriginalFileEntryId()
2822                                            };
2823    
2824                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID, args);
2825                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
2826                                            args);
2827    
2828                                    args = new Object[] {
2829                                                    dlFileEntryMetadataModelImpl.getFileEntryId()
2830                                            };
2831    
2832                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_FILEENTRYID, args);
2833                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEENTRYID,
2834                                            args);
2835                            }
2836    
2837                            if ((dlFileEntryMetadataModelImpl.getColumnBitmask() &
2838                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID.getColumnBitmask()) != 0) {
2839                                    Object[] args = new Object[] {
2840                                                    dlFileEntryMetadataModelImpl.getOriginalFileVersionId()
2841                                            };
2842    
2843                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_FILEVERSIONID,
2844                                            args);
2845                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID,
2846                                            args);
2847    
2848                                    args = new Object[] {
2849                                                    dlFileEntryMetadataModelImpl.getFileVersionId()
2850                                            };
2851    
2852                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_FILEVERSIONID,
2853                                            args);
2854                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_FILEVERSIONID,
2855                                            args);
2856                            }
2857                    }
2858    
2859                    entityCache.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2860                            DLFileEntryMetadataImpl.class, dlFileEntryMetadata.getPrimaryKey(),
2861                            dlFileEntryMetadata, false);
2862    
2863                    clearUniqueFindersCache(dlFileEntryMetadataModelImpl);
2864                    cacheUniqueFindersCache(dlFileEntryMetadataModelImpl, isNew);
2865    
2866                    dlFileEntryMetadata.resetOriginalValues();
2867    
2868                    return dlFileEntryMetadata;
2869            }
2870    
2871            protected DLFileEntryMetadata toUnwrappedModel(
2872                    DLFileEntryMetadata dlFileEntryMetadata) {
2873                    if (dlFileEntryMetadata instanceof DLFileEntryMetadataImpl) {
2874                            return dlFileEntryMetadata;
2875                    }
2876    
2877                    DLFileEntryMetadataImpl dlFileEntryMetadataImpl = new DLFileEntryMetadataImpl();
2878    
2879                    dlFileEntryMetadataImpl.setNew(dlFileEntryMetadata.isNew());
2880                    dlFileEntryMetadataImpl.setPrimaryKey(dlFileEntryMetadata.getPrimaryKey());
2881    
2882                    dlFileEntryMetadataImpl.setUuid(dlFileEntryMetadata.getUuid());
2883                    dlFileEntryMetadataImpl.setFileEntryMetadataId(dlFileEntryMetadata.getFileEntryMetadataId());
2884                    dlFileEntryMetadataImpl.setCompanyId(dlFileEntryMetadata.getCompanyId());
2885                    dlFileEntryMetadataImpl.setDDMStorageId(dlFileEntryMetadata.getDDMStorageId());
2886                    dlFileEntryMetadataImpl.setDDMStructureId(dlFileEntryMetadata.getDDMStructureId());
2887                    dlFileEntryMetadataImpl.setFileEntryId(dlFileEntryMetadata.getFileEntryId());
2888                    dlFileEntryMetadataImpl.setFileVersionId(dlFileEntryMetadata.getFileVersionId());
2889    
2890                    return dlFileEntryMetadataImpl;
2891            }
2892    
2893            /**
2894             * 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.
2895             *
2896             * @param primaryKey the primary key of the document library file entry metadata
2897             * @return the document library file entry metadata
2898             * @throws NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2899             */
2900            @Override
2901            public DLFileEntryMetadata findByPrimaryKey(Serializable primaryKey)
2902                    throws NoSuchFileEntryMetadataException {
2903                    DLFileEntryMetadata dlFileEntryMetadata = fetchByPrimaryKey(primaryKey);
2904    
2905                    if (dlFileEntryMetadata == null) {
2906                            if (_log.isWarnEnabled()) {
2907                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2908                            }
2909    
2910                            throw new NoSuchFileEntryMetadataException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2911                                    primaryKey);
2912                    }
2913    
2914                    return dlFileEntryMetadata;
2915            }
2916    
2917            /**
2918             * Returns the document library file entry metadata with the primary key or throws a {@link NoSuchFileEntryMetadataException} if it could not be found.
2919             *
2920             * @param fileEntryMetadataId the primary key of the document library file entry metadata
2921             * @return the document library file entry metadata
2922             * @throws NoSuchFileEntryMetadataException if a document library file entry metadata with the primary key could not be found
2923             */
2924            @Override
2925            public DLFileEntryMetadata findByPrimaryKey(long fileEntryMetadataId)
2926                    throws NoSuchFileEntryMetadataException {
2927                    return findByPrimaryKey((Serializable)fileEntryMetadataId);
2928            }
2929    
2930            /**
2931             * Returns the document library file entry metadata with the primary key or returns <code>null</code> if it could not be found.
2932             *
2933             * @param primaryKey the primary key of the document library file entry metadata
2934             * @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
2935             */
2936            @Override
2937            public DLFileEntryMetadata fetchByPrimaryKey(Serializable primaryKey) {
2938                    DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)entityCache.getResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2939                                    DLFileEntryMetadataImpl.class, primaryKey);
2940    
2941                    if (dlFileEntryMetadata == _nullDLFileEntryMetadata) {
2942                            return null;
2943                    }
2944    
2945                    if (dlFileEntryMetadata == null) {
2946                            Session session = null;
2947    
2948                            try {
2949                                    session = openSession();
2950    
2951                                    dlFileEntryMetadata = (DLFileEntryMetadata)session.get(DLFileEntryMetadataImpl.class,
2952                                                    primaryKey);
2953    
2954                                    if (dlFileEntryMetadata != null) {
2955                                            cacheResult(dlFileEntryMetadata);
2956                                    }
2957                                    else {
2958                                            entityCache.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2959                                                    DLFileEntryMetadataImpl.class, primaryKey,
2960                                                    _nullDLFileEntryMetadata);
2961                                    }
2962                            }
2963                            catch (Exception e) {
2964                                    entityCache.removeResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
2965                                            DLFileEntryMetadataImpl.class, primaryKey);
2966    
2967                                    throw processException(e);
2968                            }
2969                            finally {
2970                                    closeSession(session);
2971                            }
2972                    }
2973    
2974                    return dlFileEntryMetadata;
2975            }
2976    
2977            /**
2978             * Returns the document library file entry metadata with the primary key or returns <code>null</code> if it could not be found.
2979             *
2980             * @param fileEntryMetadataId the primary key of the document library file entry metadata
2981             * @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
2982             */
2983            @Override
2984            public DLFileEntryMetadata fetchByPrimaryKey(long fileEntryMetadataId) {
2985                    return fetchByPrimaryKey((Serializable)fileEntryMetadataId);
2986            }
2987    
2988            @Override
2989            public Map<Serializable, DLFileEntryMetadata> fetchByPrimaryKeys(
2990                    Set<Serializable> primaryKeys) {
2991                    if (primaryKeys.isEmpty()) {
2992                            return Collections.emptyMap();
2993                    }
2994    
2995                    Map<Serializable, DLFileEntryMetadata> map = new HashMap<Serializable, DLFileEntryMetadata>();
2996    
2997                    if (primaryKeys.size() == 1) {
2998                            Iterator<Serializable> iterator = primaryKeys.iterator();
2999    
3000                            Serializable primaryKey = iterator.next();
3001    
3002                            DLFileEntryMetadata dlFileEntryMetadata = fetchByPrimaryKey(primaryKey);
3003    
3004                            if (dlFileEntryMetadata != null) {
3005                                    map.put(primaryKey, dlFileEntryMetadata);
3006                            }
3007    
3008                            return map;
3009                    }
3010    
3011                    Set<Serializable> uncachedPrimaryKeys = null;
3012    
3013                    for (Serializable primaryKey : primaryKeys) {
3014                            DLFileEntryMetadata dlFileEntryMetadata = (DLFileEntryMetadata)entityCache.getResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
3015                                            DLFileEntryMetadataImpl.class, primaryKey);
3016    
3017                            if (dlFileEntryMetadata == null) {
3018                                    if (uncachedPrimaryKeys == null) {
3019                                            uncachedPrimaryKeys = new HashSet<Serializable>();
3020                                    }
3021    
3022                                    uncachedPrimaryKeys.add(primaryKey);
3023                            }
3024                            else {
3025                                    map.put(primaryKey, dlFileEntryMetadata);
3026                            }
3027                    }
3028    
3029                    if (uncachedPrimaryKeys == null) {
3030                            return map;
3031                    }
3032    
3033                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3034                                    1);
3035    
3036                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA_WHERE_PKS_IN);
3037    
3038                    for (Serializable primaryKey : uncachedPrimaryKeys) {
3039                            query.append(String.valueOf(primaryKey));
3040    
3041                            query.append(StringPool.COMMA);
3042                    }
3043    
3044                    query.setIndex(query.index() - 1);
3045    
3046                    query.append(StringPool.CLOSE_PARENTHESIS);
3047    
3048                    String sql = query.toString();
3049    
3050                    Session session = null;
3051    
3052                    try {
3053                            session = openSession();
3054    
3055                            Query q = session.createQuery(sql);
3056    
3057                            for (DLFileEntryMetadata dlFileEntryMetadata : (List<DLFileEntryMetadata>)q.list()) {
3058                                    map.put(dlFileEntryMetadata.getPrimaryKeyObj(),
3059                                            dlFileEntryMetadata);
3060    
3061                                    cacheResult(dlFileEntryMetadata);
3062    
3063                                    uncachedPrimaryKeys.remove(dlFileEntryMetadata.getPrimaryKeyObj());
3064                            }
3065    
3066                            for (Serializable primaryKey : uncachedPrimaryKeys) {
3067                                    entityCache.putResult(DLFileEntryMetadataModelImpl.ENTITY_CACHE_ENABLED,
3068                                            DLFileEntryMetadataImpl.class, primaryKey,
3069                                            _nullDLFileEntryMetadata);
3070                            }
3071                    }
3072                    catch (Exception e) {
3073                            throw processException(e);
3074                    }
3075                    finally {
3076                            closeSession(session);
3077                    }
3078    
3079                    return map;
3080            }
3081    
3082            /**
3083             * Returns all the document library file entry metadatas.
3084             *
3085             * @return the document library file entry metadatas
3086             */
3087            @Override
3088            public List<DLFileEntryMetadata> findAll() {
3089                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3090            }
3091    
3092            /**
3093             * Returns a range of all the document library file entry metadatas.
3094             *
3095             * <p>
3096             * 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.
3097             * </p>
3098             *
3099             * @param start the lower bound of the range of document library file entry metadatas
3100             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
3101             * @return the range of document library file entry metadatas
3102             */
3103            @Override
3104            public List<DLFileEntryMetadata> findAll(int start, int end) {
3105                    return findAll(start, end, null);
3106            }
3107    
3108            /**
3109             * Returns an ordered range of all the document library file entry metadatas.
3110             *
3111             * <p>
3112             * 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.
3113             * </p>
3114             *
3115             * @param start the lower bound of the range of document library file entry metadatas
3116             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
3117             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3118             * @return the ordered range of document library file entry metadatas
3119             */
3120            @Override
3121            public List<DLFileEntryMetadata> findAll(int start, int end,
3122                    OrderByComparator<DLFileEntryMetadata> orderByComparator) {
3123                    return findAll(start, end, orderByComparator, true);
3124            }
3125    
3126            /**
3127             * Returns an ordered range of all the document library file entry metadatas.
3128             *
3129             * <p>
3130             * 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.
3131             * </p>
3132             *
3133             * @param start the lower bound of the range of document library file entry metadatas
3134             * @param end the upper bound of the range of document library file entry metadatas (not inclusive)
3135             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3136             * @param retrieveFromCache whether to retrieve from the finder cache
3137             * @return the ordered range of document library file entry metadatas
3138             */
3139            @Override
3140            public List<DLFileEntryMetadata> findAll(int start, int end,
3141                    OrderByComparator<DLFileEntryMetadata> orderByComparator,
3142                    boolean retrieveFromCache) {
3143                    boolean pagination = true;
3144                    FinderPath finderPath = null;
3145                    Object[] finderArgs = null;
3146    
3147                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3148                                    (orderByComparator == null)) {
3149                            pagination = false;
3150                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3151                            finderArgs = FINDER_ARGS_EMPTY;
3152                    }
3153                    else {
3154                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3155                            finderArgs = new Object[] { start, end, orderByComparator };
3156                    }
3157    
3158                    List<DLFileEntryMetadata> list = null;
3159    
3160                    if (retrieveFromCache) {
3161                            list = (List<DLFileEntryMetadata>)finderCache.getResult(finderPath,
3162                                            finderArgs, this);
3163                    }
3164    
3165                    if (list == null) {
3166                            StringBundler query = null;
3167                            String sql = null;
3168    
3169                            if (orderByComparator != null) {
3170                                    query = new StringBundler(2 +
3171                                                    (orderByComparator.getOrderByFields().length * 3));
3172    
3173                                    query.append(_SQL_SELECT_DLFILEENTRYMETADATA);
3174    
3175                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3176                                            orderByComparator);
3177    
3178                                    sql = query.toString();
3179                            }
3180                            else {
3181                                    sql = _SQL_SELECT_DLFILEENTRYMETADATA;
3182    
3183                                    if (pagination) {
3184                                            sql = sql.concat(DLFileEntryMetadataModelImpl.ORDER_BY_JPQL);
3185                                    }
3186                            }
3187    
3188                            Session session = null;
3189    
3190                            try {
3191                                    session = openSession();
3192    
3193                                    Query q = session.createQuery(sql);
3194    
3195                                    if (!pagination) {
3196                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
3197                                                            getDialect(), start, end, false);
3198    
3199                                            Collections.sort(list);
3200    
3201                                            list = Collections.unmodifiableList(list);
3202                                    }
3203                                    else {
3204                                            list = (List<DLFileEntryMetadata>)QueryUtil.list(q,
3205                                                            getDialect(), start, end);
3206                                    }
3207    
3208                                    cacheResult(list);
3209    
3210                                    finderCache.putResult(finderPath, finderArgs, list);
3211                            }
3212                            catch (Exception e) {
3213                                    finderCache.removeResult(finderPath, finderArgs);
3214    
3215                                    throw processException(e);
3216                            }
3217                            finally {
3218                                    closeSession(session);
3219                            }
3220                    }
3221    
3222                    return list;
3223            }
3224    
3225            /**
3226             * Removes all the document library file entry metadatas from the database.
3227             *
3228             */
3229            @Override
3230            public void removeAll() {
3231                    for (DLFileEntryMetadata dlFileEntryMetadata : findAll()) {
3232                            remove(dlFileEntryMetadata);
3233                    }
3234            }
3235    
3236            /**
3237             * Returns the number of document library file entry metadatas.
3238             *
3239             * @return the number of document library file entry metadatas
3240             */
3241            @Override
3242            public int countAll() {
3243                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3244                                    FINDER_ARGS_EMPTY, this);
3245    
3246                    if (count == null) {
3247                            Session session = null;
3248    
3249                            try {
3250                                    session = openSession();
3251    
3252                                    Query q = session.createQuery(_SQL_COUNT_DLFILEENTRYMETADATA);
3253    
3254                                    count = (Long)q.uniqueResult();
3255    
3256                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3257                                            count);
3258                            }
3259                            catch (Exception e) {
3260                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3261                                            FINDER_ARGS_EMPTY);
3262    
3263                                    throw processException(e);
3264                            }
3265                            finally {
3266                                    closeSession(session);
3267                            }
3268                    }
3269    
3270                    return count.intValue();
3271            }
3272    
3273            @Override
3274            public Set<String> getBadColumnNames() {
3275                    return _badColumnNames;
3276            }
3277    
3278            @Override
3279            protected Map<String, Integer> getTableColumnsMap() {
3280                    return DLFileEntryMetadataModelImpl.TABLE_COLUMNS_MAP;
3281            }
3282    
3283            /**
3284             * Initializes the document library file entry metadata persistence.
3285             */
3286            public void afterPropertiesSet() {
3287            }
3288    
3289            public void destroy() {
3290                    entityCache.removeCache(DLFileEntryMetadataImpl.class.getName());
3291                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3292                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3293                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3294            }
3295    
3296            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3297            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3298            private static final String _SQL_SELECT_DLFILEENTRYMETADATA = "SELECT dlFileEntryMetadata FROM DLFileEntryMetadata dlFileEntryMetadata";
3299            private static final String _SQL_SELECT_DLFILEENTRYMETADATA_WHERE_PKS_IN = "SELECT dlFileEntryMetadata FROM DLFileEntryMetadata dlFileEntryMetadata WHERE fileEntryMetadataId IN (";
3300            private static final String _SQL_SELECT_DLFILEENTRYMETADATA_WHERE = "SELECT dlFileEntryMetadata FROM DLFileEntryMetadata dlFileEntryMetadata WHERE ";
3301            private static final String _SQL_COUNT_DLFILEENTRYMETADATA = "SELECT COUNT(dlFileEntryMetadata) FROM DLFileEntryMetadata dlFileEntryMetadata";
3302            private static final String _SQL_COUNT_DLFILEENTRYMETADATA_WHERE = "SELECT COUNT(dlFileEntryMetadata) FROM DLFileEntryMetadata dlFileEntryMetadata WHERE ";
3303            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileEntryMetadata.";
3304            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileEntryMetadata exists with the primary key ";
3305            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileEntryMetadata exists with the key {";
3306            private static final Log _log = LogFactoryUtil.getLog(DLFileEntryMetadataPersistenceImpl.class);
3307            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3308                                    "uuid"
3309                            });
3310            private static final DLFileEntryMetadata _nullDLFileEntryMetadata = new DLFileEntryMetadataImpl() {
3311                            @Override
3312                            public Object clone() {
3313                                    return this;
3314                            }
3315    
3316                            @Override
3317                            public CacheModel<DLFileEntryMetadata> toCacheModel() {
3318                                    return _nullDLFileEntryMetadataCacheModel;
3319                            }
3320                    };
3321    
3322            private static final CacheModel<DLFileEntryMetadata> _nullDLFileEntryMetadataCacheModel =
3323                    new CacheModel<DLFileEntryMetadata>() {
3324                            @Override
3325                            public DLFileEntryMetadata toEntityModel() {
3326                                    return _nullDLFileEntryMetadata;
3327                            }
3328                    };
3329    }