Class ColumnNameResultSetReader

  • All Implemented Interfaces:
    ResultReader<java.sql.ResultSet,​java.lang.String>

    public final class ColumnNameResultSetReader
    extends java.lang.Object
    implements ResultReader<java.sql.ResultSet,​java.lang.String>
    A ResultReader for JDBC that uses the column name.
    Since:
    1.0.0
    Author:
    graemerocher
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T convertRequired​(java.lang.Object value, java.lang.Class<T> type)
      Convert the value to the given type.
      io.micronaut.core.convert.ConversionService<?> getConversionService()
      Get conversion service.
      <T> T getRequiredValue​(java.sql.ResultSet resultSet, java.lang.String name, java.lang.Class<T> type)
      Get a value from the given result set for the given name and type.
      boolean next​(java.sql.ResultSet resultSet)
      Move the index to the next result if possible.
      java.math.BigDecimal readBigDecimal​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a BigDecimal value for the given name.
      boolean readBoolean​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a boolean value for the given name.
      byte readByte​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a byte value for the given name.
      byte[] readBytes​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a byte[] value for the given name.
      char readChar​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a char value for the given name.
      java.util.Date readDate​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a date value for the given name.
      double readDouble​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a double value for the given name.
      java.lang.Object readDynamic​(java.sql.ResultSet resultSet, java.lang.String index, DataType dataType)
      Read a value dynamically using the result set and the given name and data type.
      float readFloat​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a float value for the given name.
      int readInt​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a int value for the given name.
      long readLong​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a long value for the given name.
      short readShort​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a short value for the given name.
      java.lang.String readString​(java.sql.ResultSet resultSet, java.lang.String name)
      Read a string value for the given name.
      java.util.Date readTimestamp​(java.sql.ResultSet resultSet, java.lang.String index)
      Read a timestamp value for the given index.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ColumnNameResultSetReader

        public ColumnNameResultSetReader()
      • ColumnNameResultSetReader

        public ColumnNameResultSetReader​(DataConversionService<?> conversionService)
        Constructs a new instance.
        Parameters:
        conversionService - The data conversion service
        Since:
        3.1
    • Method Detail

      • getConversionService

        public io.micronaut.core.convert.ConversionService<?> getConversionService()
        Description copied from interface: ResultReader
        Get conversion service.
        Specified by:
        getConversionService in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Returns:
        the instance of ConversionService
      • readDynamic

        @Nullable
        public java.lang.Object readDynamic​(@NonNull
                                            java.sql.ResultSet resultSet,
                                            @NonNull
                                            java.lang.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<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        index - The name
        dataType - The data type
        Returns:
        The value, can be null
      • next

        public boolean next​(java.sql.ResultSet resultSet)
        Description copied from interface: ResultReader
        Move the index to the next result if possible.
        Specified by:
        next in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        Returns:
        The next result
      • convertRequired

        public <T> T convertRequired​(@NonNull
                                     java.lang.Object value,
                                     java.lang.Class<T> type)
        Description copied from interface: ResultReader
        Convert the value to the given type.
        Specified by:
        convertRequired in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Type Parameters:
        T - The generic type
        Parameters:
        value - The value
        type - The type
        Returns:
        The converted value
      • readTimestamp

        public java.util.Date readTimestamp​(java.sql.ResultSet resultSet,
                                            java.lang.String index)
        Description copied from interface: ResultReader
        Read a timestamp value for the given index.
        Specified by:
        readTimestamp in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        index - The index (such as the column name)
        Returns:
        The char value
      • readLong

        public long readLong​(java.sql.ResultSet resultSet,
                             java.lang.String name)
        Description copied from interface: ResultReader
        Read a long value for the given name.
        Specified by:
        readLong in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The long value
      • readChar

        public char readChar​(java.sql.ResultSet resultSet,
                             java.lang.String name)
        Description copied from interface: ResultReader
        Read a char value for the given name.
        Specified by:
        readChar in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The char value
      • readDate

        public java.util.Date readDate​(java.sql.ResultSet resultSet,
                                       java.lang.String name)
        Description copied from interface: ResultReader
        Read a date value for the given name.
        Specified by:
        readDate in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The char value
      • readString

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

        public int readInt​(java.sql.ResultSet resultSet,
                           java.lang.String name)
        Description copied from interface: ResultReader
        Read a int value for the given name.
        Specified by:
        readInt in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The int value
      • readBoolean

        public boolean readBoolean​(java.sql.ResultSet resultSet,
                                   java.lang.String name)
        Description copied from interface: ResultReader
        Read a boolean value for the given name.
        Specified by:
        readBoolean in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The boolean value
      • readFloat

        public float readFloat​(java.sql.ResultSet resultSet,
                               java.lang.String name)
        Description copied from interface: ResultReader
        Read a float value for the given name.
        Specified by:
        readFloat in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The float value
      • readByte

        public byte readByte​(java.sql.ResultSet resultSet,
                             java.lang.String name)
        Description copied from interface: ResultReader
        Read a byte value for the given name.
        Specified by:
        readByte in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The byte value
      • readShort

        public short readShort​(java.sql.ResultSet resultSet,
                               java.lang.String name)
        Description copied from interface: ResultReader
        Read a short value for the given name.
        Specified by:
        readShort in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The short value
      • readDouble

        public double readDouble​(java.sql.ResultSet resultSet,
                                 java.lang.String name)
        Description copied from interface: ResultReader
        Read a double value for the given name.
        Specified by:
        readDouble in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The double value
      • readBigDecimal

        public java.math.BigDecimal readBigDecimal​(java.sql.ResultSet resultSet,
                                                   java.lang.String name)
        Description copied from interface: ResultReader
        Read a BigDecimal value for the given name.
        Specified by:
        readBigDecimal in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The BigDecimal value
      • readBytes

        public byte[] readBytes​(java.sql.ResultSet resultSet,
                                java.lang.String name)
        Description copied from interface: ResultReader
        Read a byte[] value for the given name.
        Specified by:
        readBytes in interface ResultReader<java.sql.ResultSet,​java.lang.String>
        Parameters:
        resultSet - The result set
        name - The name (such as the column name)
        Returns:
        The byte[] value
      • getRequiredValue

        public <T> T getRequiredValue​(java.sql.ResultSet resultSet,
                                      java.lang.String name,
                                      java.lang.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<java.sql.ResultSet,​java.lang.String>
        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