use of org.activiti.engine.impl.interceptor.CommandConfig in project Activiti by Activiti.
the class DbSchemaUpdate 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).dbSchemaUpdate();
return null;
}
});
}
use of org.activiti.engine.impl.interceptor.CommandConfig in project Activiti by Activiti.
the class AbstractActivitiTestCase 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() throws Throwable {
log.debug("verifying that db is clean after test");
Map<String, Long> tableCounts = managementService.getTableCount();
StringBuilder outputMessage = new StringBuilder();
for (String tableName : tableCounts.keySet()) {
String tableNameWithoutPrefix = tableName.replace(processEngineConfiguration.getDatabaseTablePrefix(), "");
if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
Long count = tableCounts.get(tableName);
if (count != 0L) {
outputMessage.append(" ").append(tableName).append(": ").append(count).append(" 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;
}
});
if (exception != null) {
throw exception;
} else {
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 SpringTransactionContext method addTransactionListener.
public void addTransactionListener(final TransactionState transactionState, final TransactionListener transactionListener) {
if (transactionState.equals(TransactionState.COMMITTING)) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void beforeCommit(boolean readOnly) {
transactionListener.execute(commandContext);
}
});
} else if (transactionState.equals(TransactionState.COMMITTED)) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCommit() {
CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
commandExecutor.execute(commandConfig, new Command<Void>() {
public Void execute(CommandContext commandContext) {
transactionListener.execute(commandContext);
return null;
}
});
}
});
} else if (transactionState.equals(TransactionState.ROLLINGBACK)) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void beforeCompletion() {
transactionListener.execute(commandContext);
}
});
} else if (transactionState.equals(TransactionState.ROLLED_BACK)) {
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
@Override
public void afterCompletion(int status) {
if (TransactionSynchronization.STATUS_ROLLED_BACK == status) {
CommandExecutor commandExecutor = commandContext.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig commandConfig = new CommandConfig(false, TransactionPropagation.REQUIRES_NEW);
commandExecutor.execute(commandConfig, new Command<Void>() {
public Void execute(CommandContext commandContext) {
transactionListener.execute(commandContext);
return null;
}
});
}
}
});
}
}
use of org.activiti.engine.impl.interceptor.CommandConfig in project Activiti by Activiti.
the class TimerEventCompatibilityTest method changeConfigurationToPlainText.
protected void changeConfigurationToPlainText(JobEntity job) {
String activityId = TimerEventHandler.getActivityIdFromConfiguration(job.getJobHandlerConfiguration());
final JobEntity finalJob = job;
CommandExecutor commandExecutor = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
final String finalActivityId = activityId;
commandExecutor.execute(config, new Command<Object>() {
public Object execute(CommandContext commandContext) {
DbSqlSession session = commandContext.getSession(DbSqlSession.class);
session.delete(finalJob);
session.flush();
session.commit();
return null;
}
});
commandExecutor.execute(config, new Command<Object>() {
public Object execute(CommandContext commandContext) {
DbSqlSession session = commandContext.getSession(DbSqlSession.class);
finalJob.setJobHandlerConfiguration(finalActivityId);
finalJob.setId(null);
session.insert(finalJob);
session.flush();
session.commit();
return null;
}
});
}
Aggregations