Class JdbcTypeMapper.DataTypeMapping<T>
- Type Parameters:
T
- the Deephaven column type this mapping handles
- Direct Known Subclasses:
JdbcTypeMapper.BooleanDataTypeMapping
,JdbcTypeMapper.ByteArrayDataTypeMapping
,JdbcTypeMapper.ByteDataTypeMapping
,JdbcTypeMapper.CharDataTypeMapping
,JdbcTypeMapper.DateDBDateTimeDataTypeMapping
,JdbcTypeMapper.DateLocalDateDataTypeMapping
,JdbcTypeMapper.DateYearDataTypeMapping
,JdbcTypeMapper.DecimalDataTypeMapping
,JdbcTypeMapper.DoubleDataTypeMapping
,JdbcTypeMapper.FloatDataTypeMapping
,JdbcTypeMapper.IntDataTypeMapping
,JdbcTypeMapper.LongDataTypeMapping
,JdbcTypeMapper.ShortDataTypeMapping
,JdbcTypeMapper.StringDataTypeMapping
,JdbcTypeMapper.StringDoubleArrayDataTypeMapping
,JdbcTypeMapper.StringLongArrayDataTypeMapping
,JdbcTypeMapper.TimeDataTypeMappingBase
,JdbcTypeMapper.TimestampDBDateTimeDataTypeMapping
- Enclosing class:
- JdbcTypeMapper
public abstract static class JdbcTypeMapper.DataTypeMapping<T> extends Object
Note that more than one type mapping is possible for each SQL type - a DATE might be converted to either a LocalDate or a DBDateTime for example. And the same is true for the target type - a DBDateTime might be sourced from a SQL DATE or TIMESTAMP value.
Most mappings can lose information, making them "asymmetrical". A trivial example is integer values - since null integers are represented in Iris using Integer.MIN_VALUE, an integer value extracted from a JDBC data source with this value will appear as NULL in Iris. If this value is then written out to a JDBC data source using the default mapping behavior, it will be mapped to NULL in JDBC, not the original value. This problem is impossible to avoid when the domain of the SQL and Iris types do not match precisely.
DateTime values have a different problem - SQL and Deephaven DBDateTime values are conceptually different. TIMESTAMP columns in SQL databases typically do not store timezone information. They are equivalent to a java LocalDateTime in this respect. However, Deephaven usually stores timestamps in DBDateTime columns, internally represented as nanos-since-the-epoch. This means JDBC timestamps usually require the "context" of a timezone in order to be converted to a DBDateTime properly. Writing a DBDateTime to a JDBC datasource (via the bind mechanism) has the same issue. Unfortunately this time-zone context issue applies even when mapping JDBC DATETIME values "directly" to LocalDate, because most JDBC drivers require all Date related values to pass through a java.sql.Date object, which is also epoch-based, not "local". The latest JDBC standard deals with this problem but doesn't seem to be widely implemented. Here we handle this problem by passing a "Context" object every time a conversion occurs, which contains the timezone to be used when extracting or binding JDBC date or timestamp values.
-
Method Summary
Modifier and Type Method Description void
bindByte(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, byte value)
Bind the given byte value to the given prepared statement.void
bindChar(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, char value)
Bind the given character value to the given prepared statement.void
bindDouble(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, double value)
Bind the given double value to the given prepared statement.void
bindFloat(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, float value)
Bind the given float value to the given prepared statement.void
bindInt(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, int value)
Bind the given integer to the given prepared statement.void
bindLong(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, long value)
Bind the given long integer value to the given prepared statement.abstract void
bindObject(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, T value)
Bind the given value to the given prepared statement.void
bindShort(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, short value)
Bind the given short integer value to the given prepared statement.abstract JdbcTypeMapper.ColumnSourceBinder
columnSourceBinder(ColumnSource columnSource, JdbcTypeMapper.Context context)
Provides a function, via a lambda, that can be used to bind values from the given ColumnSource to a PreparedStatement.abstract JdbcTypeMapper.ColumnSourceBinder
columnSourcePrevBinder(ColumnSource columnSource, JdbcTypeMapper.Context context)
Provides a function, via a lambda, that can be used to bind previous values from the given ColumnSource to a PreparedStatement.byte
getByte(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context)
Get a byte value from the current row in the given ResultSet and column and convert to the target type.byte
getByte(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, byte defaultValue)
Get a byte value from the current row in the given ResultSet and column and convert to the target type.char
getChar(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context)
Get a character value from the current row in the given ResultSet and column and convert to the target type.char
getChar(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, char defaultValue)
Get a character value from the current row in the given ResultSet and column and convert to the target type.Class
getDbType()
double
getDouble(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context)
Get an double value from the current row in the given ResultSet and column and convert to the target type.double
getDouble(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, double defaultValue)
Get a double value from the current row in the given ResultSet and column and convert to the target type.float
getFloat(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context)
Get a float value from the current row in the given ResultSet and column and convert to the target type.float
getFloat(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, float defaultValue)
Get a float value from the current row in the given ResultSet and column and convert to the target type.Class
getInputType()
int
getInt(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context)
Get an int value from the current row in the given ResultSet and column and convert to the target type.int
getInt(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, int defaultValue)
Get an int value from the current row in the given ResultSet and column and convert to the target type.long
getLong(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context)
Get an long integer value from the current row in the given ResultSet and column and convert to the target type.long
getLong(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, long defaultValue)
Get a long value from the current row in the given ResultSet and column and convert to the target type.T
getObject(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context)
Get a value from the current row in the given ResultSet and column and convert to the target type.abstract T
getObject(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, T defaultValue)
Get a value from the current row in the given ResultSet and column and convert to the target type.T
getObject(ResultSet resultSet, String columnName, JdbcTypeMapper.Context context)
Get a value from the current row in the given ResultSet and column and convert to the target type.T
getObject(ResultSet resultSet, String columnName, JdbcTypeMapper.Context context, T defaultValue)
Get a value from the current row in the given ResultSet and column and convert to the target type.String
getObjectCodec()
String
getObjectCodecArguments(ResultSetMetaData metaData, String column)
Provide the proper object codec arguments for the given ResultSetMetaData column.String
getObjectCodecArguments(ResultSet resultSet, String col)
Provide the proper object codec arguments for the given ResultSet column.short
getShort(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context)
Get a short int value from the current row in the given ResultSet and column and convert to the target type.short
getShort(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, short defaultValue)
Get a short int value from the current row in the given ResultSet and column and convert to the target type.
-
Method Details
-
getDbType
-
getInputType
-
getObjectCodec
-
getObjectCodecArguments
Provide the proper object codec arguments for the given ResultSet column. This permits the codec to allocate the minimum space that will accommodate the SQL type details (i.e. precision and scale).- Parameters:
resultSet
- ResultSet to querycol
- the column to query- Returns:
- codec arguments consistent with the codec class provided by
getObjectCodec()
-
getObjectCodecArguments
Provide the proper object codec arguments for the given ResultSetMetaData column. This permits the codec to allocate the minimum space that will accommodate the SQL type details (i.e. precision and scale).- Parameters:
metaData
- ResultSetMetaData to querycolumn
- the column to query- Returns:
- codec arguments consistent with the codec class provided by
getObjectCodec()
-
getInt
public int getInt(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, int defaultValue) throws SQLExceptionGet an int value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the given default value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to an int need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.defaultValue
- value to return in case the source value is null.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getShort
public short getShort(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, short defaultValue) throws SQLExceptionGet a short int value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the given default value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a short need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.defaultValue
- value to return in case the source value is null.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getFloat
public float getFloat(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, float defaultValue) throws SQLExceptionGet a float value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the given default value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a float need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.defaultValue
- value to return in case the source value is null.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getDouble
public double getDouble(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, double defaultValue) throws SQLExceptionGet a double value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the given default value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a double need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.defaultValue
- value to return in case the source value is null.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getLong
public long getLong(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, long defaultValue) throws SQLExceptionGet a long value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the given default value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a long need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.defaultValue
- value to return in case the source value is null.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getByte
public byte getByte(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, byte defaultValue) throws SQLExceptionGet a byte value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the given default value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a byte need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.defaultValue
- value to return in case the source value is null.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getChar
public char getChar(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, char defaultValue) throws SQLExceptionGet a character value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the given default value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a char need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.defaultValue
- value to return in case the source value is null.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getInt
public int getInt(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context) throws SQLExceptionGet an int value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the Deephaven null-equivalent. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to an int need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getShort
public short getShort(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context) throws SQLExceptionGet a short int value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the Deephaven null-equivalent. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a short need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getFloat
public float getFloat(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context) throws SQLExceptionGet a float value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the Deephaven null-equivalent. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a float need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getDouble
public double getDouble(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context) throws SQLExceptionGet an double value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the Deephaven null-equivalent. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to an double need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getLong
public long getLong(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context) throws SQLExceptionGet an long integer value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the Deephaven null-equivalent. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a long need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getByte
public byte getByte(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context) throws SQLExceptionGet a byte value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the Deephaven null-equivalent. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a byte need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getChar
public char getChar(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context) throws SQLExceptionGet a character value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the Deephaven null-equivalent. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone). Only mappings that can logically be converted to a char need implement this method.- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getObject
public abstract T getObject(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context, T defaultValue) throws SQLExceptionGet a value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the given default value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone).- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.defaultValue
- value to return in case the source value is null.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getObject
public T getObject(ResultSet resultSet, String columnName, JdbcTypeMapper.Context context, T defaultValue) throws SQLExceptionGet a value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, return the given default value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone).- Parameters:
resultSet
- from which to extract the value.columnName
- ResultSet column from which to extract the value.context
- conversion context information.defaultValue
- value to return in case the source value is null.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getObject
public T getObject(ResultSet resultSet, int columnIndex, JdbcTypeMapper.Context context) throws SQLExceptionGet a value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, this will return the null-equivalent Deephaven value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone).- Parameters:
resultSet
- from which to extract the value.columnIndex
- ResultSet column from which to extract the value (1-based).context
- conversion context information.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
getObject
public T getObject(ResultSet resultSet, String columnName, JdbcTypeMapper.Context context) throws SQLExceptionGet a value from the current row in the given ResultSet and column and convert to the target type. If the source value is null, this will return the null-equivalent Deephaven value. A Context object is provided for additional context or "settings" regarding how to perform the conversion (for example, the source time zone).- Parameters:
resultSet
- from which to extract the value.columnName
- ResultSet column from which to extract the value.context
- conversion context information.- Returns:
- the converted value
- Throws:
SQLException
- if an error occurs
-
bindInt
public void bindInt(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, int value) throws SQLExceptionBind the given integer to the given prepared statement. Implementations should avoid boxing and bind QueryConstants.NULL_INT values as SQL NULL.- Parameters:
stmt
- statement to which to bind the given valueparameterIndex
- parameter index to bindcontext
- context information for the bindingvalue
- value to bind- Throws:
SQLException
- if an error occurs
-
bindShort
public void bindShort(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, short value) throws SQLExceptionBind the given short integer value to the given prepared statement. Implementations should avoid boxing and bind QueryConstants.NULL_SHORT values as SQL NULL.- Parameters:
stmt
- statement to which to bind the given valueparameterIndex
- parameter index to bindcontext
- context information for the bindingvalue
- value to bind- Throws:
SQLException
- if an error occurs
-
bindFloat
public void bindFloat(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, float value) throws SQLExceptionBind the given float value to the given prepared statement. Implementations should avoid boxing and bind QueryConstants.NULL_FLOAT values as SQL NULL.- Parameters:
stmt
- statement to which to bind the given valueparameterIndex
- parameter index to bindcontext
- context information for the bindingvalue
- value to bind- Throws:
SQLException
- if an error occurs
-
bindDouble
public void bindDouble(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, double value) throws SQLExceptionBind the given double value to the given prepared statement. Implementations should avoid boxing and bind QueryConstants.NULL_DOUBLE values as SQL NULL.- Parameters:
stmt
- statement to which to bind the given valueparameterIndex
- parameter index to bindcontext
- context information for the bindingvalue
- value to bind- Throws:
SQLException
- if an error occurs
-
bindLong
public void bindLong(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, long value) throws SQLExceptionBind the given long integer value to the given prepared statement. Implementations should avoid boxing and bind QueryConstants.NULL_LONG values as SQL NULL.- Parameters:
stmt
- statement to which to bind the given valueparameterIndex
- parameter index to bindcontext
- context information for the bindingvalue
- value to bind- Throws:
SQLException
- if an error occurs
-
bindByte
public void bindByte(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, byte value) throws SQLExceptionBind the given byte value to the given prepared statement. Implementations should avoid boxing and bind QueryConstants.NULL_BYTE values as SQL NULL.- Parameters:
stmt
- statement to which to bind the given valueparameterIndex
- parameter index to bindcontext
- context information for the bindingvalue
- value to bind- Throws:
SQLException
- if an error occurs
-
bindChar
public void bindChar(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, char value) throws SQLExceptionBind the given character value to the given prepared statement. Implementations should avoid boxing and bind QueryConstants.NULL_CHAR values as SQL NULL.- Parameters:
stmt
- statement to which to bind the given valueparameterIndex
- parameter index to bindcontext
- context information for the bindingvalue
- value to bind- Throws:
SQLException
- if an error occurs
-
bindObject
public abstract void bindObject(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, T value) throws SQLExceptionBind the given value to the given prepared statement. All concrete implementations must provide this method. If the given value is null or matches the Deephaven null-equivalent, it should be bound as SQL NULL.- Parameters:
stmt
- statement to which to bind the given valueparameterIndex
- parameter index to bindcontext
- context information for the bindingvalue
- value to bind- Throws:
SQLException
- if an error occurs
-
columnSourceBinder
public abstract JdbcTypeMapper.ColumnSourceBinder columnSourceBinder(ColumnSource columnSource, JdbcTypeMapper.Context context)Provides a function, via a lambda, that can be used to bind values from the given ColumnSource to a PreparedStatement.- Parameters:
columnSource
- the column source from which values will be extractedcontext
- context information to use when binding- Returns:
- a ColumnSourceBinder
-
columnSourcePrevBinder
public abstract JdbcTypeMapper.ColumnSourceBinder columnSourcePrevBinder(ColumnSource columnSource, JdbcTypeMapper.Context context)Provides a function, via a lambda, that can be used to bind previous values from the given ColumnSource to a PreparedStatement.- Parameters:
columnSource
- the column source from which values will be extractedcontext
- context information to use when binding- Returns:
- a ColumnSourceBinder
-