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