Interface IGenericFileDao
- All Known Implementing Classes:
GenericFileDao
- Since:
- 8.0.0
- Author:
- XIMA MEDIA GmbH
-
Method Summary
Modifier and TypeMethodDescription<Data extends IFileDataEntity<?>>
EntityIdWithLockingVersiongetDataEntityLockingVersion(IEntityContext ec, Class<Data> dataClass, IFileEntity<?, Data> fileEntity) Gets the ID and locking version of the data entity for the given file entity.<Data extends IFileDataEntity<?>>
EntityIdWithLockingVersiongetDataEntityLockingVersion(IEntityContext ec, Class<Data> dataClass, IFileProviding<?, Data> fileProviding) Gets the ID and locking version of the data entity for the given file entity.<D extends IFileDataEntity<F>, F extends IKeyDependentFileEntity<E,D>, E extends IFileMapProviding<F, D>>
byte[]getFileData(IEntityContext ec, E entity, String fileKey) Returns the file data of a file belonging to the given entity with the given file key.<E extends IFileDataEntity<?>, T extends IFileProviding<?,E>>
byte[]getFileData(IEntityContext ec, Class<T> entityClass, long id) Returns the file data of a file entity.<E extends IFileDataEntity<?>, T extends IFileProviding<?,E>>
byte[]getFileData(IEntityContext ec, T entity) Returns the file data of a file entity.<D extends IFileDataEntity<F>, F extends IKeyDependentFileEntity<E,D>, E extends IFileMapProviding<F, D>>
DgetFileDataEntity(IEntityContext ec, E entity, String fileKey) Returns the file data entity of a file belonging to the given entity with the given file key.<E extends IFileDataEntity<?>, T extends IFileEntity<?,E>>
EgetFileDataEntity(IEntityContext ec, T entity) Get the file data entity for a given file entity.<FileData extends IFileDataEntity<?>>
byte[]getFileEntityData(IEntityContext ec, Class<FileData> fileDataEntityType, de.xima.cmn.criteria.FilterCriterion filter) <T extends IFileEntity<?,?>>
byte[]getFileEntityData(IEntityContext ec, T fileEntity) Gets the data of the given file entity as an in-memory byte array.<TFileMeta extends IFileMetaEntity<?,?>>
byte[]getFileEntityData(IEntityContext ec, TFileMeta fileEntity) Returns the file data of the given file entity.<FileData extends IFileDataEntity<?>>
InputStreamgetFileEntityStream(IEntityContext ec, Class<FileData> fileDataEntityType, de.xima.cmn.criteria.FilterCriterion filter) <T extends IFileEntity<?,?>>
InputStreamgetFileEntityStream(IEntityContext ec, T fileEntity) Gets the data of the given file entity as an input stream.<TFileMeta extends IFileMetaEntity<?,?>>
InputStreamgetFileEntityStream(IEntityContext ec, TFileMeta fileEntity) Returns the file data of the given file entity as an input stream.<D extends IFileDataEntity<F>, F extends IKeyDependentFileEntity<E,D>, E extends IFileMapProviding<F, D>>
InputStreamgetFileStream(IEntityContext ec, E entity, String fileKey) Returns the file data of a file belonging to the given entity with the given file key, as an input stream.<E extends IFileDataEntity<?>, T extends IFileProviding<?,E>>
InputStreamgetFileStream(IEntityContext ec, T entity) openFileEntityStreamLazy(Supplier<IEntityContext> ec, Class<? extends IFileDataEntity<?>> fileDataEntityType, Long fileEntityId) Opens an input stream to the file data of the given file entity.<FileEntity extends IFileEntity<?, FileDataEntity>, FileDataEntity extends IFileDataEntity<FileEntity>>
InputStreamopenFileEntityStreamLazy(Supplier<IEntityContext> ec, Class<FileDataEntity> fileDataEntityType, FileEntity fileEntity) Opens an input stream to the file data of the given file entity.openFileEntityStreamOutputStreamLazy(Supplier<IEntityContext> entityContextFactory, Class<? extends IFileEntity<?, ?>> fileEntityType, Class<? extends IFileDataEntity<?>> fileDataEntityType, Long fileEntityId, Integer fileEntityLockingVersion, Integer fileDataEntityLockingVersion) Opens an output stream for updating the given file entity with the data.voidupdateFileData(IEntityContext ec, Class<? extends IFileDataEntity<?>> fileEntityType, long fileEntityId, InputStream data) Replaces the data of the given file entity with the new data.<E extends IFileDataEntity<?>, T extends IFileEntity<?,E>>
TupdateFileData(IEntityContext ec, T entity, byte[] data) Replaces the data of the given file entity with the new data.
-
Method Details
-
getFileData
<E extends IFileDataEntity<?>, T extends IFileProviding<?,E>> byte[] getFileData(IEntityContext ec, Class<T> entityClass, long id) Returns the file data of a file entity.Use with care! As the name suggests, this holds the entire file data in memory. Prefer
using an input streaminstead.- Type Parameters:
E- Type of the entity with the file data.T- Type of the entity with the file metadata.- Parameters:
ec- Entity context for database transactions.entityClass- Type of the file entity with the file metadata.id- ID of the file entity with the file metadata.- Returns:
- The file content as a byte array, or
nullwhen no file content was found.
-
getFileData
<E extends IFileDataEntity<?>, T extends IFileProviding<?,E>> byte[] getFileData(IEntityContext ec, T entity) Returns the file data of a file entity.Use with care! As the name suggests, this holds the entire file data in memory. Prefer
using an input streaminstead.- Type Parameters:
E- Type of the entity with the file data.T- Type of the entity with the file metadata.- Parameters:
ec- Entity context for database transactions.entity- File entity with the file metadata.- Returns:
- The file content as a byte array.
-
getFileData
<D extends IFileDataEntity<F>, F extends IKeyDependentFileEntity<E,D>, E extends IFileMapProviding<F, byte[] getFileDataD>> (IEntityContext ec, E entity, String fileKey) Returns the file data of a file belonging to the given entity with the given file key.Use with care! As the name suggests, this holds the entire file data in memory. Prefer
using an input streaminstead.- Type Parameters:
D- file data entity typeF- file entity typeE- file map providing base entity type- Parameters:
ec- entity context for database transactions.entity- that owns the filefileKey- Key identifying the file to retrieve.- Returns:
- The file data as a byte array.
- Since:
- 7.1.0
-
getFileStream
<D extends IFileDataEntity<F>, F extends IKeyDependentFileEntity<E,D>, E extends IFileMapProviding<F, InputStream getFileStreamD>> (IEntityContext ec, E entity, String fileKey) Returns the file data of a file belonging to the given entity with the given file key, as an input stream.- Type Parameters:
D- file data entity typeF- file entity typeE- file map providing base entity type- Parameters:
ec- entity context for database transactions.entity- that owns the filefileKey- Key identifying the file to retrieve.- Returns:
- The file data as an input stream.
- Since:
- 8.0.0
-
updateFileData
<E extends IFileDataEntity<?>, T extends IFileEntity<?,E>> T updateFileData(IEntityContext ec, T entity, byte[] data) Replaces the data of the given file entity with the new data.- Type Parameters:
E- Type of the entity with the file data.T- Type of the entity with the file metadata.- Parameters:
ec- Entity context for database transactions.entity- File entity with the file metadata.data- New data to set.- Returns:
- The updated file entity.
-
updateFileData
void updateFileData(IEntityContext ec, Class<? extends IFileDataEntity<?>> fileEntityType, long fileEntityId, InputStream data) throws IOException Replaces the data of the given file entity with the new data. Does not read the file data entity into memory, it won't be part of the entity manager's cache.- Parameters:
ec- Entity context for database transactions.fileEntityType- Type of the file entity with the file metadata.fileEntityId- ID of the file entity that contains the data entity.data- New data to set.- Throws:
IOException
-
getFileDataEntity
<E extends IFileDataEntity<?>, T extends IFileEntity<?,E>> E getFileDataEntity(IEntityContext ec, T entity) Get the file data entity for a given file entity. The entity is read from the database if it is detached.- Type Parameters:
E- Type of the entity with the file data.T- Type of the entity with the file metadata.- Parameters:
ec- Entity context for database transactions.entity- File entity with the file metadata.- Returns:
- The file data entity for the given file entity.
-
getFileDataEntity
<D extends IFileDataEntity<F>, F extends IKeyDependentFileEntity<E,D>, E extends IFileMapProviding<F, D getFileDataEntityD>> (IEntityContext ec, E entity, String fileKey) Returns the file data entity of a file belonging to the given entity with the given file key.- Type Parameters:
D- file data entity typeF- file entity typeE- file map providing base entity type- Parameters:
ec- Entity context for database transactions.entity- that owns the filefileKey- key identifying the file entity- Returns:
- file data entity containing the data of the request file.
- Since:
- 8.0.0
-
getFileStream
<E extends IFileDataEntity<?>, T extends IFileProviding<?,E>> InputStream getFileStream(IEntityContext ec, T entity) - Type Parameters:
E- Type of the entity with the file data.T- Type of the entity with the file metadata.- Parameters:
ec- Entity context for database transactions.entity- File entity with the file metadata.- Returns:
- The data of the file entity as an input stream, or
nullwhen no data exists.
-
getFileEntityData
Gets the data of the given file entity as an in-memory byte array.Use with care! As the name suggests, this holds the entire file data in memory. Prefer
using an input streaminstead.- Type Parameters:
T- Type of the file entity with the data.- Parameters:
ec- Entity context for database transactions.fileEntity- File entity with the data.- Returns:
- The data as a byte array, or
nullif no data exists.
-
getFileEntityData
<FileData extends IFileDataEntity<?>> byte[] getFileEntityData(IEntityContext ec, Class<FileData> fileDataEntityType, de.xima.cmn.criteria.FilterCriterion filter) -
getFileEntityData
<TFileMeta extends IFileMetaEntity<?,?>> byte[] getFileEntityData(IEntityContext ec, TFileMeta fileEntity) Returns the file data of the given file entity.- Type Parameters:
TFileMeta- type of file entity.- Parameters:
ec- entity context for database transactions.fileEntity- that owns the file data.- Returns:
- binary data of the file or
nullif no data exists. - Since:
- 8.2.0
-
getFileEntityStream
<TFileMeta extends IFileMetaEntity<?,?>> InputStream getFileEntityStream(IEntityContext ec, TFileMeta fileEntity) Returns the file data of the given file entity as an input stream.- Type Parameters:
TFileMeta- type of file entity.- Parameters:
ec- entity context for database transactions.fileEntity- that owns the file data.- Returns:
- input stream of the file data or
nullif no data exists. - Since:
- 8.2.0
-
getFileEntityStream
Gets the data of the given file entity as an input stream.- Type Parameters:
T- Type of the file entity with the data.- Parameters:
ec- Entity context for database transactions.fileEntity- File entity with the data.- Returns:
- The data as an input stream, or
nullif no data exists. - Since:
- 8.0.0
-
getFileEntityStream
<FileData extends IFileDataEntity<?>> InputStream getFileEntityStream(IEntityContext ec, Class<FileData> fileDataEntityType, de.xima.cmn.criteria.FilterCriterion filter) -
openFileEntityStreamLazy
<FileEntity extends IFileEntity<?, FileDataEntity>, FileDataEntity extends IFileDataEntity<FileEntity>> InputStream openFileEntityStreamLazy(Supplier<IEntityContext> ec, Class<FileDataEntity> fileDataEntityType, FileEntity fileEntity) throws IOException Opens an input stream to the file data of the given file entity.Similar to
getFileEntityStream(IEntityContext, IFileEntity), but does not access the file data entity directly. That would cause the file data entity to be initialized with the file content. If you keep a list offile entitiesin memory, this would cause the data to be associated with those file entities, effectively loading all files into RAM. Instead, this method reads the file data directly.Note: this method assumes that the
IFileEntityonly ever has a singleIFileDataEntity.- Type Parameters:
FileEntity- Type of the file entity with the data.FileDataEntity- Type of the file data entity.- Parameters:
ec- Factory for the entity context for database transactions.fileDataEntityType- Type of the file data entity.fileEntity- File entity with the data.- Returns:
- The data as an input stream, or null if no data exists.
- Throws:
IOException- If an I/O error occurs while opening the input stream.
-
openFileEntityStreamLazy
InputStream openFileEntityStreamLazy(Supplier<IEntityContext> ec, Class<? extends IFileDataEntity<?>> fileDataEntityType, Long fileEntityId) throws IOException Opens an input stream to the file data of the given file entity.Similar to
getFileEntityStream(IEntityContext, IFileEntity), but does not access the file data entity directly. That would cause the file data entity to be initialized with the file content. If you keep a list offile entitiesin memory, this would cause the data to be associated with those file entities, effectively loading all files into RAM. Instead, this method reads the file data directly.Note: this method assumes that the
IFileEntityonly ever has a singleIFileDataEntity.- Parameters:
ec- Factory for the entity context for database transactions.fileDataEntityType- Type of the file data entity.fileEntityId- ID of the file entity with the data.- Returns:
- The data as an input stream, or null if no data exists.
- Throws:
IOException- If an I/O error occurs while opening the input stream.
-
getDataEntityLockingVersion
<Data extends IFileDataEntity<?>> EntityIdWithLockingVersion getDataEntityLockingVersion(IEntityContext ec, Class<Data> dataClass, IFileEntity<?, Data> fileEntity) Gets the ID and locking version of the data entity for the given file entity.- Type Parameters:
Data- Type of the data entity.- Parameters:
ec- Entity context for accessing the database.dataClass- Class of the data entity.fileEntity- File entity containing the data entity.- Returns:
- ID and locking version of the data entity, or null if the file does not exist.
-
getDataEntityLockingVersion
<Data extends IFileDataEntity<?>> EntityIdWithLockingVersion getDataEntityLockingVersion(IEntityContext ec, Class<Data> dataClass, IFileProviding<?, Data> fileProviding) Gets the ID and locking version of the data entity for the given file entity.- Type Parameters:
Data- Type of the data entity.- Parameters:
ec- Entity context for accessing the database.dataClass- Class of the data entity.fileProviding- Entity providing a file entity.- Returns:
- ID and locking version of the data entity, or null if the file does not exist.
-
openFileEntityStreamOutputStreamLazy
OutputStream openFileEntityStreamOutputStreamLazy(Supplier<IEntityContext> entityContextFactory, Class<? extends IFileEntity<?, ?>> fileEntityType, Class<? extends IFileDataEntity<?>> fileDataEntityType, Long fileEntityId, Integer fileEntityLockingVersion, Integer fileDataEntityLockingVersion) throws IOExceptionOpens an output stream for updating the given file entity with the data.Does not access the file data entity directly. That would cause the file data entity to be initialized with the file content. If you keep a list of
file entitiesin memory, this would cause the data to be associated with those file entities, effectively loading all files into RAM. Instead, this method updates the file data directly.Note 1: this method assumes that the
IFileEntityonly ever has a singleIFileDataEntity.Note 2: After a call to this method, existing
entity managersmay be out-of-sync. You should discard the entity manager after calling this method; or at leastclearorrefresh/EntityManager.detach(Object)the file entity.- Parameters:
entityContextFactory- Factory for the entity context to use for database transactions.fileEntityType- Type of the file entity with the data.fileDataEntityType- Type of the file data entity.fileEntityId- ID of the file entity with the data.fileEntityLockingVersion- Locking version of the file entity. When given, updates only if the version in the database matches this version.fileDataEntityLockingVersion- Locking version of the file data entity. When given, updates only if the version in the database matches this version.- Returns:
- An output stream for writing the new data.
- Throws:
IOException- If an I/O error occurs while reading the input stream.
-