java.lang.Object
org.litebridge.orm.persistence.DtoConstructor
A utility class responsible for constructing Data Transfer Object (DTO) instances
using default or canonical constructors. This class leverages cached constructor data
for performance optimization and ensures proper mapping of field values to parameters.
It supports both Java POJOs and Java Records as DTOs.
The class heavily relies on a TableRegistry instance to retrieve metadata
about the DTOs being constructed, and it computes or caches constructor and field
accessor mappings as needed.
The caching mechanism ensures that constructors and their associated parameters are resolved only once for each DTO class, significantly improving performance for repeated instantiations.
Thread-safety is ensured via the use of ConcurrentHashMap for storing
cached constructor and field accessor data.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe result of constructing a Data Transfer Object (DTO).static final recordDependency configuration for a Data Transfer Object (DTO).static final recordA pair consisting of aFieldAccessorand its corresponding value. -
Constructor Summary
ConstructorsConstructorDescriptionDtoConstructor(TableRegistry tableRegistry) Creates a new DTO constructor instance. -
Method Summary
Modifier and TypeMethodDescription<DTO> DtoConstructor.ConstructionResult<DTO> newInstance(Class<DTO> dtoClass, List<DtoConstructor.FieldAccessorValue> fieldAccessorValues) Creates a new instance of the specified DTO class using the provided field accessor values to resolve constructor arguments.
-
Constructor Details
-
DtoConstructor
Creates a new DTO constructor instance.- Parameters:
tableRegistry- the table registry to use for dependency resolution
-
-
Method Details
-
newInstance
public <DTO> DtoConstructor.ConstructionResult<DTO> newInstance(Class<DTO> dtoClass, List<DtoConstructor.FieldAccessorValue> fieldAccessorValues) Creates a new instance of the specified DTO class using the provided field accessor values to resolve constructor arguments.- Type Parameters:
DTO- The type of the Data Transfer Object to instantiate.- Parameters:
dtoClass- The class of the DTO to be instantiated.fieldAccessorValues- A list ofFieldAccessorValueobjects, where each object specifies a field accessor and its corresponding value for the DTO.- Returns:
- A
ConstructionResult<DTO>containing the instantiated DTO object and a boolean indicating whether the default constructor was used. - Throws:
IllegalArgumentException- If no suitable constructor is found for the given DTO class.
-