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