提交 a36df18f 编写于 作者: F frederikheremans

Merge pull request #174 from smirzai/act-1082

fix act-1839
......@@ -103,9 +103,23 @@ public class DbSqlSession implements Session {
this.connectionMetadataDefaultCatalog = catalog;
this.connectionMetadataDefaultSchema = schema;
}
// Touch ///////////////////////////////////////////////////////////////////
// brings the given persistenObject to the top if it already exists
public void touch(PersistentObject persistentObject) {
if (persistentObject.getId()==null) {
throw new ActivitiException("Cannot touch " + persistentObject.getClass() + " with no id");
}
if (insertedObjects.contains(persistentObject)) {
insertedObjects.remove(persistentObject);
insertedObjects.add(persistentObject);
cachePut(persistentObject, false);
}
}
// insert ///////////////////////////////////////////////////////////////////
public void insert(PersistentObject persistentObject) {
if (persistentObject.getId()==null) {
String id = dbSqlSessionFactory.getIdGenerator().getNextId();
......@@ -1125,4 +1139,6 @@ public class DbSqlSession implements Session {
public DbSqlSessionFactory getDbSqlSessionFactory() {
return dbSqlSessionFactory;
}
}
......@@ -55,6 +55,13 @@ public class VariableInstanceEntity implements ValueFields, PersistentObject, Ha
protected VariableInstanceEntity() {
}
public static void touch(VariableInstanceEntity variableInstance) {
Context.getCommandContext()
.getDbSqlSession()
.touch(variableInstance);
}
public static VariableInstanceEntity createAndInsert(String name, VariableType type, Object value) {
VariableInstanceEntity variableInstance = create(name, type, value);
......
......@@ -349,8 +349,10 @@ public abstract class VariableScopeImpl implements Serializable, VariableScope {
variableInstance.setValue(null);
variableInstance.setType(newType);
variableInstance.forceUpdate();
}
variableInstance.setValue(value);
variableInstance.setValue(value);
VariableInstanceEntity.touch(variableInstance);
} else
variableInstance.setValue(value);
Context.getCommandContext().getHistoryManager()
.recordHistoricDetailVariableCreate(variableInstance, sourceActivityExecution, isActivityIdUsedForDetails());
......
package org.activiti.examples.variables;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
public class ChangeVariableType implements JavaDelegate {
public void execute(DelegateExecution execution) throws Exception {
// Initially set to null, stored as NullType
execution.setVariable("myVar", null);
// Now set to something stored as SerializableType. This could happen much later on than this.
execution.setVariable("myVar", new SomeSerializable("someValue"));
}
}
package org.activiti.examples.variables;
import java.io.Serializable;
public class SomeSerializable implements Serializable {
private static final long serialVersionUID = 1L;
private final String value;
public SomeSerializable(String value){
this.value = value;
}
public String getValue() {
return value;
}
}
......@@ -28,9 +28,12 @@ import org.activiti.engine.impl.variable.ValueFields;
import org.activiti.engine.impl.variable.VariableType;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.ActivitiRule;
import org.activiti.engine.test.Deployment;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.junit.Rule;
import org.junit.Test;
/**
* @author Tom Baeyens
......@@ -144,8 +147,26 @@ public class VariablesTest extends PluggableActivitiTestCase {
Task task = taskService.createTaskQuery().executionId(processInstance.getId()).singleResult();
taskService.complete(task.getId());
}
// Test case for ACT-1839
@Test
@Deployment(resources = {"org/activiti/examples/variables/VariablesTest.testChangeTypeSerializable.bpmn20.xml"})
public void testChangeTypeSerializable() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("variable-type-change-test");
assertNotNull(processInstance);
Task task = taskService.createTaskQuery().singleResult();
assertEquals("Activiti is awesome!", task.getName());
SomeSerializable myVar = (SomeSerializable) runtimeService.getVariable(processInstance.getId(), "myVar");
assertEquals("someValue", myVar.getValue());
}
public String getVariableInstanceId(String executionId, String name) {
HistoricVariableInstance variable = historyService.createHistoricVariableInstanceQuery().processInstanceId(executionId).variableName(name).singleResult();
......
package org.activiti.examples.variables
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
public class ChangeVariableType implements JavaDelegate {
public void execute(DelegateExecution execution) throws Exception {
// Initially set to null, stored as NullType
execution.setVariable("myVar", null);
// Now set to something stored as SerializableType. This could happen much later on than this.
execution.setVariable("myVar", new SomeSerializable("someValue"));
}
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn"
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema"
expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="variable-type-change-test">
<startEvent id="start" />
<sequenceFlow id="flow1" sourceRef="start" targetRef="changeVariableType" />
<serviceTask id="changeVariableType" activiti:class="org.activiti.examples.variables.ChangeVariableType"/>
<sequenceFlow id="flow2" sourceRef="changeVariableType" targetRef="someTask" />
<userTask id="someTask" name="Activiti is awesome!" />
<sequenceFlow id="flow3" sourceRef="someTask" targetRef="end" />
<endEvent id="end" />
</process>
</definitions>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册