use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class GroupEntityManager method updateGroup.
public void updateGroup(Group updatedGroup) {
CommandContext commandContext = Context.getCommandContext();
DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
dbSqlSession.update((GroupEntity) updatedGroup);
if (getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, updatedGroup));
}
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class ModelEntityManager method updateModel.
public void updateModel(ModelEntity updatedModel) {
CommandContext commandContext = Context.getCommandContext();
updatedModel.setLastUpdateTime(Context.getProcessEngineConfiguration().getClock().getCurrentTime());
DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
dbSqlSession.update(updatedModel);
if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, updatedModel));
}
}
use of org.activiti.engine.impl.interceptor.CommandContext 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.CommandContext in project Activiti by Activiti.
the class EventLogger method onEvent.
@Override
public void onEvent(ActivitiEvent event) {
EventLoggerEventHandler eventHandler = getEventHandler(event);
if (eventHandler != null) {
// Events are flushed when command context is closed
CommandContext currentCommandContext = Context.getCommandContext();
EventFlusher eventFlusher = (EventFlusher) currentCommandContext.getAttribute(EVENT_FLUSHER_KEY);
if (eventHandler != null && eventFlusher == null) {
eventFlusher = createEventFlusher();
if (eventFlusher == null) {
// Default
eventFlusher = new DatabaseEventFlusher();
}
currentCommandContext.addAttribute(EVENT_FLUSHER_KEY, eventFlusher);
currentCommandContext.addCloseListener(eventFlusher);
currentCommandContext.addCloseListener(new CommandContextCloseListener() {
@Override
public void closing(CommandContext commandContext) {
}
@Override
public void closed(CommandContext commandContext) {
// For those who are interested: we can now broadcast the events were added
if (listeners != null) {
for (EventLoggerListener listener : listeners) {
listener.eventsAdded(EventLogger.this);
}
}
}
});
}
eventFlusher.addEventHandler(eventHandler);
}
}
use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.
the class JobExecutorCmdExceptionTest method testJobCommandsWith3Exceptions.
public void testJobCommandsWith3Exceptions() {
tweetExceptionHandler.setExceptionsRemaining(3);
commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
MessageEntity message = createTweetExceptionMessage();
commandContext.getJobEntityManager().send(message);
return message.getId();
}
});
Job job = managementService.createJobQuery().singleResult();
assertEquals(3, job.getRetries());
try {
managementService.executeJob(job.getId());
fail("exception expected");
} catch (Exception e) {
// exception expected;
}
job = managementService.createJobQuery().singleResult();
assertEquals(2, job.getRetries());
try {
managementService.executeJob(job.getId());
fail("exception expected");
} catch (Exception e) {
// exception expected;
}
job = managementService.createJobQuery().singleResult();
assertEquals(1, job.getRetries());
try {
managementService.executeJob(job.getId());
fail("exception expected");
} catch (Exception e) {
// exception expected;
}
job = managementService.createJobQuery().singleResult();
assertEquals(0, job.getRetries());
managementService.deleteJob(job.getId());
}
Aggregations