Search in sources :

Example 51 with CommandContext

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

Example 52 with CommandContext

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

Example 53 with CommandContext

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;
        }
    });
}
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 54 with CommandContext

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);
    }
}
Also used : EventLoggerEventHandler(org.activiti.engine.impl.event.logger.handler.EventLoggerEventHandler) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) CommandContextCloseListener(org.activiti.engine.impl.interceptor.CommandContextCloseListener)

Example 55 with CommandContext

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());
}
Also used : MessageEntity(org.activiti.engine.impl.persistence.entity.MessageEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) Job(org.activiti.engine.runtime.Job)

Aggregations

CommandContext (org.activiti.engine.impl.interceptor.CommandContext)72 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)18 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)13 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)8 Date (java.util.Date)7 ActivitiException (org.activiti.engine.ActivitiException)7 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)7 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)6 HashMap (java.util.HashMap)4 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)4 Job (org.activiti.engine.runtime.Job)4 Deployment (org.activiti.engine.test.Deployment)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 List (java.util.List)3 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)3 DynamicBpmnService (org.activiti.engine.DynamicBpmnService)3 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)3