Package de.xima.fc.logic.filesystem
Class FileEntityViewPersistenceAdapter<View extends IFileEntityView,File extends IFileEntity<?,Data> & IFileSizeProviding,Data extends IFileDataEntity<File>,Context>
- java.lang.Object
-
- de.xima.fc.logic.filesystem.FileEntityViewPersistenceAdapter<View,File,Data,Context>
-
- Type Parameters:
View
- The type of the view.File
- The type of the file entity.Data
- The type of the file data entity.Context
- The type of the context for the entities.
- All Implemented Interfaces:
ICrudPersistenceAdapter<IEntityContext,View>
,IFileDataPersistenceAdapter<IEntityContext,View>
,IScopedEntityPersistenceAdapter<IEntityContext,View,Context>
,IEntityFileSystemPersistenceAdapter<IEntityContext,View,Context>
,Serializable
- Direct Known Subclasses:
FormThemeFileViewPersistenceAdapter
public abstract class FileEntityViewPersistenceAdapter<View extends IFileEntityView,File extends IFileEntity<?,Data> & IFileSizeProviding,Data extends IFileDataEntity<File>,Context> extends Object implements IEntityFileSystemPersistenceAdapter<IEntityContext,View,Context>
Afile entity adapter
for a view of afile entity
.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FileEntityViewPersistenceAdapter(Class<View> dtoClass, Class<File> fileEntityType, Class<Data> fileDataEntityType)
Creates afile entity adapter
for a generalfile entity
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addSelectCriteria(de.xima.cmn.criteria.AttributeSelectCriteriaManager acm)
Adds additional select criteria for extra attributes needed to construct the view.protected void
addUpdateCriteria(IEntityContext ec, de.xima.cmn.criteria.UpdateCriteriaManager ucm, View view)
Adds additional update criteria for extra attributes that need to be updated when updating the entity.View
create(IEntityContext ec, View view)
Persists the file entity in the database and returns the persisted entity.protected abstract de.xima.cmn.criteria.FilterCriterion
createContextualFilter(Context context)
Creates the filter to limit the database query to the given context.void
delete(IEntityContext ec, View view)
Deletes the file entity and all its children (such as file data).protected void
fillEmptyEntity(IEntityContext ec, File entity, View view)
protected void
hydrateView(View view, javax.persistence.Tuple tuple)
Hydrates the view with additional attributes from the loaded tuple.protected boolean
ignoreLockingVersion()
When set to true, the locking version is ignored.List<View>
list(IEntityContext ec, Context context)
Reads all file entities that exist in the given context.protected File
newEntity()
Creates a new empty instance of the entity.protected View
newView()
Creates a new empty instance of the view.InputStream
openForRead(Supplier<IEntityContext> ec, View view)
Opens an input stream to the content of a file entity.OutputStream
openForWrite(Supplier<IEntityContext> ec, View view)
Opens an output stream for changing the content of a file entity.View
read(IEntityContext ec, View view)
Reads the entity from the persistence layer, returning a fresh version of the entity.View
update(IEntityContext ec, View view)
Updates the file entity in the persistence layer and returns the updated entity.
-
-
-
Constructor Detail
-
FileEntityViewPersistenceAdapter
protected FileEntityViewPersistenceAdapter(Class<View> dtoClass, Class<File> fileEntityType, Class<Data> fileDataEntityType)
Creates afile entity adapter
for a generalfile entity
.- Parameters:
fileEntityType
- The type of the file entity.fileDataEntityType
- The type of the file data entity.
-
-
Method Detail
-
create
public final View create(IEntityContext ec, View view)
Description copied from interface:ICrudPersistenceAdapter
Persists the file entity in the database and returns the persisted entity.- Specified by:
create
in interfaceICrudPersistenceAdapter<View extends IFileEntityView,File extends IFileEntity<?,Data> & IFileSizeProviding>
- Parameters:
ec
- Persistence context to use for accessing the database.view
- The entity to create.- Returns:
- The persisted entity.
-
delete
public final void delete(IEntityContext ec, View view)
Description copied from interface:ICrudPersistenceAdapter
Deletes the file entity and all its children (such as file data).- Specified by:
delete
in interfaceICrudPersistenceAdapter<View extends IFileEntityView,File extends IFileEntity<?,Data> & IFileSizeProviding>
- Parameters:
ec
- Persistence context to use for accessing the persistence layer.view
- The entity to delete.
-
list
public final List<View> list(IEntityContext ec, Context context)
Description copied from interface:IScopedEntityPersistenceAdapter
Reads all file entities that exist in the given context.- Specified by:
list
in interfaceIScopedEntityPersistenceAdapter<View extends IFileEntityView,File extends IFileEntity<?,Data> & IFileSizeProviding,Data extends IFileDataEntity<File>>
- Parameters:
ec
- Persistence context to use for accessing the persistence layer.context
- The context in which to read the entities, such as a client or project.- Returns:
- A list of all file entities in the context.
-
openForRead
public final InputStream openForRead(Supplier<IEntityContext> ec, View view) throws IOException
Description copied from interface:IFileDataPersistenceAdapter
Opens an input stream to the content of a file entity.- Specified by:
openForRead
in interfaceIFileDataPersistenceAdapter<View extends IFileEntityView,File extends IFileEntity<?,Data> & IFileSizeProviding>
- Parameters:
ec
- Persistence context factory to use for accessing the persistence layer.view
- The entity to open.- Returns:
- An input stream to the file content.
- Throws:
IOException
- If an error occurs while opening the file.
-
openForWrite
public final OutputStream openForWrite(Supplier<IEntityContext> ec, View view) throws IOException
Description copied from interface:IFileDataPersistenceAdapter
Opens an output stream for changing the content of a file entity. This should also update the file metadata, such as the user who last modified the file and the last modified time.- Specified by:
openForWrite
in interfaceIFileDataPersistenceAdapter<View extends IFileEntityView,File extends IFileEntity<?,Data> & IFileSizeProviding>
- Parameters:
ec
- Persistence context factory to use for accessing the persistence layer.view
- The entity to open.- Returns:
- An output stream to the file content.
- Throws:
IOException
- If an error occurs while opening the file.
-
read
public final View read(IEntityContext ec, View view)
Description copied from interface:ICrudPersistenceAdapter
Reads the entity from the persistence layer, returning a fresh version of the entity.- Specified by:
read
in interfaceICrudPersistenceAdapter<View extends IFileEntityView,File extends IFileEntity<?,Data> & IFileSizeProviding>
- Parameters:
ec
- Persistence context to use for accessing the persistence layer.view
- The entity to read.- Returns:
- The entity read from the persistence layer.
-
update
public final View update(IEntityContext ec, View view)
Description copied from interface:ICrudPersistenceAdapter
Updates the file entity in the persistence layer and returns the updated entity.- Specified by:
update
in interfaceICrudPersistenceAdapter<View extends IFileEntityView,File extends IFileEntity<?,Data> & IFileSizeProviding>
- Parameters:
ec
- Persistence context to use for accessing the database.view
- The entity to update.- Returns:
- The updated entity.
-
addSelectCriteria
protected void addSelectCriteria(de.xima.cmn.criteria.AttributeSelectCriteriaManager acm)
Adds additional select criteria for extra attributes needed to construct the view. The default implementation does not add any additional criteria.- Parameters:
acm
- The attribute select criteria manager to which to add the criteria.
-
addUpdateCriteria
protected void addUpdateCriteria(IEntityContext ec, de.xima.cmn.criteria.UpdateCriteriaManager ucm, View view)
Adds additional update criteria for extra attributes that need to be updated when updating the entity. The default implementation does not add any additional criteria.- Parameters:
ucm
- The update criteria manager to which to add the criteria.view
- The view from which to take the values.
-
createContextualFilter
protected abstract de.xima.cmn.criteria.FilterCriterion createContextualFilter(Context context)
Creates the filter to limit the database query to the given context.- Parameters:
context
- The context to which to limit the query.- Returns:
- The contextual filter.
-
fillEmptyEntity
protected void fillEmptyEntity(IEntityContext ec, File entity, View view)
-
hydrateView
protected void hydrateView(View view, javax.persistence.Tuple tuple)
Hydrates the view with additional attributes from the loaded tuple. Should be compatible withaddSelectCriteria
. The default implementation does not hydrate any additional attributes.- Parameters:
view
- The view to hydrate.tuple
- The tuple from which to take the values.
-
ignoreLockingVersion
protected boolean ignoreLockingVersion()
When set to true, the locking version is ignored. When set to false, an exception is thrown when the locking version does not match.- Returns:
- Whether to ignore the locking version.
-
newEntity
protected File newEntity()
Creates a new empty instance of the entity. The default implementation uses reflection to create a new instance via the default constructor. You may override this method if the class does not have a default constructor or to provide a more efficient way to create a new instance.- Returns:
- A new instance of the entity.
-
newView
protected View newView()
Creates a new empty instance of the view. The default implementation uses reflection to create a new instance via the default constructor. You may override this method if the class does not have a default constructor or to provide a more efficient way to create a new instance.- Returns:
- A new instance of the view.
-
-