Author: shawkins
Date: 2011-06-18 08:21:26 -0400 (Sat, 18 Jun 2011)
New Revision: 3256
Modified:
branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java
Log:
TEIID-1641 fix for npe
Modified: branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java
===================================================================
--- branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-06-18
12:20:53 UTC (rev 3255)
+++ branches/7.4.x/client/src/main/java/org/teiid/jdbc/StatementImpl.java 2011-06-18
12:21:26 UTC (rev 3256)
@@ -149,7 +149,7 @@
private Serializable payload;
/** List of INSERT, UPDATE, DELETE AND SELECT INTO commands */
- private List batchedUpdates;
+ private List<String> batchedUpdates;
/** Array of update counts as returned by executeBatch() */
protected int[] updateCounts;
@@ -243,24 +243,15 @@
this.commandStatus = State.RUNNING;
}
- /**
- * Adds sql to this statement object's current list of commands.
- * @param sql statement to be added to the batch
- */
public void addBatch(String sql) throws SQLException {
//Check to see the statement is closed and throw an exception
checkStatement();
if (batchedUpdates == null) {
- batchedUpdates = new ArrayList();
+ batchedUpdates = new ArrayList<String>();
}
batchedUpdates.add(sql);
}
- /**
- * This method can be used by one thread to cancel a statement that is being
- * executed by another thread.
- * @throws SQLException should never occur.
- */
public void cancel() throws SQLException {
/* Defect 19848 - Mark the statement cancelled before sending the CANCEL
request.
* Otherwise, it's possible get into a race where the server response is
quicker
@@ -272,10 +263,6 @@
cancelRequest();
}
- /**
- * Warning could be schema validation errors or partial results warnings.
- * @throws SQLException should never occur.
- */
public void clearWarnings() throws SQLException {
//Check to see the statement is closed and throw an exception
checkStatement();
@@ -284,22 +271,12 @@
serverWarnings = null;
}
- /**
- * Makes the set of commands in the current batch empty.
- *
- * @throws SQLException if a database access error occurs or the
- * driver does not support batch statements
- */
public void clearBatch() throws SQLException {
- batchedUpdates.clear();
+ if (batchedUpdates != null) {
+ batchedUpdates.clear();
+ }
}
- /**
- * In many cases, it is desirable to immediately release a Statements's database
- * and JDBC resources instead of waiting for this to happen when it is automatically
- * closed; the close method provides this immediate release.
- * @throws SQLException should never occur.
- */
public void close() throws SQLException {
if ( isClosed ) {
return;
@@ -346,7 +323,7 @@
if (batchedUpdates == null || batchedUpdates.isEmpty()) {
return new int[0];
}
- String[] commands = (String[])batchedUpdates.toArray(new
String[batchedUpdates.size()]);
+ String[] commands = batchedUpdates.toArray(new String[batchedUpdates.size()]);
executeSql(commands, true, ResultsMode.UPDATECOUNT, true);
return updateCounts;
}
Modified: branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java
===================================================================
--- branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java 2011-06-18
12:20:53 UTC (rev 3255)
+++ branches/7.4.x/client/src/test/java/org/teiid/jdbc/TestStatement.java 2011-06-18
12:21:26 UTC (rev 3256)
@@ -50,6 +50,7 @@
results.getResultsReceiver().receiveResults(rm);
Mockito.stub(conn.getDQP()).toReturn(dqp);
StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
+ statement.clearBatch(); //previously caused npe
statement.addBatch("delete from table"); //$NON-NLS-1$
statement.addBatch("delete from table1"); //$NON-NLS-1$
assertTrue(Arrays.equals(new int[] {1, 2}, statement.executeBatch()));
Show replies by thread