Skip to content

Commit

Permalink
[postgres] DRAFT handling for PG types - return as Strings by the dri…
Browse files Browse the repository at this point in the history
…ver API
  • Loading branch information
kares committed Mar 21, 2013
1 parent cdf5a65 commit b78fc5f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java
Expand Up @@ -30,6 +30,8 @@
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types; import java.sql.Types;
import java.util.Collection;
import java.util.HashSet;
import java.util.UUID; import java.util.UUID;


import org.jruby.Ruby; import org.jruby.Ruby;
Expand Down Expand Up @@ -97,15 +99,35 @@ protected IRubyObject jdbcToRuby(final Ruby runtime,
return super.jdbcToRuby(runtime, column, type, resultSet); return super.jdbcToRuby(runtime, column, type, resultSet);
} }


// TODO this is just a fast-draft for now :
private static final Collection<String> PG_TYPES = new HashSet<String>();
static {
PG_TYPES.add("org.postgresql.util.PGobject");
PG_TYPES.add("org.postgresql.util.PGmoney");
PG_TYPES.add("org.postgresql.util.PGInterval");
PG_TYPES.add("org.postgresql.geometric.PGbox");
PG_TYPES.add("org.postgresql.geometric.PGcircle");
PG_TYPES.add("org.postgresql.geometric.PGline");
PG_TYPES.add("org.postgresql.geometric.PGlseg");
PG_TYPES.add("org.postgresql.geometric.PGpath");
PG_TYPES.add("org.postgresql.geometric.PGpoint");
PG_TYPES.add("org.postgresql.geometric.PGpolygon");
}

@Override @Override
protected IRubyObject objectToRuby( protected IRubyObject objectToRuby(
final Ruby runtime, final ResultSet resultSet, final Object object) final Ruby runtime, final ResultSet resultSet, final Object object)
throws SQLException { throws SQLException {
if ( object == null && resultSet.wasNull() ) return runtime.getNil(); if ( object == null && resultSet.wasNull() ) return runtime.getNil();


if ( object.getClass() == UUID.class ) { if ( object.getClass() == UUID.class ) {
return runtime.newString( ((UUID) object).toString() ); return runtime.newString( object.toString() );
} }
// NOTE: this should get refactored using PG's JDBC API :
if ( PG_TYPES.contains(object.getClass().getName()) ) {
return runtime.newString( object.toString() );
}

return JavaUtil.convertJavaToRuby(runtime, object); return JavaUtil.convertJavaToRuby(runtime, object);
} }


Expand Down

0 comments on commit b78fc5f

Please sign in to comment.