Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,30 +108,49 @@ 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);
}
}

@Override
public void cancel() throws TaskException {

public void cancel() {
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cancel() method signature was changed to remove the throws TaskException declaration, which is inconsistent with the parent class AbstractTask that declares public abstract void cancel() throws TaskException;. Even though the implementation throws TaskException on line 148, the signature should maintain the throws declaration for consistency with the parent class and other task implementations.

Suggested change
public void cancel() {
public void cancel() throws TaskException {

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cancel() method signature was changed to remove the throws TaskException declaration, which is inconsistent with the parent class AbstractTask that declares public abstract void cancel() throws TaskException;. Even though the implementation throws TaskException on line 148, the signature should maintain the throws declaration for consistency with the parent class and other task implementations.

ok,good

Statement stmt = this.sessionStatement;
if (stmt != null) {
try {
log.debug("Try to cancel this procedure task");
stmt.cancel();
setExitStatusCode(TaskConstants.EXIT_CODE_KILL);
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exit status code should be set to EXIT_CODE_KILL before attempting to cancel the statement. If stmt.cancel() throws an exception, the exit status will not be set, which could lead to incorrect task status reporting. Consider moving line 144 before line 143.

Suggested change
stmt.cancel();
setExitStatusCode(TaskConstants.EXIT_CODE_KILL);
setExitStatusCode(TaskConstants.EXIT_CODE_KILL);
stmt.cancel();

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exit status code should be set to EXIT_CODE_KILL before attempting to cancel the statement. If stmt.cancel() throws an exception, the exit status will not be set, which could lead to incorrect task status reporting. Consider moving line 144 before line 143.

good

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 http task failed", ex);
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message refers to "http task" but this is a procedure task. The message should be "Cancel procedure task failed" instead of "Cancel http task failed".

Suggested change
throw new TaskException("Cancel http task failed", ex);
throw new TaskException("Cancel procedure task failed", ex);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message refers to "http task" but this is a procedure task. The message should be "Cancel procedure task failed" instead of "Cancel http task failed".

nice

}
} 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
Loading