Class ColumnNameResultSetReader
java.lang.Object
io.micronaut.data.jdbc.mapper.ColumnNameResultSetReader
- All Implemented Interfaces:
ResultReader<ResultSet, String>
public final class ColumnNameResultSetReader
extends Object
implements ResultReader<ResultSet, String>
A
ResultReader for JDBC that uses the column name.- Since:
- 1.0.0
- Author:
- graemerocher
-
Constructor Summary
ConstructorsConstructorDescriptionColumnNameResultSetReader(@Nullable DataConversionService conversionService) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescription<T> TconvertRequired(Object value, Class<T> type) Convert the value to the given type.intfindColumnIndex(ResultSet 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 usingResultReader.getColumnIndexReader()instead of resolving the column name for every row.The reader capable of reading values by the ordinals resolved byResultReader.findColumnIndex(Object, String).io.micronaut.core.convert.ConversionServiceGet conversion service.<T> @Nullable TgetRequiredValue(ResultSet resultSet, String name, Class<T> type) Get a value from the given result set for the given name and type.booleanMove the index to the next result if possible.@Nullable BigDecimalreadBigDecimal(ResultSet resultSet, String name) Read a BigDecimal value for the given name.booleanreadBoolean(ResultSet resultSet, String name) Read a boolean value for the given name.byteRead a byte value for the given name.byte[]Read a byte[] value for the given name.charRead a char value for the given name.@Nullable DateRead a date value for the given name.doublereadDouble(ResultSet resultSet, String name) Read a double value for the given name.@Nullable ObjectreadDynamic(ResultSet resultSet, String index, DataType dataType) Read a value dynamically using the result set and the given name and data type.floatRead a float value for the given name.intRead an int value for the given name.longRead a long value for the given name.shortRead a short value for the given name.@Nullable StringreadString(ResultSet resultSet, String name) Read a string value for the given name.@Nullable TimeRead a time value for the given index.@Nullable DatereadTimestamp(ResultSet resultSet, String index) Read a timestamp value for the given index.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ResultReader
columnResolutionKey, convertRequired, getRequiredValueNonNull, readDuration, readPeriod, readUUID
-
Constructor Details
-
ColumnNameResultSetReader
public ColumnNameResultSetReader() -
ColumnNameResultSetReader
Constructs a new instance.- Parameters:
conversionService- The data conversion service- Since:
- 3.1
-
-
Method Details
-
getConversionService
public io.micronaut.core.convert.ConversionService getConversionService()Description copied from interface:ResultReaderGet conversion service.- Specified by:
getConversionServicein interfaceResultReader<ResultSet, String>- Returns:
- the instance of
ConversionService
-
findColumnIndex
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 usingResultReader.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.A failure to resolve the ordinal is not reported here: the caller falls back to reading the column by name, and a failure that is not a missing column, such as a closed result set, surfaces from that read with the message of the underlying driver rather than being swallowed.
- Specified by:
findColumnIndexin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setcolumnName- The column name- Returns:
- The column index or
-1if the column cannot be resolved
-
getColumnIndexReader
Description copied from interface:ResultReaderThe reader capable of reading values by the ordinals resolved byResultReader.findColumnIndex(Object, String).- Specified by:
getColumnIndexReaderin interfaceResultReader<ResultSet, String>- Returns:
- The column index reader or
nullif reading by column index is not supported
-
readDynamic
Description copied from interface:ResultReaderRead a value dynamically using the result set and the given name and data type.- Specified by:
readDynamicin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setindex- The namedataType- The data type- Returns:
- The value, can be null
-
next
Description copied from interface:ResultReaderMove the index to the next result if possible.- Specified by:
nextin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result set- Returns:
- The next result
-
convertRequired
Description copied from interface:ResultReaderConvert the value to the given type.- Specified by:
convertRequiredin interfaceResultReader<ResultSet, String>- Type Parameters:
T- The generic type- Parameters:
value- The valuetype- The type- Returns:
- The converted value
-
readTimestamp
Description copied from interface:ResultReaderRead a timestamp value for the given index.- Specified by:
readTimestampin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setindex- The index (such as the column name)- Returns:
- The char value
-
readTime
Description copied from interface:ResultReaderRead a time value for the given index.- Specified by:
readTimein interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setindex- The index (such as the column name)- Returns:
- The char value
-
readLong
Description copied from interface:ResultReaderRead a long value for the given name.- Specified by:
readLongin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The long value
-
readChar
Description copied from interface:ResultReaderRead a char value for the given name.- Specified by:
readCharin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The char value
-
readDate
Description copied from interface:ResultReaderRead a date value for the given name.- Specified by:
readDatein interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The char value
-
readString
Description copied from interface:ResultReaderRead a string value for the given name.- Specified by:
readStringin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The string value
-
readInt
Description copied from interface:ResultReaderRead an int value for the given name.- Specified by:
readIntin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The int value
-
readBoolean
Description copied from interface:ResultReaderRead a boolean value for the given name.- Specified by:
readBooleanin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The boolean value
-
readFloat
Description copied from interface:ResultReaderRead a float value for the given name.- Specified by:
readFloatin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The float value
-
readByte
Description copied from interface:ResultReaderRead a byte value for the given name.- Specified by:
readBytein interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The byte value
-
readShort
Description copied from interface:ResultReaderRead a short value for the given name.- Specified by:
readShortin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The short value
-
readDouble
Description copied from interface:ResultReaderRead a double value for the given name.- Specified by:
readDoublein interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The double value
-
readBigDecimal
Description copied from interface:ResultReaderRead a BigDecimal value for the given name.- Specified by:
readBigDecimalin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The BigDecimal value
-
readBytes
Description copied from interface:ResultReaderRead a byte[] value for the given name.- Specified by:
readBytesin interfaceResultReader<ResultSet, String>- Parameters:
resultSet- The result setname- The name (such as the column name)- Returns:
- The byte[] value
-
getRequiredValue
public <T> @Nullable T getRequiredValue(ResultSet resultSet, String name, Class<T> type) throws DataAccessException Description copied from interface:ResultReaderGet a value from the given result set for the given name and type.- Specified by:
getRequiredValuein interfaceResultReader<ResultSet, String>- Type Parameters:
T- The generic type- Parameters:
resultSet- The result setname- The nametype- The type- Returns:
- The value
- Throws:
DataAccessException- if the value cannot be read
-