Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
[do_jdbc] Revert "Added support for subclasses of supported types"
Browse files Browse the repository at this point in the history
* Will use alternative solution (recursive RubyType#getRubyType) added
  in 67e3ef9.

This reverts commit 59923d1.

[#1123]

Signed-off-by: Alex Coles <alex@alexcolesportfolio.com>
  • Loading branch information
myabc committed Nov 16, 2009
1 parent 67e3ef9 commit 8e64ca1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
45 changes: 0 additions & 45 deletions do_jdbc/src/main/java/data_objects/RubyType.java
@@ -1,7 +1,5 @@
package data_objects;

import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.*;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -125,47 +123,4 @@ public static RubyType jdbcTypeToRubyType(int type, int scale) {
return primitiveType;
}

public static RubyType inferRubyType(IRubyObject obj){
RubyType primitiveType = null;
Ruby runtime = obj.getRuntime();

//XXX Remember that types must by correctly ordered
// RubyObject must be last, Extlib::ByteArray must be before String, etc (inheritance)
if(obj instanceof RubyFixnum){
primitiveType = RubyType.FIXNUM;
}else if(obj instanceof RubyBignum){
primitiveType = RubyType.BIGNUM;
}else if(obj instanceof RubyInteger){
primitiveType = RubyType.INTEGER;
}else if(obj instanceof RubyFloat){
primitiveType = RubyType.FLOAT;
}else if(obj instanceof RubyBigDecimal){
primitiveType = RubyType.BIG_DECIMAL;
}else if(obj.getMetaClass().hasModuleInHierarchy(runtime.fastGetModule("Extlib").fastGetClass("ByteArray"))){
primitiveType = RubyType.BYTE_ARRAY;
}else if(obj instanceof RubyString){
primitiveType = RubyType.STRING;
}else if(obj instanceof RubyTime){
primitiveType = RubyType.TIME;
}else if(obj.getMetaClass().hasModuleInHierarchy(runtime.fastGetClass("DateTime"))){
primitiveType = RubyType.DATE_TIME;
}else if(obj.getMetaClass().hasModuleInHierarchy(runtime.fastGetClass("Date"))){
primitiveType = RubyType.DATE;
}else if(obj instanceof RubyNil){
primitiveType = RubyType.NIL;
}else if(obj.getMetaClass().hasModuleInHierarchy(runtime.fastGetClass("TrueClass"))){
primitiveType = RubyType.TRUE_CLASS;
}else if(obj.getMetaClass().hasModuleInHierarchy(runtime.fastGetClass("FalseClass"))){
primitiveType = RubyType.FALSE_CLASS;
}else if(obj instanceof RubyRational){
primitiveType = RubyType.RATIONAL;
}else if(obj instanceof RubyRegexp){
primitiveType = RubyType.REGEXP;
}else if(obj instanceof RubyClass){
primitiveType = RubyType.CLASS;
}else{
primitiveType = RubyType.OBJECT;
}
return primitiveType;
}
}
Expand Up @@ -475,8 +475,7 @@ public IRubyObject getTypecastResultSetValue(Ruby runtime,
*/
public void setPreparedStatementParam(PreparedStatement ps,
IRubyObject arg, int idx) throws SQLException {
//switch (RubyType.getRubyType(arg.getType().getName())) {
switch (RubyType.inferRubyType(arg)) {
switch (RubyType.getRubyType(arg.getType().getName())) {
case FIXNUM:
ps.setInt(idx, Integer.parseInt(arg.toString()));
break;
Expand Down

0 comments on commit 8e64ca1

Please sign in to comment.