Interface EntityFactory<T>
- Type Parameters:
T
- type of the entity
- All Known Subinterfaces:
EntityModel<T,
U>
- All Known Implementing Classes:
DefaultEntityModel
,DtoAwarePersistentEntityFactory
,PersistentEntityFactory
public interface EntityFactory<T>
Interface that provides factory methods for creating a new entity instance,
or a DTO (detached) instance of an existing entity.
-
Method Summary
Modifier and TypeMethodDescriptionCreate a DTO of an existing entity.Create a new entity instance.static <T> EntityFactory<T>
Create a defaultEntityFactory
which uses theconstructorFunction
for creating a new instance, and thedtoFunction
for creating a DTO.static <T> EntityFactory<T>
Create a defaultEntityFactory
which uses thesupplier
for creating a new instance.static <T> EntityFactory<T>
Create a defaultEntityFactory
which uses thesupplier
for creating a new instance, and thedtoFunction
for creating a DTO.
-
Method Details
-
createNew
Create a new entity instance. In case of anEntityFactory
for an association, the first (and often only) argument will be the parent entity.- Parameters:
args
- constructor arguments- Returns:
- new instance
-
createDto
Create a DTO of an existing entity.- Parameters:
entity
- to create a DTO for- Returns:
- dto
-
of
Create a defaultEntityFactory
which uses thesupplier
for creating a new instance. For creating a DTO that same supplier will be used to first create a new instance and then copy all public properties to the DTO.- Type Parameters:
T
- entity type- Parameters:
supplier
- for creating a new instance- Returns:
- factory
-
of
Create a defaultEntityFactory
which uses thesupplier
for creating a new instance, and thedtoFunction
for creating a DTO.- Type Parameters:
T
- entity type- Parameters:
supplier
- for creating a new instancedtoFunction
- for creating a DTO- Returns:
- factory
-
of
static <T> EntityFactory<T> of(@NonNull @NonNull Function<Object[], T> constructorFunction, Function<T, T> dtoFunction) Create a defaultEntityFactory
which uses theconstructorFunction
for creating a new instance, and thedtoFunction
for creating a DTO.- Type Parameters:
T
- entity type- Parameters:
constructorFunction
- for creating a new instancedtoFunction
- for creating a dto- Returns:
- factory
-