Search in sources :

Example 1 with CommandConfig

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);
    }
}
Also used : TransactionListener(org.activiti.engine.impl.cfg.TransactionListener) CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor)

Example 2 with CommandConfig

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;
        }
    });
}
Also used : CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Example 3 with CommandConfig

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"));
    }
}
Also used : CommandInvoker(org.activiti.engine.impl.interceptor.CommandInvoker) ActivitiException(org.activiti.engine.ActivitiException) CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) RetryInterceptor(org.activiti.engine.impl.interceptor.RetryInterceptor)

Example 4 with CommandConfig

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");
    }
}
Also used : CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 5 with CommandConfig

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);
}
Also used : CommandConfig(org.activiti.engine.impl.interceptor.CommandConfig)

Aggregations

CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)9 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)7 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)7 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)3 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)2 ActivitiException (org.activiti.engine.ActivitiException)1 TransactionListener (org.activiti.engine.impl.cfg.TransactionListener)1 CommandInvoker (org.activiti.engine.impl.interceptor.CommandInvoker)1 RetryInterceptor (org.activiti.engine.impl.interceptor.RetryInterceptor)1 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)1