Class JdbcTypeMapper.DataTypeMapping<T>

java.lang.Object
com.illumon.iris.utils.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
An abstraction for mapping a JDBC type to an Deephaven column type. Each implementation of DataTypeMapping provides the logic for extracting a value of a specific SQL type from a ResultSet and converting to the Deephaven type as well as binding an Deephaven value to a JDBC Statement appropriately (bidirectional mapping).

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 Details

    • getDbType

      public Class getDbType()
    • getInputType

      public Class getInputType()
    • getObjectCodec

      public String getObjectCodec()
    • getObjectCodecArguments

      public final String getObjectCodecArguments​(ResultSet resultSet, String col)
      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 query
      col - the column to query
      Returns:
      codec arguments consistent with the codec class provided by getObjectCodec()
    • getObjectCodecArguments

      public String getObjectCodecArguments​(ResultSetMetaData metaData, String column)
      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 query
      column - 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Get 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 SQLException
      Bind 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 value
      parameterIndex - parameter index to bind
      context - context information for the binding
      value - value to bind
      Throws:
      SQLException - if an error occurs
    • bindShort

      public void bindShort​(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, short value) throws SQLException
      Bind 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 value
      parameterIndex - parameter index to bind
      context - context information for the binding
      value - value to bind
      Throws:
      SQLException - if an error occurs
    • bindFloat

      public void bindFloat​(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, float value) throws SQLException
      Bind 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 value
      parameterIndex - parameter index to bind
      context - context information for the binding
      value - value to bind
      Throws:
      SQLException - if an error occurs
    • bindDouble

      public void bindDouble​(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, double value) throws SQLException
      Bind 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 value
      parameterIndex - parameter index to bind
      context - context information for the binding
      value - value to bind
      Throws:
      SQLException - if an error occurs
    • bindLong

      public void bindLong​(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, long value) throws SQLException
      Bind 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 value
      parameterIndex - parameter index to bind
      context - context information for the binding
      value - value to bind
      Throws:
      SQLException - if an error occurs
    • bindByte

      public void bindByte​(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, byte value) throws SQLException
      Bind 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 value
      parameterIndex - parameter index to bind
      context - context information for the binding
      value - value to bind
      Throws:
      SQLException - if an error occurs
    • bindChar

      public void bindChar​(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, char value) throws SQLException
      Bind 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 value
      parameterIndex - parameter index to bind
      context - context information for the binding
      value - value to bind
      Throws:
      SQLException - if an error occurs
    • bindObject

      public abstract void bindObject​(PreparedStatement stmt, int parameterIndex, JdbcTypeMapper.Context context, T value) throws SQLException
      Bind 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 value
      parameterIndex - parameter index to bind
      context - context information for the binding
      value - 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 extracted
      context - 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 extracted
      context - context information to use when binding
      Returns:
      a ColumnSourceBinder