use of org.activiti.engine.impl.interceptor.CommandConfig in project Activiti by Activiti.
the class StandaloneMybatisTransactionContext method fireTransactionEvent.
/**
* Fires the event for the provided {@link TransactionState}.
*
* @param transactionState The {@link TransactionState} for which the listeners will be called.
* @param executeInNewContext If true, the listeners will be called in a new command context.
* This is needed for example when firing the {@link TransactionState#COMMITTED}
* event: the transaction is already committed and executing logic in the same
* context could lead to strange behaviour (for example doing a {@link SqlSession#update(String)}
* would actually roll back the update (as the MyBatis context is already committed
* and the internal flags have not been correctly set).
*/
protected void fireTransactionEvent(TransactionState transactionState, boolean executeInNewContext) {
if (stateTransactionListeners == null) {
return;
}
final List<TransactionListener> transactionListeners = stateTransactionListeners.get(transactionState);
if (transactionListeners == null) {
return;
}
if (executeInNewContext) {
CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
commandExecutor.execute(commandConfig, new Command<Void>() {
public Void execute(CommandContext commandContext) {
executeTransactionListeners(transactionListeners, commandContext);
return null;
}
});
} else {
executeTransactionListeners(transactionListeners, commandContext);
}
}
use of org.activiti.engine.impl.interceptor.CommandConfig in project Activiti by Activiti.
the class DbSchemaDrop method main.
public static void main(String[] args) {
ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new Command<Object>() {
public Object execute(CommandContext commandContext) {
commandContext.getSession(DbSqlSession.class).dbSchemaDrop();
return null;
}
});
}
use of org.activiti.engine.impl.interceptor.CommandConfig in project Activiti by Activiti.
the class RetryInterceptorTest method testRetryInterceptor.
public void testRetryInterceptor() {
RetryInterceptor retryInterceptor = new RetryInterceptor();
retryInterceptor.setNext(new CommandInvoker());
try {
retryInterceptor.execute(new CommandConfig(), new CommandThrowingOptimisticLockingException());
fail("ActivitiException expected.");
} catch (ActivitiException e) {
assertTrue(e.getMessage().contains(retryInterceptor.getNumOfRetries() + " retries failed"));
}
}
use of org.activiti.engine.impl.interceptor.CommandConfig in project Activiti by Activiti.
the class AbstractMuleTest method assertAndEnsureCleanDb.
/** Each test is assumed to clean up all DB content it entered.
* After a test method executed, this method scans all tables to see if the DB is completely clean.
* It throws AssertionFailed in case the DB is not clean.
* If the DB is not clean, it is cleaned by performing a create a drop. */
protected void assertAndEnsureCleanDb(ProcessEngine processEngine) throws Exception {
log.debug("verifying that db is clean after test");
Map<String, Long> tableCounts = processEngine.getManagementService().getTableCount();
StringBuilder outputMessage = new StringBuilder();
for (String tableName : tableCounts.keySet()) {
String tableNameWithoutPrefix = tableName.replace(processEngine.getProcessEngineConfiguration().getDatabaseTablePrefix(), "");
if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
Long count = tableCounts.get(tableName);
if (count != 0L) {
outputMessage.append(" " + tableName + ": " + count + " record(s) ");
}
}
}
if (outputMessage.length() > 0) {
outputMessage.insert(0, "DB NOT CLEAN: \n");
log.error(EMPTY_LINE);
log.error(outputMessage.toString());
log.info("dropping and recreating db");
CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new Command<Object>() {
public Object execute(CommandContext commandContext) {
DbSqlSession session = commandContext.getSession(DbSqlSession.class);
session.dbSchemaDrop();
session.dbSchemaCreate();
return null;
}
});
Assert.fail(outputMessage.toString());
} else {
log.info("database was clean");
}
}
use of org.activiti.engine.impl.interceptor.CommandConfig in project Activiti by Activiti.
the class FailedJobListener method execute.
public void execute(CommandContext commandContext) {
CommandConfig commandConfig = commandExecutor.getDefaultConfig().transactionRequiresNew();
FailedJobCommandFactory failedJobCommandFactory = commandContext.getFailedJobCommandFactory();
Command<Object> cmd = failedJobCommandFactory.getCommand(jobId, exception);
log.trace("Using FailedJobCommandFactory '" + failedJobCommandFactory.getClass() + "' and command of type '" + cmd.getClass() + "'");
commandExecutor.execute(commandConfig, cmd);
}
Aggregations