Skip to content

Commit

Permalink
Add support for datetime type conversion in JDBC
Browse files Browse the repository at this point in the history
Signed-off-by: Guian Gumpac <[email protected]>
  • Loading branch information
guiangumpac authored Nov 8, 2021
1 parent a2037bc commit 8c4b8f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sql-jdbc/src/main/java/org/opensearch/jdbc/ResultSetImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,11 @@ protected <T> T getObjectX(int columnIndex, Class<T> javaClass) throws SQLExcept
}

protected <T> T getObjectX(int columnIndex, Class<T> javaClass, Map<String, Object> conversionParams) throws SQLException {
Object value = getColumn(columnIndex);
TypeConverter tc = TypeConverters.getInstance(getColumnMetaData(columnIndex).getOpenSearchType().getJdbcType());
final Object value = getColumn(columnIndex);
final TypeConverter tc = TypeConverters.getInstance(getColumnMetaData(columnIndex).getOpenSearchType().getJdbcType());
if (null == tc) {
throw new SQLException("Conversion from " + getColumnMetaData(columnIndex).getOpenSearchType() + " not supported.");
}
return tc.convert(value, javaClass, conversionParams);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public enum OpenSearchType {
OBJECT(JDBCType.STRUCT, null, 0, 0, false),
DATE(JDBCType.DATE, Date.class, 24, 24, false),
TIME(JDBCType.TIME, Time.class, 24, 24, false),
DATETIME(JDBCType.TIMESTAMP, Timestamp.class, 24, 24, false),
TIMESTAMP(JDBCType.TIMESTAMP, Timestamp.class, 24, 24, false),
BINARY(JDBCType.VARBINARY, String.class, Integer.MAX_VALUE, 0, false),
NULL(JDBCType.NULL, null, 0, 0, false),
Expand Down

0 comments on commit 8c4b8f2

Please sign in to comment.