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