Browse files

[postgres] JDBC support for UUIDs + avoid (not-supported) ARRAY.free()

  • Loading branch information...
1 parent 14932fa commit b031353cd6c5cd91ef5b084152474a5d4fb784da @kares kares committed Mar 21, 2013
Showing with 25 additions and 5 deletions.
  1. +25 −5 src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java
View
30 src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java
@@ -25,24 +25,24 @@
***** END LICENSE BLOCK *****/
package arjdbc.postgresql;
-import arjdbc.jdbc.RubyJdbcConnection;
-
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
+import java.util.UUID;
import org.jruby.Ruby;
import org.jruby.RubyClass;
+import org.jruby.javasupport.JavaUtil;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.builtin.IRubyObject;
/**
*
* @author enebo
*/
-public class PostgreSQLRubyJdbcConnection extends RubyJdbcConnection {
+public class PostgreSQLRubyJdbcConnection extends arjdbc.jdbc.RubyJdbcConnection {
protected PostgreSQLRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
super(runtime, metaClass);
@@ -83,13 +83,33 @@ protected String caseConvertIdentifierForJdbc(final DatabaseMetaData metaData, f
protected IRubyObject jdbcToRuby(final Ruby runtime,
final int column, final int type, final ResultSet resultSet)
throws SQLException {
- if ( type == Types.TIMESTAMP ) {
- return stringToRuby(runtime, resultSet, resultSet.getString(column));
+ switch ( type ) {
+ case Types.TIMESTAMP:
+ return stringToRuby(runtime, resultSet, resultSet.getString(column));
+ //case Types.JAVA_OBJECT: case Types.OTHER:
+ //return objectToRuby(runtime, resultSet, resultSet.getObject(column));
+ case Types.ARRAY:
+ // NOTE: avoid `finally { array.free(); }` on PostgreSQL due :
+ // java.sql.SQLFeatureNotSupportedException:
+ // Method org.postgresql.jdbc4.Jdbc4Array.free() is not yet implemented.
+ return arrayToRuby(runtime, resultSet, resultSet.getArray(column));
}
return super.jdbcToRuby(runtime, column, type, resultSet);
}
@Override
+ protected IRubyObject objectToRuby(
+ final Ruby runtime, final ResultSet resultSet, final Object object)
+ throws SQLException {
+ if ( object == null && resultSet.wasNull() ) return runtime.getNil();
+
+ if ( object.getClass() == UUID.class ) {
+ return runtime.newString( ((UUID) object).toString() );
+ }
+ return JavaUtil.convertJavaToRuby(runtime, object);
+ }
+
+ @Override
protected TableName extractTableName(
final Connection connection, String catalog, String schema,
final String tableName) throws IllegalArgumentException, SQLException {

0 comments on commit b031353

Please sign in to comment.