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