@Test public void updateWorkflowInstance() throws InterruptedException { WorkflowInstance i1 = constructWorkflowInstanceBuilder().setStatus(created).build(); long id = dao.insertWorkflowInstance(i1); List<Long> ids = dao.pollNextWorkflowInstanceIds(1); assertThat(ids, contains(id)); DateTime started = now(); final WorkflowInstance i2 = new WorkflowInstance.Builder( dao.getWorkflowInstance(id, EnumSet.of(CURRENT_STATE_VARIABLES), null)).setStatus(inProgress).setState("updateState") .setStateText("update text").setStartedIfNotSet(started).build(); final WorkflowInstance polledInstance = dao.getWorkflowInstance(id, emptySet(), null); assertThat(polledInstance.status, equalTo(executing)); final DateTime originalModifiedTime = polledInstance.modified; sleep(1); WorkflowInstanceAction action = constructActionBuilder(id).build(); WorkflowInstance newWorkflow = constructWorkflowInstanceBuilder().setBusinessKey("newKey").build(); dao.updateWorkflowInstanceAfterExecution(i2, action, noChildWorkflows, asList(newWorkflow), false); jdbc.query("select * from nflow_workflow where id = " + id, new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { assertThat(rs.getString("status"), equalTo(inProgress.name())); assertThat(rs.getString("state"), equalTo(i2.state)); assertThat(rs.getString("state_text"), equalTo(i2.stateText)); assertThat(rs.getTimestamp("next_activation").getTime(), equalTo(i2.nextActivation.toDate().getTime())); assertThat(rs.getInt("executor_id") != 0, equalTo(i2.status == executing)); assertThat(rs.getTimestamp("modified").getTime(), greaterThan(originalModifiedTime.getMillis())); assertThat(rs.getTimestamp("started").getTime(), is(equalTo(started.getMillis()))); } }); QueryWorkflowInstances query = new QueryWorkflowInstances.Builder().setBusinessKey("newKey").build(); List<WorkflowInstance> instances = dao.queryWorkflowInstances(query); assertThat(instances.size(), is(1)); for (WorkflowInstance instance : instances) { assertThat(instance.parentWorkflowId, is(nullValue())); assertThat(instance.businessKey, is("newKey")); } }
public int updateWorkflowInstance(WorkflowInstance instance) { Object nextActivation = sqlVariants.toTimestampObject(instance.nextActivation); return jdbc.update(updateWorkflowInstanceSql(), instance.status.name(), instance.state, abbreviate(instance.stateText, getInstanceStateTextLength()), nextActivation, nextActivation, nextActivation, instance.status == executing ? executorInfo.getExecutorId() : null, instance.retries, toTimestamp(instance.started), instance.id); }
WorkflowInstanceDao { public int updateWorkflowInstance(WorkflowInstance instance) { Object nextActivation = sqlVariants.toTimestampObject(instance.nextActivation); return jdbc.update(updateWorkflowInstanceSql(), instance.status.name(), instance.state, abbreviate(instance.stateText, getInstanceStateTextLength()), nextActivation, nextActivation, nextActivation, instance.status == executing ? executorInfo.getExecutorId() : null, instance.retries, toTimestamp(instance.started), instance.id); } }
WorkflowInstanceDao { public int updateWorkflowInstance(WorkflowInstance instance) { Object nextActivation = sqlVariants.toTimestampObject(instance.nextActivation); return jdbc.update(updateWorkflowInstanceSql(), instance.status.name(), instance.state, abbreviate(instance.stateText, getInstanceStateTextLength()), nextActivation, nextActivation, nextActivation, instance.status == executing ? executorInfo.getExecutorId() : null, instance.retries, toTimestamp(instance.started), instance.id); } @Inject  WorkflowInstanceDao(SQLVariants sqlVariants, @NFlow JdbcTemplate nflowJdbcTemplate,
      @NFlow TransactionTemplate transactionTemplate, @NFlow NamedParameterJdbcTemplate nflowNamedParameterJdbcTemplate,
      ExecutorDao executorDao, WorkflowInstanceExecutor workflowInstanceExecutor, WorkflowInstanceFactory workflowInstanceFactory,
      Environment env); }
