You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ol...@apache.org on 2002/12/22 16:42:34 UTC
cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/util/batch PreparedStatementInvocationHandler.java
olegnitz 2002/12/22 07:42:34
Modified: src/java/org/apache/ojb/broker/util/batch
PreparedStatementInvocationHandler.java
Log:
A workaround for the bug in Sybase jConnect JDBC driver: doens't support setLong for batches
Revision Changes Path
1.2 +27 -17 jakarta-ojb/src/java/org/apache/ojb/broker/util/batch/PreparedStatementInvocationHandler.java
Index: PreparedStatementInvocationHandler.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/util/batch/PreparedStatementInvocationHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PreparedStatementInvocationHandler.java 2 Dec 2002 17:14:12 -0000 1.1
+++ PreparedStatementInvocationHandler.java 22 Dec 2002 15:42:34 -0000 1.2
@@ -57,6 +57,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
+import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -88,18 +89,31 @@
private final static Method ADD_BATCH;
+ private final static Method SET_BIG_DECIMAL;
+
static
{
Method addBatch = null;
+ Method setBigDecimal = null;
try
{
addBatch = PreparedStatement.class.getMethod("addBatch", null);
}
- catch (Exception ex)
+ catch (Exception ex)
{
}
ADD_BATCH = addBatch;
+
+ try
+ {
+ setBigDecimal = PreparedStatement.class.getMethod("setBigDecimal",
+ new Class[] {Integer.TYPE, BigDecimal.class});
+ }
+ catch (Exception ex)
+ {
+ }
+ SET_BIG_DECIMAL = setBigDecimal;
}
private final BatchConnection _batchConn;
@@ -119,28 +133,24 @@
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable
{
- if (method.getName().equals("executeUpdate"))
- {
+ String name = method.getName();
+ if (name.equals("executeUpdate")) {
_batchConn.nextExecuted(_sql);
_methods.add(ADD_BATCH);
_params.add(null);
return ONE;
- }
- else if (method.getName().equals("doExecute"))
- {
+ } else if (name.equals("doExecute")) {
doExecute((Connection) args[0]);
- return null;
- }
- else
- {
- if (method.getReturnType() == Void.TYPE
- && method.getName().startsWith("set"))
- {
- _methods.add(method);
- _params.add(args);
+ } else if (name.startsWith("set")) {
+ // workaround for the bug in Sybase jConnect JDBC driver
+ if (name.equals("setLong")) {
+ method = SET_BIG_DECIMAL;
+ args[1] = BigDecimal.valueOf(((Long) args[1]).longValue());
}
- return null;
+ _methods.add(method);
+ _params.add(args);
}
+ return null;
}
/**
@@ -177,7 +187,7 @@
{
th = ex;
}
- if (th instanceof SQLException)
+ if (th instanceof SQLException)
{
throw ((SQLException) th);
}