adejanovski / cassandra-jdbc-wrapper

A JDBC wrapper for the Datastax Java Driver for Cassandra
Apache License 2.0
53 stars 36 forks source link

Missing implementation of getObject(String, Class<T>) method in CassandraResultSet #27

Open maximevw opened 5 years ago

maximevw commented 5 years ago

Assuming I execute a select query like this one:

SELECT id, ts_update FROM mytable ;

where ts_update is a timestamp.

I used the Cassandra JDBC wrapper with MyBatis 3.4.6. My column ts_update is mapped on field of type OffsetDateTime in a Java bean.

In this version of MyBatis, the mapping of the columns of type timestamp was implemented as following:

public OffsetDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
        Timestamp timestamp = rs.getTimestamp(columnName);
        return getOffsetDateTime(timestamp);
}

So, it worked with the current version of CassandraResultSet (3.1.0). But, when I updated MyBatis to the version 3.5.1, I got the following error:

Caused by: java.sql.SQLFeatureNotSupportedException: the Cassandra implementation does not support this method
    at com.github.adejanovski.cassandra.jdbc.AbstractResultSet.getObject(AbstractResultSet.java:136)
    at com.zaxxer.hikari.pool.HikariProxyResultSet.getObject(HikariProxyResultSet.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:69)
    at com.sun.proxy.$Proxy161.getObject(Unknown Source)
    at org.apache.ibatis.type.OffsetDateTimeTypeHandler.getNullableResult(OffsetDateTimeTypeHandler.java:38)
    at org.apache.ibatis.type.OffsetDateTimeTypeHandler.getNullableResult(OffsetDateTimeTypeHandler.java:28)
    at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:81)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getPropertyMappingValue(DefaultResultSetHandler.java:472)

The issue comes from the fact that the method getObject(String, Class<T>) is not implemented in CassandraResultSet but called by the new implementation of the OffsetDateTime handling:

public OffsetDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return (OffsetDateTime)rs.getObject(columnName, OffsetDateTime.class); 
}

So, the mentioned method should be implemented.