Class ColumnNameR2dbcResultReader

java.lang.Object
io.micronaut.data.r2dbc.mapper.ColumnNameR2dbcResultReader
All Implemented Interfaces:
ResultReader<io.r2dbc.spi.Row, String>

public class ColumnNameR2dbcResultReader extends Object
Implementation of ResultReader for R2DBC.
Since:
1.0.0
Author:
graemerocher
  • Field Details

    • conversionService

      protected final io.micronaut.core.convert.ConversionService conversionService
  • Constructor Details

    • ColumnNameR2dbcResultReader

      public ColumnNameR2dbcResultReader()
    • ColumnNameR2dbcResultReader

      public ColumnNameR2dbcResultReader(@Nullable DataConversionService conversionService)
      Constructs a new instance.
      Parameters:
      conversionService - The data conversion service
      Since:
      3.1
  • Method Details

    • getValue

      protected @Nullable Object getValue(io.r2dbc.spi.Row row, String name)
      Reads the raw value of the column.
      Parameters:
      row - The row
      name - The column identifier
      Returns:
      The value, can be null
    • getValue

      protected <T> @Nullable T getValue(io.r2dbc.spi.Row row, String name, Class<T> type)
      Reads the value of the column as the given type.
      Type Parameters:
      T - The type
      Parameters:
      row - The row
      name - The column identifier
      type - The type
      Returns:
      The value, can be null
    • getRequiredTypedValue

      protected <T> @Nullable T getRequiredTypedValue(io.r2dbc.spi.Row row, String name, Class<T> type)
      Reads the value of the column as the given type for ResultReader.getRequiredValue(Row, I, Class), which the reader addressing a column by name retries with an upper case name.
      Type Parameters:
      T - The type
      Parameters:
      row - The row
      name - The column identifier
      type - The type
      Returns:
      The value, can be null
    • getRequiredRawValue

      protected @Nullable Object getRequiredRawValue(io.r2dbc.spi.Row row, String name)
      Reads the raw value of the column for ResultReader.getRequiredValue(Row, I, Class), which the reader addressing a column by name retries with an upper case name.
      Parameters:
      row - The row
      name - The column identifier
      Returns:
      The value, can be null
    • findColumnIndex

      public int findColumnIndex(io.r2dbc.spi.Row resultSet, String columnName)
      Resolves the ordinal of the column with the given name in the result set, so that callers can cache it and read the values of subsequent rows by index using ResultReader.getColumnIndexReader() instead of resolving the column name for every row.

      The returned ordinal is only valid for the given result set and uses the index convention of the underlying driver (for example 1-based for JDBC). Readers that cannot resolve column ordinals return -1, in which case callers must keep reading by name.

      The ordinal is resolved from the row metadata, matching the column name the way the drivers do, ignoring case. A column that cannot be matched is reported as -1 so that the caller keeps reading it by name.

      Parameters:
      resultSet - The result set
      columnName - The column name
      Returns:
      The column index or -1 if the column cannot be resolved
    • getColumnIndexReader

      public ResultReader<io.r2dbc.spi.Row, Integer> getColumnIndexReader()
      Description copied from interface: ResultReader
      The reader capable of reading values by the ordinals resolved by ResultReader.findColumnIndex(Object, String).
      Returns:
      The column index reader or null if reading by column index is not supported
    • columnResolutionKey

      public Object columnResolutionKey(io.r2dbc.spi.Row resultSet)
      The object the resolved column ordinals belong to, compared by identity by callers that cache them. It is the result set itself when the result set spans every row, which is the case for JDBC. Readers whose result set object is a single row, which is the case for R2DBC, return something shared by the rows of one result, such as the row metadata, so that the ordinals survive from one row to the next.

      Returning a different object per row is safe: the ordinals are then resolved again for each row.

      An R2DBC Row is only valid for the row being consumed, so the resolved ordinals are tied to the RowMetadata instead, which the drivers share between the rows of one result. A driver that returns fresh metadata per row simply causes the ordinals to be resolved again for each row.

      Parameters:
      resultSet - The result set
      Returns:
      The object the resolved ordinals belong to
    • exceptionForColumn

      protected DataAccessException exceptionForColumn(String name, Exception e)
      Parameters:
      name - The column identifier
      e - The cause
      Returns:
      The exception describing a column that cannot be read
    • getConversionService

      public io.micronaut.core.convert.ConversionService getConversionService()
      Description copied from interface: ResultReader
      Get conversion service.
      Specified by:
      getConversionService in interface ResultReader<io.r2dbc.spi.Row, I>
      Returns:
      the instance of ConversionService
    • readDynamic

      public @Nullable Object readDynamic(@NonNull io.r2dbc.spi.Row resultSet, String index, @NonNull DataType dataType)
      Description copied from interface: ResultReader
      Read a value dynamically using the result set and the given name and data type.
      Specified by:
      readDynamic in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      index - The name
      dataType - The data type
      Returns:
      The value, can be null
    • readLong

      public long readLong(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a long value for the given name.
      Specified by:
      readLong in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The long value
    • readChar

      public char readChar(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a char value for the given name.
      Specified by:
      readChar in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The char value
    • readDate

      public @Nullable Date readDate(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a date value for the given name.
      Specified by:
      readDate in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The char value
    • readTimestamp

      public @Nullable Date readTimestamp(io.r2dbc.spi.Row resultSet, String index)
      Description copied from interface: ResultReader
      Read a timestamp value for the given index.
      Specified by:
      readTimestamp in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      index - The index (such as the column name)
      Returns:
      The char value
    • readString

      public @Nullable String readString(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a string value for the given name.
      Specified by:
      readString in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The string value
    • readInt

      public int readInt(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read an int value for the given name.
      Specified by:
      readInt in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The int value
    • readBoolean

      public boolean readBoolean(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a boolean value for the given name.
      Specified by:
      readBoolean in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The boolean value
    • readFloat

      public float readFloat(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a float value for the given name.
      Specified by:
      readFloat in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The float value
    • readByte

      public byte readByte(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a byte value for the given name.
      Specified by:
      readByte in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The byte value
    • readShort

      public short readShort(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a short value for the given name.
      Specified by:
      readShort in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The short value
    • readDouble

      public double readDouble(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a double value for the given name.
      Specified by:
      readDouble in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The double value
    • readBigDecimal

      public @Nullable BigDecimal readBigDecimal(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a BigDecimal value for the given name.
      Specified by:
      readBigDecimal in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The BigDecimal value
    • readBytes

      public byte @Nullable [] readBytes(io.r2dbc.spi.Row resultSet, String name)
      Description copied from interface: ResultReader
      Read a byte[] value for the given name.
      Specified by:
      readBytes in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      name - The name (such as the column name)
      Returns:
      The byte[] value
    • getRequiredValue

      public <T> @Nullable T getRequiredValue(io.r2dbc.spi.Row resultSet, String name, Class<T> type) throws DataAccessException
      Description copied from interface: ResultReader
      Get a value from the given result set for the given name and type.
      Specified by:
      getRequiredValue in interface ResultReader<io.r2dbc.spi.Row, I>
      Type Parameters:
      T - The generic type
      Parameters:
      resultSet - The result set
      name - The name
      type - The type
      Returns:
      The value
      Throws:
      DataAccessException - if the value cannot be read
    • next

      public boolean next(io.r2dbc.spi.Row resultSet)
      Description copied from interface: ResultReader
      Move the index to the next result if possible.
      Specified by:
      next in interface ResultReader<io.r2dbc.spi.Row, I>
      Parameters:
      resultSet - The result set
      Returns:
      The next result