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

SerializableType object stream subclassing improved

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