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)
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
variable.setKey(key);
variable.setExecution(getExecution());
variable.setTask(getTask());
variable.setHistoryEnabled(isHistoryEnabled);
if (isHistoryEnabled) {
HistoryEvent.fire(new VariableCreate(variable));
}
variable.setValue(value);
Variable.java
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
@Override
public void process() {
DbSession dbSession = Environment.getFromCurrent(DbSession.class);
HistoryVariableImpl historyVariable = dbSession.get(HistoryVariableImpl.class, variable.getDbid());
historyVariable.updated(variable);
}
HistoryVariableImpl.java
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 中
/** only here to get hibernate cascade */
protected Set<HistoryDetailImpl> details = new HashSet<HistoryDetailImpl>();
因此在数据库的 jbpm4_hist_detail 表中查询不到任何数据。
补充: 刚刚查到,原来 jbpm4.0 中 关于History Variable 的 代码虽然提交了,但还没有完成,也就是说还不能用