提交 117f2bc6 编写于 作者: O Oleg Efimov

SerializableType object stream subclassing improved

上级 6bddf067
......@@ -554,10 +554,6 @@ public class DbSqlSession implements Session {
// deserialized objects /////////////////////////////////////////////////////
public void addDeserializedObject(Object deserializedObject, byte[] serializedBytes, VariableInstanceEntity variableInstanceEntity) {
addDeserializedObject(new DeserializedObject(deserializedObject, serializedBytes, variableInstanceEntity));
}
public void addDeserializedObject(DeserializedObject deserializedObject) {
deserializedObjects.add(deserializedObject);
}
......
......@@ -21,12 +21,13 @@ import org.activiti.engine.impl.persistence.entity.VariableInstanceEntity;
* @author Tom Baeyens
*/
public class DeserializedObject {
SerializableType type;
Object deserializedObject;
byte[] originalBytes;
VariableInstanceEntity variableInstanceEntity;
public DeserializedObject(Object deserializedObject, byte[] serializedBytes, VariableInstanceEntity variableInstanceEntity) {
public DeserializedObject(SerializableType type, Object deserializedObject, byte[] serializedBytes, VariableInstanceEntity variableInstanceEntity) {
this.type = type;
this.deserializedObject = deserializedObject;
this.originalBytes = serializedBytes;
this.variableInstanceEntity = variableInstanceEntity;
......@@ -35,7 +36,7 @@ public class DeserializedObject {
public void flush() {
// this first check verifies if the variable value was not overwritten with another object
if (deserializedObject==variableInstanceEntity.getCachedValue() && !variableInstanceEntity.isDeleted()) {
byte[] bytes = SerializableType.serialize(deserializedObject, variableInstanceEntity);
byte[] bytes = type.serialize(deserializedObject, variableInstanceEntity);
if (!Arrays.equals(originalBytes, bytes)) {
variableInstanceEntity.setBytes(bytes);
}
......
......@@ -61,9 +61,9 @@ public class SerializableType extends ByteArrayType {
// so that it can be serialized again if it was changed.
Context.getCommandContext()
.getDbSqlSession()
.addDeserializedObject(deserializedObject, bytes, (VariableInstanceEntity) valueFields);
.addDeserializedObject(new DeserializedObject(this, deserializedObject, bytes, (VariableInstanceEntity) valueFields));
}
return deserializedObject;
} catch (Exception e) {
throw new ActivitiException("Couldn't deserialize object in variable '"+valueFields.getName()+"'", e);
......@@ -77,21 +77,21 @@ public class SerializableType extends ByteArrayType {
public void setValue(Object value, ValueFields valueFields) {
byte[] byteArray = serialize(value, valueFields);
valueFields.setCachedValue(value);
if (valueFields.getBytes() == null) {
// TODO why the null check? won't this cause issues when setValue is called the second this with a different object?
if (valueFields instanceof VariableInstanceEntity) {
// register the deserialized object for dirty checking.
Context.getCommandContext()
.getDbSqlSession()
.addDeserializedObject(valueFields.getCachedValue(), byteArray, (VariableInstanceEntity)valueFields);
.addDeserializedObject(new DeserializedObject(this, valueFields.getCachedValue(), byteArray, (VariableInstanceEntity)valueFields));
}
}
super.setValue(byteArray, valueFields);
}
public static byte[] serialize(Object value, ValueFields valueFields) {
public byte[] serialize(Object value, ValueFields valueFields) {
if (value == null) {
return null;
}
......@@ -120,8 +120,8 @@ public class SerializableType extends ByteArrayType {
}
};
}
private static ObjectOutputStream createObjectOutputStream(OutputStream os) throws IOException {
protected ObjectOutputStream createObjectOutputStream(OutputStream os) throws IOException {
return new ObjectOutputStream(os);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册