Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -60,6 +61,8 @@ public class ProcedureTask extends AbstractTask {

private final ProcedureTaskExecutionContext procedureTaskExecutionContext;

private volatile Statement sessionStatement;

/**
* constructor
*
Expand Down Expand Up @@ -105,21 +108,26 @@ public void handle(TaskCallBack taskCallBack) throws TaskException {
}
String proceduerSql = formatSql(sqlParamsMap, paramsMap);
// call method
try (CallableStatement stmt = connection.prepareCall(proceduerSql)) {
try (CallableStatement tmpStatement = connection.prepareCall(proceduerSql)) {
sessionStatement = tmpStatement;
// set timeout
setTimeout(stmt);
setTimeout(tmpStatement);

// outParameterMap
Map<Integer, Property> outParameterMap = getOutParameterMap(stmt, sqlParamsMap, paramsMap);
Map<Integer, Property> outParameterMap = getOutParameterMap(tmpStatement, sqlParamsMap, paramsMap);

stmt.executeUpdate();
tmpStatement.executeUpdate();

// print the output parameters to the log
printOutParameter(stmt, outParameterMap);
printOutParameter(tmpStatement, outParameterMap);

setExitStatusCode(EXIT_CODE_SUCCESS);
}
} catch (Exception e) {
if (exitStatusCode == TaskConstants.EXIT_CODE_KILL) {
log.info("procedure task has been killed");
return;
}
setExitStatusCode(EXIT_CODE_FAILURE);
log.error("procedure task error", e);
throw new TaskException("Execute procedure task failed", e);
Expand All @@ -128,7 +136,21 @@ public void handle(TaskCallBack taskCallBack) throws TaskException {

@Override
public void cancel() throws TaskException {

Statement stmt = this.sessionStatement;
if (stmt != null) {
try {
log.debug("Try to cancel this procedure task");
setExitStatusCode(TaskConstants.EXIT_CODE_KILL);
stmt.cancel();
log.debug("this procedure task was canceled");
} catch (SQLException ex) {
log.warn("Failed to cancel stored procedure (driver/DB may not support it)", ex);
throw new TaskException("Cancel procedure task failed", ex);
}
} else {
log.warn(
"Attempted to cancel procedure task, but no active statement exists. Possible reasons: task not started, already completed, or canceled.");
}
}

private String formatSql(Map<Integer, Property> sqlParamsMap, Map<String, Property> paramsMap) {
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.