Canceling a Statement
NuoDB does not support a Statement#cancel()
call, but does supply killStatement()
in the implementation class RemStatement
.
Implementing Statement#cancel()
in NuoDB’s JDBC driver is complicated because each connection to a TE processes requests synchronously (any attempt to cancel would only run after that statement has already completed).
To use RemStatement#killStatement()
, cast a Statement
object to RemStatement
and supply the connection URL and connection properties, including credentials. This will cause a second connection to be created and a KILL STATEMENT
command to be executed.
The internal class RemStatement is potentially subject to change, although it is unlikely that NuoDB would remove this method.
Care should be taken when upgrading the JDBC driver to check that any code using RemStatement still compiles.
|
/* Assume pStatement is a PreparedStatement object that needs to be killed... */
final String dburl = "jdbc:com.nuodb://host:48004/my_database";
final Properties properties = new Properties()
{
{
put("user", getDBUser());
put("password", getDBPassword());
put("schema", getDBSchema());
}
};
RemStatement remStmt = null;
if (statement instanceof RemStatement)
/* Simple cast to subtype */
remStmt = ((RemStatement)pStatement);
else {
try {
/* statement may be a proxy wrapping an actual Statement instance */
remStmt= statement.unwrap(RemStatement.class);
}
catch (ClassCastException e)
logger.warn("Unable to kill statement, request ignored.");
}
if (remStmt != null)
remStmt.killStatement(dburl, properties);
Statement.isWrapperFor() returns false in all cases and should not be used.
|