java.lang.Object
org.litebridge.orm.persistence.DtoMapper
Maps data from rows of a database query to DTO (Data Transfer Object) instances.
It uses a "compiled" mapping plan to achieve high performance by pre-resolving column indices and constructors.
This implementation is designed to handle generic SQL query results to a limited extent. (results from queries that did not necessarily originate from the ORM).
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDtoMapper(DtoConstructor dtoConstructor, LitebridgeContext litebridgeContext) Creates a newDtoMapperinstance. -
Method Summary
Modifier and TypeMethodDescriptionstatic <DTO> DTOconstructDto(Class<DTO> dtoClass, List<DtoConstructor.FieldAccessorValue> fieldAccessorValues, DtoConstructor dtoConstructor) Constructs a DTO instance from the provided field accessor values.<DTO> List<DTO> Maps database rows to a list of DTO instances of the specified type.
-
Constructor Details
-
DtoMapper
Creates a newDtoMapperinstance.- Parameters:
dtoConstructor- the DTO constructor helperlitebridgeContext- the Litebridge context
-
-
Method Details
-
toDtos
public <DTO> List<DTO> toDtos(Class<DTO> dtoClass, @Nullable Class<?> contextDtoClass, List<Row> rows) Maps database rows to a list of DTO instances of the specified type.- Type Parameters:
DTO- the target DTO type- Parameters:
dtoClass- the class of the DTO to map tocontextDtoClass- the context DTO class, ornullrows- the database rows to map- Returns:
- the list of mapped DTO instances
-
constructDto
public static <DTO> DTO constructDto(Class<DTO> dtoClass, List<DtoConstructor.FieldAccessorValue> fieldAccessorValues, DtoConstructor dtoConstructor) Constructs a DTO instance from the provided field accessor values.- Type Parameters:
DTO- the target DTO type- Parameters:
dtoClass- the class of the DTO to constructfieldAccessorValues- the list of field accessor valuesdtoConstructor- the DTO constructor helper- Returns:
- the constructed DTO instance
-