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