You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2006/08/28 22:47:44 UTC
svn commit: r437822 - in /db/derby/code/trunk/java:
client/org/apache/derby/client/am/PreparedStatement.java
testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java
Author: djd
Date: Mon Aug 28 13:47:43 2006
New Revision: 437822
URL: http://svn.apache.org/viewvc?rev=437822&view=rev
Log:
DERBY-1292 1) The addition of a copy method to org.apache.derby.client.am.ColumnMetaData.
2) Modifications to org.apache.derby.client.am.PreparedStatement to hold on to a copy of the column meta data for each entry used in batch updates.
3) A test was added to org.apache.derbyTestingfunctionTests.tests.derbynet.prepStmt.
Patch contributed by James F. Adams derby@xemaps.com
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java?rev=437822&r1=437821&r2=437822&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/PreparedStatement.java Mon Aug 28 13:47:43 2006
@@ -27,6 +27,7 @@
import java.io.InputStream;
import java.io.Reader;
import java.sql.SQLException;
+import java.util.ArrayList;
import org.apache.derby.client.ClientPooledConnection;
import org.apache.derby.jdbc.ClientDriver;
@@ -62,6 +63,8 @@
}
public ColumnMetaData parameterMetaData_; // type information for input sqlda
+
+ private ArrayList parameterTypeList;
// The problem with storing the scrollable ResultSet associated with cursorName in scrollableRS_ is
@@ -86,6 +89,7 @@
parameterSet_ = null;
parameterRegistered_ = null;
parameterMetaData_ = null;
+ parameterTypeList = null;
isAutoCommittableStatement_ = true;
isPreparedStatement_ = true;
}
@@ -1361,6 +1365,10 @@
}
checkForClosedStatement();
checkThatAllParametersAreSet();
+
+ if (parameterTypeList == null) {
+ parameterTypeList = new ArrayList();
+ }
// ASSERT: since OUT/INOUT parameters are not allowed, there should
// be no problem in sharing the JDBC Wrapper object instances
@@ -1373,8 +1381,13 @@
System.arraycopy(parameters_, 0, inputsClone, 0, parameters_.length);
batch_.add(inputsClone);
+
+ // Get a copy of the parameter type data and save it in a list
+ // which will be used later on at the time of batch execution.
+ parameterTypeList.add(parameterMetaData_.clientParamtertype_.clone());
} else {
batch_.add(null);
+ parameterTypeList.add(null);
}
}
}
@@ -2027,6 +2040,7 @@
}
for (int i = 0; i < batchSize; i++) {
+ parameterMetaData_.clientParamtertype_ = (int[]) parameterTypeList.get(i);
parameters_ = (Object[]) batch_.get(i);
if (sqlMode_ != isCall__) {
@@ -2115,6 +2129,7 @@
}
// We need to clear the batch before any exception is thrown from agent_.endBatchedReadChain().
batch_.clear();
+ parameterTypeList = null;
// restore the saved input set, setting it to "current"
parameters_ = savedInputs;
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java?rev=437822&r1=437821&r2=437822&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/prepStmt.java Mon Aug 28 13:47:43 2006
@@ -30,6 +30,7 @@
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
+import java.sql.Types;
import java.sql.SQLException;
import java.sql.BatchUpdateException;
import java.io.ByteArrayInputStream;
@@ -49,7 +50,7 @@
private static String[] testObjects = // string array for cleaning up
{"table t1", "table tab1", "table t2", "table bigtab", "table tstab",
"table doubletab", "table numtab", "table Numeric_Tab", "table jira614",
- "table jira614_a", "table jira428", "table jira125",
+ "table jira614_a", "table jira428", "table jira125", "table varcharclobtab",
"table jira125125125125125125125125125125125125125125125125125125125125125125125125125125125125125125125",
"table jira1533_a", "table jira1533_b"};
@@ -309,6 +310,10 @@
testBigDecimalSetObject(conn);
testBigDecimalSetObjectWithScale(conn);
+
+ if (!TestUtil.isJCCFramework()) {
+ testVaryingClientParameterTypeBatch(conn);
+ }
test4975(conn);
test5130(conn);
@@ -335,6 +340,36 @@
e.printStackTrace();
}
}
+
+ // Test execution of batch update where the type of
+ // a parameter varies for difference entries in the batch.
+ private static void testVaryingClientParameterTypeBatch(Connection conn) throws Exception
+ {
+ Statement stmt = conn.createStatement();
+
+ try { stmt.execute("drop table varcharclobtab"); } catch (Throwable t) { }
+ stmt.execute("create table varcharclobtab (c1 varchar(100), c2 clob)");
+ stmt.close();
+
+ PreparedStatement pStmt = conn.prepareStatement("insert into varcharclobtab VALUES(?,?)");
+
+ pStmt.setNull(1, Types.VARCHAR);
+ pStmt.setString(2, "clob");
+ pStmt.addBatch();
+
+ pStmt.setString(1, "varchar");
+ pStmt.setNull(2, Types.CLOB);
+ pStmt.addBatch();
+
+ // The following statement should not throw an exception.
+ try {
+ pStmt.executeBatch();
+ } catch (ClassCastException e) {
+ System.out.println("FAIL: ClassCastException thrown by testVaryingClientParameterTypeBatch test.");
+ throw e;
+ }
+ pStmt.close();
+ }
// Test creation and execution of many Prepared Statements
// Beetle 5130