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.
EntityFactoryfor creation of instances and transforming them into dtosEntityInformationfor accessing an entity metadataPrinterfor generating the labelFunctionfor save and find methodsConsumerfor delete method
- Author:
- Arne Vandamme
- See Also:
-
EntityFactoryEntityInformationPrinter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConvert an existing entity into a dto.Create a new instance of the entity type this model represents.voidDeletes 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.booleanSaves an entity.voidsetDeleteMethod(@NonNull Consumer<T> deleteMethod) Set the callback method to be used when deleting an entity.voidsetEntityFactory(@NonNull EntityFactory<T> entityFactory) Set theEntityFactorydelegate that should be used for creating a new instance or converting an existing instance to a dto.voidsetEntityInformation(@NonNull org.springframework.data.repository.core.EntityInformation<T, U> entityInformation) Set the metadata provider for this entity type.voidsetFindOneMethod(@NonNull Function<U, T> findOneMethod) Set the callback method to be used for finding a single entity based on its id.voidsetLabelPrinter(@NonNull org.springframework.format.Printer<T> labelPrinter) Set the printer to be used for calls togetLabel(Object)andgetLabel(Object, Locale).voidsetSaveMethod(@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, waitMethods 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:EntityModelGenerates a label for the entity and the default locale attached to the thread.- Specified by:
getLabelin interfaceEntityModel<T,U extends Serializable> - Parameters:
entity- to generate the label for- Returns:
- label
-
getLabel
Description copied from interface:EntityModelGenerates a label for the entity and the locale specified.- Specified by:
getLabelin interfaceEntityModel<T,U extends Serializable> - Parameters:
entity- to generate the label forlocale- to use for formatting- Returns:
- label
-
setEntityFactory
Set theEntityFactorydelegate 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:EntityModelCreate 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:
createNewin interfaceEntityFactory<T>- Specified by:
createNewin interfaceEntityModel<T,U extends Serializable> - Parameters:
args- optional list of arguments (eg. constructor parameters)- Returns:
- newly created entity
-
createDto
Description copied from interface:EntityModelConvert an existing entity into a dto. Used by default views to ensure operations are not done on managed entities.- Specified by:
createDtoin interfaceEntityFactory<T>- Specified by:
createDtoin 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:EntityModelFind a single entity based on its unique id.- Specified by:
findOnein 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:EntityModelSaves 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:
savein 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:EntityModelDeletes the given entity.- Specified by:
deletein 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:
isNewin interfaceorg.springframework.data.repository.core.EntityInformation<T,U extends Serializable>
-
getId
- Specified by:
getIdin interfaceorg.springframework.data.repository.core.EntityInformation<T,U extends Serializable>
-
getIdType
- Specified by:
getIdTypein interfaceorg.springframework.data.repository.core.EntityInformation<T,U extends Serializable>
-
getJavaType
- Specified by:
getJavaTypein interfaceorg.springframework.data.repository.core.EntityMetadata<T>
-