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