Skip to content

Commit

Permalink
Merge pull request #105 from luan-cestari/issue103
Browse files Browse the repository at this point in the history
Fixes #103
  • Loading branch information
bserdar committed Jan 28, 2015
2 parents 44c75f8 + 3e7906d commit 43fad2d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.redhat.lightblue.metadata.rdbms.converter;

import java.math.BigDecimal;
import java.sql.*;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -142,6 +143,13 @@ public void setInt(String name, int value) throws SQLException {
}
}

public void setBigDecimal(String name, BigDecimal value) throws SQLException {
int[] indexes = getIndexes(name);
for (int index : indexes) {
statement.setBigDecimal(index, value);
}
}

public void setLong(String name, long value) throws SQLException {
int[] indexes = getIndexes(name);
for (int index : indexes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.redhat.lightblue.metadata.rdbms.converter;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand Down Expand Up @@ -137,7 +138,7 @@ public static PreparedStatement getStatement(RDBMSContext context) {
return ps;
}
enum Classes {
Boolean,Short,Integer,Long,Double,String,Date,Time, Bytes ;
Boolean,Short,Integer,Long,Double,String,Date,Time,Bytes,BigDecimal;

public static Classes getEnum(String clazz){
if("byte[]".equals(clazz)) {
Expand Down Expand Up @@ -191,6 +192,9 @@ public static void processDynVar(RDBMSContext context,NamedParameterStatement np
case Time:
nps.setTime(key, (Time) o);
break;
case BigDecimal:
nps.setBigDecimal(key, (BigDecimal) o);
break;
case Bytes:
nps.setBytes(key, (byte[]) o);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,27 @@ public void setBytes(int parameterIndex, byte[] x) throws SQLException {
RDBMSUtilsMetadata.processDynVar(context, nps, dynVar);
assertTrue(flag.isAsserted());
}

{
flag.reset();
final java.math.BigDecimal value = new java.math.BigDecimal(456123L);
final Class<?> objectClass = java.math.BigDecimal.class;
connection = new MyConnection();
connection.myPreparedStatement = new MyPreparedStatement() {
@Override
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
assertEquals(1, parameterIndex);
assertEquals(value, x);
flag.done();
}
};
nps = new NamedParameterStatement(connection, ":parameter");
dynVar = new DynVar(context);
Column column = new Column(0, "parameter", "parameter", "java.math.BigDecimal", Types.DECIMAL);
dynVar.put(value, objectClass, column);
RDBMSUtilsMetadata.processDynVar(context, nps, dynVar);
assertTrue(flag.isAsserted());
}
}

private static class MyConnection implements Connection {
Expand Down Expand Up @@ -1046,4 +1067,4 @@ public boolean isWrapperFor(Class<?> iface) throws SQLException {
return false;
}
}
}
}

0 comments on commit 43fad2d

Please sign in to comment.