public void schedule(TimerEntity timer) { Date duedate = timer.getDuedate(); if (duedate == null) { throw new ActivitiException("duedate is null"); } CommandContext commandContext = Context.getCommandContext(); commandContext.getDbSqlSession().insert(timer); // Check if this timer fires before the next time the job executor will check for new timers to // fire. // This is highly unlikely because normally waitTimeInMillis is 5000 (5 seconds) // and timers are usually set further in the future JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor(); int waitTimeInMillis = jobExecutor.getWaitTimeInMillis(); if (duedate.getTime() < (ClockUtil.getCurrentTime().getTime() + waitTimeInMillis)) { // then notify the job executor. commandContext .getTransactionContext() .addTransactionListener( TransactionState.COMMITTED, new MessageAddedNotification(jobExecutor)); } }
public void send(MessageEntity message) { CommandContext commandContext = Context.getCommandContext(); commandContext.getDbSqlSession().insert(message); JobExecutor jobExecutor = Context.getProcessEngineConfiguration().getJobExecutor(); commandContext .getTransactionContext() .addTransactionListener( TransactionState.COMMITTED, new MessageAddedNotification(jobExecutor)); }
public void insert(ExecutionEntity execution) { CommandContext commandContext = Context.getCommandContext(); DbSqlSession dbSqlSession = commandContext.getDbSqlSession(); dbSqlSession.insert(this); if (execution != null) { execution.addTask(this); } commandContext.getHistoryManager().recordTaskCreated(this, execution); }
public void update() { // Needed to make history work: the setter will also update the historic task setOwner(this.getOwner()); setAssignee(this.getAssignee()); setDelegationState(this.getDelegationState()); setName(this.getName()); setDescription(this.getDescription()); setPriority(this.getPriority()); setCreateTime(this.getCreateTime()); setDueDate(this.getDueDate()); setParentTaskId(this.getParentTaskId()); CommandContext commandContext = Context.getCommandContext(); DbSqlSession dbSqlSession = commandContext.getDbSqlSession(); dbSqlSession.update(this); }
@Override public void execute(JobHandler jobHandler, CommandContext commandContext) { super.execute(jobHandler, commandContext); if (repeat == null) { if (log.isLoggable(Level.FINE)) { log.fine("Timer " + getId() + " fired. Deleting timer."); } commandContext.getDbSqlSession().delete(JobEntity.class, id); } else { // TODO calculate repeat throw new UnsupportedOperationException("repeat not yet supported"); } }
public ExecutionEntity createProcessInstance(String businessKey, ActivityImpl initial) { ExecutionEntity processInstance = null; if (initial == null) { processInstance = (ExecutionEntity) super.createProcessInstance(); } else { processInstance = (ExecutionEntity) super.createProcessInstanceForInitial(initial); } CommandContext commandContext = Context.getCommandContext(); processInstance.setExecutions(new ArrayList<ExecutionEntity>()); processInstance.setProcessDefinition(processDefinition); // Do not initialize variable map (let it happen lazily) if (businessKey != null) { processInstance.setBusinessKey(businessKey); } // reset the process instance in order to have the db-generated process instance id available processInstance.setProcessInstance(processInstance); String initiatorVariableName = (String) getProperty(BpmnParse.PROPERTYNAME_INITIATOR_VARIABLE_NAME); if (initiatorVariableName != null) { String authenticatedUserId = Authentication.getAuthenticatedUserId(); processInstance.setVariable(initiatorVariableName, authenticatedUserId); } int historyLevel = Context.getProcessEngineConfiguration().getHistoryLevel(); // TODO: This smells bad, as the rest of the history is done via the ParseListener if (historyLevel >= ProcessEngineConfigurationImpl.HISTORYLEVEL_ACTIVITY) { HistoricProcessInstanceEntity historicProcessInstance = new HistoricProcessInstanceEntity(processInstance); commandContext.getSession(DbSqlSession.class).insert(historicProcessInstance); // do basically the same as in ActivityInstanceStanrtHandler IdGenerator idGenerator = Context.getProcessEngineConfiguration().getIdGenerator(); String processDefinitionId = processInstance.getProcessDefinitionId(); String processInstanceId = processInstance.getProcessInstanceId(); String executionId = processInstance.getId(); HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity(); historicActivityInstance.setId(idGenerator.getNextId()); historicActivityInstance.setProcessDefinitionId(processDefinitionId); historicActivityInstance.setProcessInstanceId(processInstanceId); historicActivityInstance.setExecutionId(executionId); historicActivityInstance.setActivityId(processInstance.getActivityId()); historicActivityInstance.setActivityName( (String) processInstance.getActivity().getProperty("name")); historicActivityInstance.setActivityType( (String) processInstance.getActivity().getProperty("type")); Date now = ClockUtil.getCurrentTime(); historicActivityInstance.setStartTime(now); commandContext.getDbSqlSession().insert(historicActivityInstance); } return processInstance; }
@SuppressWarnings("unchecked") protected void addMessageEventSubscriptions(ProcessDefinitionEntity processDefinition) { CommandContext commandContext = Context.getCommandContext(); List<EventSubscriptionDeclaration> eventDefinitions = (List<EventSubscriptionDeclaration>) processDefinition.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION); if (eventDefinitions != null) { Set<String> messageNames = new HashSet<String>(); for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) { if (eventDefinition.getEventType().equals("message") && eventDefinition.isStartEvent()) { if (!messageNames.contains(eventDefinition.getEventName())) { messageNames.add(eventDefinition.getEventName()); } else { throw new ActivitiException( "Cannot deploy process definition '" + processDefinition.getResourceName() + "': there are multiple message event subscriptions for the message with name '" + eventDefinition.getEventName() + "'."); } // look for subscriptions for the same name in db: List<EventSubscriptionEntity> subscriptionsForSameMessageName = commandContext .getEventSubscriptionEntityManager() .findEventSubscriptionsByName( MessageEventHandler.EVENT_HANDLER_TYPE, eventDefinition.getEventName(), processDefinition.getTenantId()); // also look for subscriptions created in the session: List<MessageEventSubscriptionEntity> cachedSubscriptions = commandContext.getDbSqlSession().findInCache(MessageEventSubscriptionEntity.class); for (MessageEventSubscriptionEntity cachedSubscription : cachedSubscriptions) { if (eventDefinition.getEventName().equals(cachedSubscription.getEventName()) && !subscriptionsForSameMessageName.contains(cachedSubscription)) { subscriptionsForSameMessageName.add(cachedSubscription); } } // remove subscriptions deleted in the same command subscriptionsForSameMessageName = commandContext .getDbSqlSession() .pruneDeletedEntities(subscriptionsForSameMessageName); for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsForSameMessageName) { // throw exception only if there's already a subscription as start event // no process instance-id = it's a message start event if (StringUtils.isEmpty(eventSubscriptionEntity.getProcessInstanceId())) { throw new ActivitiException( "Cannot deploy process definition '" + processDefinition.getResourceName() + "': there already is a message event subscription for the message with name '" + eventDefinition.getEventName() + "'."); } } MessageEventSubscriptionEntity newSubscription = new MessageEventSubscriptionEntity(); newSubscription.setEventName(eventDefinition.getEventName()); newSubscription.setActivityId(eventDefinition.getActivityId()); newSubscription.setConfiguration(processDefinition.getId()); newSubscription.setProcessDefinitionId(processDefinition.getId()); if (processDefinition.getTenantId() != null) { newSubscription.setTenantId(processDefinition.getTenantId()); } newSubscription.insert(); } } } }