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