提交 383df1c3 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add JdbcPreparedStatement.executeLargeUpdate() with implementation delegating to…

Add JdbcPreparedStatement.executeLargeUpdate() with implementation delegating to old internal method
上级 ef1a5ddc
......@@ -82,6 +82,36 @@ public class JdbcCallableStatement extends JdbcPreparedStatement implements
}
}
/**
* Executes a statement (insert, update, delete, create, drop)
* and returns the update count.
* If another result set exists for this statement, this will be closed
* (even if this statement fails).
*
* If auto commit is on, this statement will be committed.
* If the statement is a DDL statement (create, drop, alter) and does not
* throw an exception, the current transaction (if any) is committed after
* executing the statement.
*
* @return the update count (number of row affected by an insert, update or
* delete, or 0 if no rows or the statement was a create, drop,
* commit or rollback)
* @throws SQLException if this object is closed or invalid
*/
@Override
public long executeLargeUpdate() throws SQLException {
try {
checkClosed();
if (command.isQuery()) {
super.executeQuery();
return 0;
}
return super.executeLargeUpdate();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Registers the given OUT parameter.
*
......
......@@ -56,7 +56,7 @@ import org.h2.value.ValueTimestamp;
* Represents a prepared statement.
*/
public class JdbcPreparedStatement extends JdbcStatement implements
PreparedStatement {
PreparedStatement, JdbcPreparedStatementBackwardsCompat {
protected CommandInterface command;
private final String sqlStatement;
......@@ -156,6 +156,38 @@ public class JdbcPreparedStatement extends JdbcStatement implements
}
}
/**
* Executes a statement (insert, update, delete, create, drop)
* and returns the update count.
* If another result set exists for this statement, this will be closed
* (even if this statement fails).
*
* If auto commit is on, this statement will be committed.
* If the statement is a DDL statement (create, drop, alter) and does not
* throw an exception, the current transaction (if any) is committed after
* executing the statement.
*
* @return the update count (number of row affected by an insert, update or
* delete, or 0 if no rows or the statement was a create, drop,
* commit or rollback)
* @throws SQLException if this object is closed or invalid
*/
@Override
public long executeLargeUpdate() throws SQLException {
try {
debugCodeCall("executeLargeUpdate");
checkClosedForWrite();
batchIdentities = null;
try {
return executeUpdateInternal();
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
private int executeUpdateInternal() throws SQLException {
closeOldResultSet();
synchronized (session) {
......
/*
* Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jdbc;
import java.sql.SQLException;
/**
* Allows us to compile on older platforms, while still implementing the methods
* from the newer JDBC API.
*/
public interface JdbcPreparedStatementBackwardsCompat {
// compatibility interface
// JDBC 4.2 (incomplete)
long executeLargeUpdate() throws SQLException;
}
......@@ -454,6 +454,14 @@ public class TestStatement extends TestBase {
ps.setString(2, "v6");
ps.addBatch();
assertTrue(Arrays.equals(new long[] {1, 1}, ps.executeLargeBatch()));
ps.setInt(1, 7);
ps.setString(2, "v7");
assertEquals(1, ps.executeUpdate());
assertEquals(1, ps.getUpdateCount());
ps.setInt(1, 8);
ps.setString(2, "v8");
assertEquals(1, ps.executeLargeUpdate());
assertEquals(1, ps.getLargeUpdateCount());
stat.execute("drop table test");
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论