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 Type
    Method
    Description
    createDto(T entity)
    Create a DTO of an existing entity.
    createNew(Object... args)
    Create a new entity instance.
    static <T> EntityFactory<T>
    of(@NonNull Function<Object[],T> constructorFunction, Function<T,T> dtoFunction)
    Create a default EntityFactory which uses the constructorFunction for creating a new instance, and the dtoFunction for creating a DTO.
    static <T> EntityFactory<T>
    of(@NonNull Supplier<T> supplier)
    Create a default EntityFactory which uses the supplier for creating a new instance.
    static <T> EntityFactory<T>
    of(@NonNull Supplier<T> supplier, Function<T,T> dtoFunction)
    Create a default EntityFactory which uses the supplier for creating a new instance, and the dtoFunction for creating a DTO.
  • Method Details

    • createNew

      T createNew(Object... args)
      Create a new entity instance. In case of an EntityFactory for an association, the first (and often only) argument will be the parent entity.
      Parameters:
      args - constructor arguments
      Returns:
      new instance
    • createDto

      T createDto(T entity)
      Create a DTO of an existing entity.
      Parameters:
      entity - to create a DTO for
      Returns:
      dto
    • of

      static <T> EntityFactory<T> of(@NonNull @NonNull Supplier<T> supplier)
      Create a default EntityFactory which uses the supplier 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

      static <T> EntityFactory<T> of(@NonNull @NonNull Supplier<T> supplier, Function<T,T> dtoFunction)
      Create a default EntityFactory which uses the supplier for creating a new instance, and the dtoFunction for creating a DTO.
      Type Parameters:
      T - entity type
      Parameters:
      supplier - for creating a new instance
      dtoFunction - for creating a DTO
      Returns:
      factory
    • of

      static <T> EntityFactory<T> of(@NonNull @NonNull Function<Object[],T> constructorFunction, Function<T,T> dtoFunction)
      Create a default EntityFactory which uses the constructorFunction for creating a new instance, and the dtoFunction for creating a DTO.
      Type Parameters:
      T - entity type
      Parameters:
      constructorFunction - for creating a new instance
      dtoFunction - for creating a dto
      Returns:
      factory