JBPM4中的variable (转)

2009 - 07 - 15

JBPM4中的variable

关键字: jbpm4

jbpm4中的 Variable 和 jbpm3 中的 Variable 区别不是很大,主要是加强了lob的处理。

数据库的表结构上,在jbpm3 中, 所有的 lob 默认以 1024 byte 为间隔(1024个byte一条记录) 存放在 bytearray中, 到了 jbpm4中 只剩下了一个表 jbpm4_lob ,并且不再将 lob进行拆分,并提供了一堆附加的操作类(都在lob包下)。

 

在jbpm4中,Variable 的作用域仅仅为 execution,execution结束时 Variable 会被删除。 若需要在流程结束后仍然能够获取到之前Variable,需要将 Variable中的 isHistoryEnabled设置为true(默认为false)

Java代码 复制代码
  1. protected boolean isHistoryEnabled = false;  
  protected boolean isHistoryEnabled = false;

 

但目前的4.0版本中似乎存在bug,将isHistoryEnabled设置为true后,Variable倒是能够在jbpm4_hist_var中查询到了,可是仅仅有key,值没有存下来。

又仔细研究了jbpm4的源码,原来jbpm4是在创建Variable是触发VariableCreate 事件,然后在设置Variable的value,在Variable的setValue中,又去触发VariableUpdate。

 

ScopeInstanceImpl.java

Java代码 复制代码
  1. variable.setKey(key);   
  2. variable.setExecution(getExecution());   
  3. variable.setTask(getTask());   
  4. variable.setHistoryEnabled(isHistoryEnabled);   
  5.   
  6. if (isHistoryEnabled) {   
  7.   HistoryEvent.fire(new VariableCreate(variable));   
  8. }   
  9.   
  10. variable.setValue(value);  
    variable.setKey(key);
    variable.setExecution(getExecution());
    variable.setTask(getTask());
    variable.setHistoryEnabled(isHistoryEnabled);

    if (isHistoryEnabled) {
      HistoryEvent.fire(new VariableCreate(variable));
    }
    
    variable.setValue(value);

 

Variable.java

Java代码 复制代码
  1. setObject(value);   
  2.   
  3. HistorySession historySession = Environment.getFromCurrent(HistorySession.classfalse);   
  4. if ( isHistoryEnabled    
  5.      && (historySession!=null)   
  6.    ) {   
  7.   HistoryEvent.fire(new VariableUpdate(this));   
  8. }  
    setObject(value);
    
    HistorySession historySession = Environment.getFromCurrent(HistorySession.class, false);
    if ( isHistoryEnabled 
         && (historySession!=null)
       ) {
      HistoryEvent.fire(new VariableUpdate(this));
    }
 

在VariableUpdate中,会将Variable的变更记录保存 jbpm4_hist_detail 表中

 

VariableUpdate.java

Java代码 复制代码
  1. @Override  
  2. public void process() {   
  3.   DbSession dbSession = Environment.getFromCurrent(DbSession.class);    
  4.   HistoryVariableImpl historyVariable = dbSession.get(HistoryVariableImpl.class, variable.getDbid());   
  5.   historyVariable.updated(variable);   
  6. }  
  @Override
  public void process() {
    DbSession dbSession = Environment.getFromCurrent(DbSession.class); 
    HistoryVariableImpl historyVariable = dbSession.get(HistoryVariableImpl.class, variable.getDbid());
    historyVariable.updated(variable);
  }

 HistoryVariableImpl.java

Java代码 复制代码
  1. public void updated(Variable variable) {   
  2.   String newValue = variable.getTextValue();   
  3.   if ( (value==null && newValue!=null)   
  4.        || (value!=null && (!value.equals(newValue)))   
  5.      ) {   
  6.     addDetail(new HistoryVariableUpdateImpl(value, newValue));   
  7.   }   
  8. }   
  9.   
  10. public void addDetail(HistoryDetailImpl detail) {   
  11.   detail.setHistoryVariable(this, nextDetailIndex);   
  12.   nextDetailIndex++;   
  13. }  
  public void updated(Variable variable) {
    String newValue = variable.getTextValue();
    if ( (value==null && newValue!=null)
         || (value!=null && (!value.equals(newValue)))
       ) {
      addDetail(new HistoryVariableUpdateImpl(value, newValue));
    }
  }
  
  public void addDetail(HistoryDetailImpl detail) {
    detail.setHistoryVariable(this, nextDetailIndex);
    nextDetailIndex++;
  }

 

在HistoryVariableImpl.java 中可以看到,update操作仅仅生成了一个 HistoryVariableUpdateImpl的实例,确没有将这个实例添加到 HistoryVariableImpl 的 details 中

Java代码 复制代码
  1. /** only here to get hibernate cascade */  
  2. protected Set<HistoryDetailImpl> details = new HashSet<HistoryDetailImpl>();  
  /** only here to get hibernate cascade */
  protected Set<HistoryDetailImpl> details = new HashSet<HistoryDetailImpl>();

 

因此在数据库的  jbpm4_hist_detail 表中查询不到任何数据。 

补充: 刚刚查到,原来 jbpm4.0 中 关于History Variable 的 代码虽然提交了,但还没有完成,也就是说还不能用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值