5 Replies Latest reply on Jun 9, 2010 1:43 PM by Maciej Swiderski

    variable declaration and history support

    Alejandro Guizar Master

      A previous discussion touched the subject of JBPM-2506. While the proposed code looks great I noticed a particularity I wanted to discuss. ExecutionService has gained the following methods:

      /** creates or overwrites a variable value on the referenced execution and marks the variable to be stored in history*/
      void setVariable(String executionId, String name, Object value, boolean historyEnabled);
        
      /** creates or overwrites the variable values on the referenced execution and marks the variables to be stored in history*/
      void setVariables(String executionId, Map<String, ?> variables, boolean historyEnabled);
      

      These methods eventually reach a new overload for ScopeInstanceImpl.setVariable()

      public void setVariable(String key, Object value, boolean historyEnabled) {
        // ...
        if (variable!=null) {
          log.debug("updating variable '"+key+"' in '"+this+"' to value '"+value+"'");
          variable.setValue(value, this);
        } else if (getParentVariableScope()==null) {
          createVariable(key, value, null, historyEnabled);
        } else {
          getParentVariableScope().setVariable(key,value, historyEnabled);
        }
      }
      

      Notice that, if the variable already exists, historyEnabled is ignored. On the other hand, ExecutionService does not expose the createVariable methods of ScopeInstanceImpl. Method createVariable is sometimes useful since setVariable always tries to create the variable in the parent scope.

       

      My proposal is to make the following additions to ExecutionService instead. This way we expose useful new functionality and ensure that the historyEnabled flag is always observed.

      /** creates a variable value on the referenced execution. optionally marks the variable to be stored in history*/
      void createVariable(String executionId, String name, Object value, boolean historyEnabled);
        
      /** creates variable values on the referenced execution. optionally marks the variables to be stored in history*/
      void createVariables(String executionId, Map<String, ?> variables, boolean historyEnabled);