Class DefaultEntityModel<T,U extends Serializable>
java.lang.Object
com.foreach.across.modules.entity.registry.DefaultEntityModel<T,U>
- Type Parameters:
T
- entity typeU
- id type of the entity
- All Implemented Interfaces:
EntityFactory<T>
,EntityModel<T,
,U> org.springframework.data.repository.core.EntityInformation<T,
,U> org.springframework.data.repository.core.EntityMetadata<T>
public class DefaultEntityModel<T,U extends Serializable>
extends Object
implements EntityModel<T,U>
Default implementation of
EntityModel
that allows customizing the different methods
using callbacks and delegate instances.
EntityFactory
for creation of instances and transforming them into dtosEntityInformation
for accessing an entity metadataPrinter
for generating the labelFunction
for save and find methodsConsumer
for delete method
- Author:
- Arne Vandamme
- See Also:
-
EntityFactory
EntityInformation
Printer
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionConvert an existing entity into a dto.Create a new instance of the entity type this model represents.void
Deletes the given entity.Find a single entity based on its unique id.Generates a label for the entity and the default locale attached to the thread.Generates a label for the entity and the locale specified.boolean
Saves an entity.void
setDeleteMethod
(@NonNull Consumer<T> deleteMethod) Set the callback method to be used when deleting an entity.void
setEntityFactory
(@NonNull EntityFactory<T> entityFactory) Set theEntityFactory
delegate that should be used for creating a new instance or converting an existing instance to a dto.void
setEntityInformation
(@NonNull org.springframework.data.repository.core.EntityInformation<T, U> entityInformation) Set the metadata provider for this entity type.void
setFindOneMethod
(@NonNull Function<U, T> findOneMethod) Set the callback method to be used for finding a single entity based on its id.void
setLabelPrinter
(@NonNull org.springframework.format.Printer<T> labelPrinter) Set the printer to be used for calls togetLabel(Object)
andgetLabel(Object, Locale)
.void
setSaveMethod
(@NonNull UnaryOperator<T> saveMethod) Set the callback method to be used for saving a single entity.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.repository.core.EntityInformation
getRequiredId
-
Constructor Details
-
DefaultEntityModel
public DefaultEntityModel()
-
-
Method Details
-
setLabelPrinter
Set the printer to be used for calls togetLabel(Object)
andgetLabel(Object, Locale)
.- Parameters:
labelPrinter
- instance
-
getLabel
Description copied from interface:EntityModel
Generates a label for the entity and the default locale attached to the thread.- Specified by:
getLabel
in interfaceEntityModel<T,
U extends Serializable> - Parameters:
entity
- to generate the label for- Returns:
- label
-
getLabel
Description copied from interface:EntityModel
Generates a label for the entity and the locale specified.- Specified by:
getLabel
in interfaceEntityModel<T,
U extends Serializable> - Parameters:
entity
- to generate the label forlocale
- to use for formatting- Returns:
- label
-
setEntityFactory
Set theEntityFactory
delegate that should be used for creating a new instance or converting an existing instance to a dto.- Parameters:
entityFactory
- instance
-
createNew
Description copied from interface:EntityModel
Create a new instance of the entity type this model represents. Optionally a number of arguments can be passed, however for basic entity views the model should support a new instance without any arguments.- Specified by:
createNew
in interfaceEntityFactory<T>
- Specified by:
createNew
in interfaceEntityModel<T,
U extends Serializable> - Parameters:
args
- optional list of arguments (eg. constructor parameters)- Returns:
- newly created entity
-
createDto
Description copied from interface:EntityModel
Convert an existing entity into a dto. Used by default views to ensure operations are not done on managed entities.- Specified by:
createDto
in interfaceEntityFactory<T>
- Specified by:
createDto
in interfaceEntityModel<T,
U extends Serializable> - Parameters:
entity
- to convert into a dto- Returns:
- dto of the entity
-
setFindOneMethod
Set the callback method to be used for finding a single entity based on its id.- Parameters:
findOneMethod
- callback
-
findOne
Description copied from interface:EntityModel
Find a single entity based on its unique id.- Specified by:
findOne
in interfaceEntityModel<T,
U extends Serializable> - Parameters:
id
- of the entity- Returns:
- entity or null if not found
-
setSaveMethod
Set the callback method to be used for saving a single entity.- Parameters:
saveMethod
- callback
-
save
Description copied from interface:EntityModel
Saves an entity. Depending on the entity information this will perform an update or a create. The return value depends on the implementation but in default cases the entity passed in will be detached (dto) and the return value will be the managed entity.- Specified by:
save
in interfaceEntityModel<T,
U extends Serializable> - Parameters:
entity
- to save- Returns:
- saved entity
-
setDeleteMethod
Set the callback method to be used when deleting an entity.- Parameters:
deleteMethod
- callback
-
delete
Description copied from interface:EntityModel
Deletes the given entity.- Specified by:
delete
in interfaceEntityModel<T,
U extends Serializable> - Parameters:
entity
- to delete
-
setEntityInformation
public void setEntityInformation(@NonNull @NonNull org.springframework.data.repository.core.EntityInformation<T, U> entityInformation) Set the metadata provider for this entity type.- Parameters:
entityInformation
- implementation
-
isNew
- Specified by:
isNew
in interfaceorg.springframework.data.repository.core.EntityInformation<T,
U extends Serializable>
-
getId
- Specified by:
getId
in interfaceorg.springframework.data.repository.core.EntityInformation<T,
U extends Serializable>
-
getIdType
- Specified by:
getIdType
in interfaceorg.springframework.data.repository.core.EntityInformation<T,
U extends Serializable>
-
getJavaType
- Specified by:
getJavaType
in interfaceorg.springframework.data.repository.core.EntityMetadata<T>
-