WorkflowInstanceDao { public int updateWorkflowInstance(WorkflowInstance instance) { Object nextActivation = sqlVariants.toTimestampObject(instance.nextActivation); return jdbc.update(updateWorkflowInstanceSql(), instance.status.name(), instance.state, abbreviate(instance.stateText, getInstanceStateTextLength()), nextActivation, nextActivation, nextActivation, instance.status == executing ? executorInfo.getExecutorId() : null, instance.retries, toTimestamp(instance.started), instance.id); } @Inject  WorkflowInstanceDao(SQLVariants sqlVariants, @NFlow JdbcTemplate nflowJdbcTemplate,
      @NFlow TransactionTemplate transactionTemplate, @NFlow NamedParameterJdbcTemplate nflowNamedParameterJdbcTemplate,
      ExecutorDao executorDao, WorkflowInstanceExecutor workflowInstanceExecutor, WorkflowInstanceFactory workflowInstanceFactory,
      Environment env); long insertWorkflowInstance(WorkflowInstance instance); @SuppressWarnings("null") void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action,
      List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction); int updateWorkflowInstance(WorkflowInstance instance); void recoverWorkflowInstancesFromDeadNodes(); void checkStateVariableValueLength(String name, String value); boolean updateNotRunningWorkflowInstance(WorkflowInstance instance); boolean wakeUpWorkflowExternally(long workflowInstanceId, List<String> expectedStates); boolean wakeupWorkflowInstanceIfNotExecuting(long workflowInstanceId, List<String> expectedStates); WorkflowInstance getWorkflowInstance(long id, Set<WorkflowInstanceInclude> includes, Long maxActions); List<Long> pollNextWorkflowInstanceIds(final int batchSize); List<WorkflowInstance> queryWorkflowInstances(QueryWorkflowInstances query); Stream<WorkflowInstance> queryWorkflowInstancesAsStream(QueryWorkflowInstances query); @Transactional(propagation = MANDATORY) long insertWorkflowInstanceAction(final WorkflowInstance instance, final WorkflowInstanceAction action); long insertWorkflowInstanceAction(final WorkflowInstanceAction action); String getWorkflowInstanceState(long workflowInstanceId); Optional<Integer> getSignal(long workflowInstanceId); @Transactional boolean setSignal(long workflowInstanceId, Optional<Integer> signal, String reason, WorkflowActionType actionType); String getWorkflowInstanceType(long workflowInstanceId); }
WorkflowInstanceDao { public int updateWorkflowInstance(WorkflowInstance instance) { Object nextActivation = sqlVariants.toTimestampObject(instance.nextActivation); return jdbc.update(updateWorkflowInstanceSql(), instance.status.name(), instance.state, abbreviate(instance.stateText, getInstanceStateTextLength()), nextActivation, nextActivation, nextActivation, instance.status == executing ? executorInfo.getExecutorId() : null, instance.retries, toTimestamp(instance.started), instance.id); } @Inject  WorkflowInstanceDao(SQLVariants sqlVariants, @NFlow JdbcTemplate nflowJdbcTemplate,
      @NFlow TransactionTemplate transactionTemplate, @NFlow NamedParameterJdbcTemplate nflowNamedParameterJdbcTemplate,
      ExecutorDao executorDao, WorkflowInstanceExecutor workflowInstanceExecutor, WorkflowInstanceFactory workflowInstanceFactory,
      Environment env); long insertWorkflowInstance(WorkflowInstance instance); @SuppressWarnings("null") void updateWorkflowInstanceAfterExecution(WorkflowInstance instance, WorkflowInstanceAction action,
      List<WorkflowInstance> childWorkflows, List<WorkflowInstance> workflows, boolean createAction); int updateWorkflowInstance(WorkflowInstance instance); void recoverWorkflowInstancesFromDeadNodes(); void checkStateVariableValueLength(String name, String value); boolean updateNotRunningWorkflowInstance(WorkflowInstance instance); boolean wakeUpWorkflowExternally(long workflowInstanceId, List<String> expectedStates); boolean wakeupWorkflowInstanceIfNotExecuting(long workflowInstanceId, List<String> expectedStates); WorkflowInstance getWorkflowInstance(long id, Set<WorkflowInstanceInclude> includes, Long maxActions); List<Long> pollNextWorkflowInstanceIds(final int batchSize); List<WorkflowInstance> queryWorkflowInstances(QueryWorkflowInstances query); Stream<WorkflowInstance> queryWorkflowInstancesAsStream(QueryWorkflowInstances query); @Transactional(propagation = MANDATORY) long insertWorkflowInstanceAction(final WorkflowInstance instance, final WorkflowInstanceAction action); long insertWorkflowInstanceAction(final WorkflowInstanceAction action); String getWorkflowInstanceState(long workflowInstanceId); Optional<Integer> getSignal(long workflowInstanceId); @Transactional boolean setSignal(long workflowInstanceId, Optional<Integer> signal, String reason, WorkflowActionType actionType); String getWorkflowInstanceType(long workflowInstanceId);  }