Java Code Examples for org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity#setVariableLocal()

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity#setVariableLocal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultContextAssociationManager.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void setVariableLocal(String variableName, Object value) {
  ExecutionEntity execution = getExecutionFromContext();
  if(execution != null) {
    execution.setVariableLocal(variableName, value);
    execution.getVariableLocal(variableName);
  } else {
    getScopedAssociation().setVariableLocal(variableName, value);
  }
}
 
Example 2
Source File: CompensationUtil.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
/**
 * creates an event scope for the given execution:
 *
 * create a new event scope execution under the parent of the given execution
 * and move all event subscriptions to that execution.
 *
 * this allows us to "remember" the event subscriptions after finishing a
 * scope
 */
public static void createEventScopeExecution(ExecutionEntity execution) {

  // parent execution is a subprocess or a miBody
  ActivityImpl activity = execution.getActivity();
  ExecutionEntity scopeExecution = (ExecutionEntity) execution.findExecutionForFlowScope(activity.getFlowScope());

  List<EventSubscriptionEntity> eventSubscriptions = execution.getCompensateEventSubscriptions();

  if (eventSubscriptions.size() > 0 || hasCompensationEventSubprocess(activity)) {

    ExecutionEntity eventScopeExecution = scopeExecution.createExecution();
    eventScopeExecution.setActivity(execution.getActivity());
    eventScopeExecution.activityInstanceStarting();
    eventScopeExecution.enterActivityInstance();
    eventScopeExecution.setActive(false);
    eventScopeExecution.setConcurrent(false);
    eventScopeExecution.setEventScope(true);

    // copy local variables to eventScopeExecution by value. This way,
    // the eventScopeExecution references a 'snapshot' of the local variables
    Map<String, Object> variables = execution.getVariablesLocal();
    for (Entry<String, Object> variable : variables.entrySet()) {
      eventScopeExecution.setVariableLocal(variable.getKey(), variable.getValue());
    }

    // set event subscriptions to the event scope execution:
    for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptions) {
      EventSubscriptionEntity newSubscription =
              EventSubscriptionEntity.createAndInsert(
                      eventScopeExecution,
                      EventType.COMPENSATE,
                      eventSubscriptionEntity.getActivity());
      newSubscription.setConfiguration(eventSubscriptionEntity.getConfiguration());
      // use the original date
      newSubscription.setCreated(eventSubscriptionEntity.getCreated());
    }

    // set existing event scope executions as children of new event scope execution
    // (ensuring they don't get removed when 'execution' gets removed)
    for (PvmExecutionImpl childEventScopeExecution : execution.getEventScopeExecutions()) {
      childEventScopeExecution.setParent(eventScopeExecution);
    }

    ActivityImpl compensationHandler = getEventScopeCompensationHandler(execution);
    EventSubscriptionEntity eventSubscription = EventSubscriptionEntity
            .createAndInsert(
              scopeExecution,
              EventType.COMPENSATE,
              compensationHandler
            );
    eventSubscription.setConfiguration(eventScopeExecution.getId());

  }
}
 
Example 3
Source File: CompetingByteVariableAccessTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public Void execute(CommandContext commandContext) {

      ExecutionEntity execution = commandContext.getExecutionManager()
        .findExecutionById(executionId);

      // fetch the variable instance but not the value (make sure the byte array is lazily fetched)
      VariableInstanceEntity varInstance = (VariableInstanceEntity) execution.getVariableInstanceLocal(varName);
      String byteArrayValueId = varInstance.getByteArrayValueId();
      assertNotNull("Byte array id is expected to be not null", byteArrayValueId);

      CachedDbEntity cachedByteArray = commandContext.getDbEntityManager().getDbEntityCache()
        .getCachedEntity(ByteArrayEntity.class, byteArrayValueId);

      assertNull("Byte array is expected to be not fetched yet / lazily fetched.", cachedByteArray);

      monitor.sync();

      // now update the value
      execution.setVariableLocal(varInstance.getName(), newValue);

      return null;
    }