在 CommandInterceptor 中检索 executionId

Retrieve executionId inside CommandInterceptor

我正在像这样实现我自己的 Activiti 命令拦截器:

public class ActivitiCommandInterceptor extends AbstractCommandInterceptor {
    private RuntimeService runtimeService;
    private CommandInterceptor delegate;

    public ActivitiSpringTxCommandInterceptor(RuntimeService runtimeService, CommandInterceptor delegate) {
        this.runtimeService = runtimeService;
        this.delegate=delegate;
    }

    @Override
    public <T> T execute(CommandConfig config, Command<T> command) {
        String myVariable = runtimeService.getVariable(<missingExecutionId>, "myVariableName");

        ...
    }
}

execute() 方法中,我需要从与此命令相关的执行上下文中检索一个变量。

为此,我需要 executionId,但找不到检索它的方法。

如何从这个拦截器中获取我的变量?

谢谢

您可以创建一个 nativeExecutionQuery 这样我们就可以使用SQL直接对DB进行操作了。

对于您的情况,只需找到包含您的变量的所有执行 ID,并根据您的需要进行过滤。