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