Class DtoMapper

java.lang.Object
org.litebridge.orm.persistence.DtoMapper

public class DtoMapper extends Object
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).

  • Constructor Details

    • DtoMapper

      public DtoMapper(DtoConstructor dtoConstructor, LitebridgeContext litebridgeContext)
      Creates a new DtoMapper instance.
      Parameters:
      dtoConstructor - the DTO constructor helper
      litebridgeContext - 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 to
      contextDtoClass - the context DTO class, or null
      rows - 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 construct
      fieldAccessorValues - the list of field accessor values
      dtoConstructor - the DTO constructor helper
      Returns:
      the constructed DTO instance