Details
-
Feature Request
-
Resolution: Won't Do
-
L3 - Default
-
None
-
7.14.4
-
None
Description
User Story (Required on creation):
As a process application developer, I want to be able to execute Camunda Commands outside of a Camunda initiated context transaction.
Functional Requirements (Required before implementation):
Being able to execute commands arbitrary from the thread local context.
Technical Requirements (Required before implementation):
Provide an Adapter interface that can either execute on Context or Executor.
I have been using this frequently in various projects and came up with this solution (see hint). I would love to have this in the engine core so I do not have to re-invent it for every project.
Hints (Optional):
/**
{{ * Adapter that hides the execution of a camunda {@link Command}, works with {@link org.camunda.bpm.engine.impl.interceptor.CommandContext} when called inside}}
{{ * a camunda {@link org.camunda.bpm.engine.delegate.JavaDelegate} or Listener but uses {@link ProcessEngineConfigurationImpl#getCommandExecutorTxRequired()}}}
{{ * to get a new context when called elsewhere.}}
{{ */}}
public interface CommandExecutorAdapter {
static CommandExecutorAdapter create(CommandContext commandContext) {
return new CommandExecutorAdapter() {
@Override
public <T> T execute(Command<T> command) {
return command.execute(commandContext);
{{ }}}
};
{{ }}}
static CommandExecutorAdapter create(ProcessEngineConfigurationImpl configuration) {
return new CommandExecutorAdapter() {
@Override
public <T> T execute(Command<T> command) {
if (Context.getCommandContext() == null) {
return configuration.getCommandExecutorTxRequired().execute(command);
} else {
return command.execute(Context.getCommandContext());
{{ }}}
}
};
{{ }}}
<T> T execute(Command<T> command);
}