Class SqlResultEntityTypeMapper<RS,R>

java.lang.Object
io.micronaut.data.runtime.mapper.sql.SqlResultEntityTypeMapper<RS,R>
Type Parameters:
RS - The result set type
R - The result type
All Implemented Interfaces:
SqlTypeMapper<RS,R>, TypeMapper<RS,R>

@Internal public final class SqlResultEntityTypeMapper<RS,R> extends Object implements SqlTypeMapper<RS,R>
A TypeMapper that can take a RuntimePersistentEntity and a ResultReader and materialize an instance using column naming conventions mapped by the entity.

Instances are stateful and are not thread safe: an instance caches the column name of every property it has read and the ordinals those columns have in the result set being mapped, and hasNext(RS) keeps track of the cursor. Create one mapper per query execution, the way the repository operations do, and do not share an instance between threads or retain it after the result set has been consumed.

  • Constructor Details

  • Method Details

    • getConversionService

      public DataConversionService getConversionService()
      Specified by:
      getConversionService in interface TypeMapper<RS,R>
      Returns:
      The conversion service to use.
    • getEntity

      public RuntimePersistentEntity<R> getEntity()
      Returns:
      The entity to be materialized
    • getResultReader

      public ResultReader<RS,String> getResultReader()
      Returns:
      The result reader instance.
    • map

      public R map(RS rs, Class<R> type) throws DataAccessException
      Description copied from interface: TypeMapper
      Map the given result set to the given object.
      Specified by:
      map in interface TypeMapper<RS,R>
      Parameters:
      rs - The object to map
      type - The type
      Returns:
      The mapped object
      Throws:
      DataAccessException - If the object cannot be mapped.
    • readEntity

      public R readEntity(RS rs) throws DataAccessException
      Read the entity from the result set.
      Parameters:
      rs - The result set
      Returns:
      The entity
      Throws:
      DataAccessException
      Since:
      4.2.0
    • readEntityOrNull

      public @Nullable R readEntityOrNull(RS rs) throws DataAccessException
      Read the entity from the result set, or null when the row has no value for it, which is the case for an optional embedded projection none of whose columns is set.
      Parameters:
      rs - The result set
      Returns:
      The entity or null
      Throws:
      DataAccessException
      Since:
      5.2.0
    • read

      public @Nullable Object read(RS resultSet, String name)
      Description copied from interface: TypeMapper
      Read a value for the given name from the given object.
      Specified by:
      read in interface TypeMapper<RS,R>
      Parameters:
      resultSet - The object to read from
      name - The name
      Returns:
      The value
    • read

      public @Nullable Object read(RS resultSet, io.micronaut.core.type.Argument<?> argument)
      Description copied from interface: TypeMapper
      Read a value for the given name from the given object.
      Specified by:
      read in interface TypeMapper<RS,R>
      Parameters:
      resultSet - The object to read from
      argument - The argument
      Returns:
      The value
    • hasNext

      public boolean hasNext(RS resultSet)
      Description copied from interface: SqlTypeMapper
      Is another result available.
      Specified by:
      hasNext in interface SqlTypeMapper<RS,R>
      Parameters:
      resultSet - The result set
      Returns:
      True if it is
    • readOneMapper

      public SqlResultEntityTypeMapper.PushingMapper<RS,R> readOneMapper()
      Read one entity with a pushing mapper.
      Returns:
      The pushing mapper
    • readManyMapper

      public SqlResultEntityTypeMapper.PushingMapper<RS,List<R>> readManyMapper()
      Read multiple entities with a pushing mapper.
      Returns:
      The pushing mapper
    • getPersistentEntity

      public RuntimePersistentEntity<R> getPersistentEntity()