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