JBoss JBPM SVN: r7048 - in jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src: main/java/org/jbpm/context/exe/converter and 3 other directories.
by do-not-reply@jboss.org
Author: mputz
Date: 2011-11-15 09:59:02 -0500 (Tue, 15 Nov 2011)
New Revision: 7048
Modified:
jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/bytes/ByteArray.java
jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java
jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java
jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/test/java/org/jbpm/context/exe/MySerializableClass.java
Log:
SOA-3589: Backport changes to ByteArray / ByteBlock update handling (r7044, r7045, r7046) to jBPM 3.2.10
Modified: jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/bytes/ByteArray.java
===================================================================
--- jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/bytes/ByteArray.java 2011-11-15 14:23:46 UTC (rev 7047)
+++ jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/bytes/ByteArray.java 2011-11-15 14:59:02 UTC (rev 7048)
@@ -66,6 +66,18 @@
this.name = other.name;
}
+ public void update(ByteArray value) {
+ List otherByteBlocks = (value != null ? value.getByteBlocks() : null);
+ // Different than constructor:
+ // 1. clear to empty list.
+ this.byteBlocks.clear();
+ if (otherByteBlocks != null) {
+ // 2. use addAll in order to work as much as possible with JPA/ORM
+ this.byteBlocks.addAll(otherByteBlocks);
+ }
+ this.name = (value != null ? value.name : null );
+ }
+
public byte[] getBytes() {
return ByteBlockChopper.glueChopsBackTogether(byteBlocks);
}
@@ -108,4 +120,6 @@
public List getByteBlocks() {
return byteBlocks;
}
+
+
}
Modified: jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
===================================================================
--- jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java 2011-11-15 14:23:46 UTC (rev 7047)
+++ jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java 2011-11-15 14:59:02 UTC (rev 7048)
@@ -59,7 +59,8 @@
}
else if (byteCount > 0) {
if (log.isTraceEnabled()) log.trace("no need to chop " + byteCount + " bytes");
- bytes = Collections.singletonList(byteArray);
+ bytes = new ArrayList(1);
+ bytes.add(byteArray);
}
}
return bytes;
@@ -79,6 +80,8 @@
int blockCount = byteBlocks.size();
switch (blockCount) {
case 0:
+ // NPE's are never nice
+ byteArray = new byte [0];
break;
case 1:
byteArray = (byte[]) byteBlocks.get(0);
Modified: jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java
===================================================================
--- jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java 2011-11-15 14:23:46 UTC (rev 7047)
+++ jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java 2011-11-15 14:59:02 UTC (rev 7048)
@@ -78,17 +78,22 @@
public Object revert(Object o, final ProcessDefinition processDefinition) {
ByteArray byteArray = (ByteArray) o;
- InputStream memoryStream = new ByteArrayInputStream(byteArray.getBytes());
- try {
- ObjectInputStream objectStream = new CustomLoaderObjectInputStream(memoryStream,
- JbpmConfiguration.getProcessClassLoader(processDefinition));
- return objectStream.readObject();
+ if( byteArray.getBytes().length > 0 ) {
+ InputStream memoryStream = new ByteArrayInputStream(byteArray.getBytes());
+ try {
+ ObjectInputStream objectStream = new CustomLoaderObjectInputStream(memoryStream,
+ JbpmConfiguration.getProcessClassLoader(processDefinition));
+ return objectStream.readObject();
+ }
+ catch (IOException e) {
+ throw new JbpmException("failed to deserialize object", e);
+ }
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("serialized class not found", e);
+ }
}
- catch (IOException e) {
- throw new JbpmException("failed to deserialize object", e);
+ else {
+ return null;
}
- catch (ClassNotFoundException e) {
- throw new JbpmException("serialized class not found", e);
- }
}
}
Modified: jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java
===================================================================
--- jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java 2011-11-15 14:23:46 UTC (rev 7047)
+++ jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java 2011-11-15 14:59:02 UTC (rev 7048)
@@ -21,6 +21,7 @@
*/
package org.jbpm.context.exe.variableinstance;
+import org.hibernate.LockMode;
import org.hibernate.Session;
import org.jbpm.JbpmContext;
import org.jbpm.bytes.ByteArray;
@@ -45,15 +46,26 @@
if (token != null) {
token.addLog(new ByteArrayUpdateLog(this, this.value, (ByteArray) value));
}
- // delete old value, otherwise it will be unreachable
if (this.value != null) {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
+ ByteArray valueToUpdate = null;
if (jbpmContext != null) {
Session session = jbpmContext.getSession();
- if (session != null) session.delete(this.value);
+ if (session != null) {
+ valueToUpdate = (ByteArray) session.get(ByteArray.class, new Long(this.value.getId()), LockMode.UPGRADE);
+ if( valueToUpdate != null ) {
+ valueToUpdate.update((ByteArray) value);
+ }
+ }
}
+
+ // if for some reason, this.value is NOT in the (hibernate) session, update it anyway.
+ if( valueToUpdate == null ) {
+ this.value.update((ByteArray) value);
+ }
}
- // set new value
- this.value = (ByteArray) value;
+ else {
+ this.value = (ByteArray) value;
+ }
}
}
Modified: jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
===================================================================
--- jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2011-11-15 14:23:46 UTC (rev 7047)
+++ jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2011-11-15 14:59:02 UTC (rev 7048)
@@ -49,7 +49,7 @@
newTransaction();
ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
byteArray.getId()));
- assertNull(retrievedByteArray.getBytes());
+ assertTrue(retrievedByteArray.getBytes().length == 0);
session.delete(retrievedByteArray);
}
@@ -91,7 +91,7 @@
newTransaction();
ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
byteArray.getId()));
- assertNull(retrievedByteArray.getBytes());
+ assertTrue(retrievedByteArray.getBytes().length == 0);
session.delete(retrievedByteArray);
}
Modified: jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/test/java/org/jbpm/context/exe/MySerializableClass.java
===================================================================
--- jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/test/java/org/jbpm/context/exe/MySerializableClass.java 2011-11-15 14:23:46 UTC (rev 7047)
+++ jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/core/src/test/java/org/jbpm/context/exe/MySerializableClass.java 2011-11-15 14:59:02 UTC (rev 7048)
@@ -28,7 +28,7 @@
private static final long serialVersionUID = 1L;
int member;
- MySerializableClass(int member) {
+ public MySerializableClass(int member) {
this.member = member;
}
14 years, 4 months
JBoss JBPM SVN: r7047 - jbpm3/tags.
by do-not-reply@jboss.org
Author: mputz
Date: 2011-11-15 09:23:46 -0500 (Tue, 15 Nov 2011)
New Revision: 7047
Added:
jbpm3/tags/jbpm-3.2.10_SOA-3030_SOA-3589/
Log:
Create patch tag for SOA-3589
14 years, 4 months
JBoss JBPM SVN: r7046 - in jbpm3/branches/jbpm-3.2-soa/core/src: main/java/org/jbpm/context/exe/converter and 3 other directories.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-11-15 06:17:22 -0500 (Tue, 15 Nov 2011)
New Revision: 7046
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java
Log:
JBPM3441: Serializable Process Variable de/serialization results in an NPE in a non-trivial case
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -67,15 +67,15 @@
}
public void update(ByteArray value) {
- List otherByteBlocks = value.getByteBlocks();
+ List otherByteBlocks = (value != null ? value.getByteBlocks() : null);
// Different than constructor:
- // 1. clear on empty list.
+ // 1. clear to empty list.
this.byteBlocks.clear();
if (otherByteBlocks != null) {
// 2. use addAll in order to work as much as possible with JPA/ORM
this.byteBlocks.addAll(otherByteBlocks);
}
- this.name = value.name;
+ this.name = (value != null ? value.name : null );
}
public byte[] getBytes() {
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -59,7 +59,8 @@
}
else if (byteCount > 0) {
if (log.isTraceEnabled()) log.trace("no need to chop " + byteCount + " bytes");
- bytes = Collections.singletonList(byteArray);
+ bytes = new ArrayList(1);
+ bytes.add(byteArray);
}
}
return bytes;
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/converter/SerializableToByteArrayConverter.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -78,17 +78,22 @@
public Object revert(Object o, final ProcessDefinition processDefinition) {
ByteArray byteArray = (ByteArray) o;
- InputStream memoryStream = new ByteArrayInputStream(byteArray.getBytes());
- try {
- ObjectInputStream objectStream = new CustomLoaderObjectInputStream(memoryStream,
- JbpmConfiguration.getProcessClassLoader(processDefinition));
- return objectStream.readObject();
+ if( byteArray.getBytes().length > 0 ) {
+ InputStream memoryStream = new ByteArrayInputStream(byteArray.getBytes());
+ try {
+ ObjectInputStream objectStream = new CustomLoaderObjectInputStream(memoryStream,
+ JbpmConfiguration.getProcessClassLoader(processDefinition));
+ return objectStream.readObject();
+ }
+ catch (IOException e) {
+ throw new JbpmException("failed to deserialize object", e);
+ }
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("serialized class not found", e);
+ }
}
- catch (IOException e) {
- throw new JbpmException("failed to deserialize object", e);
+ else {
+ return null;
}
- catch (ClassNotFoundException e) {
- throw new JbpmException("serialized class not found", e);
- }
}
}
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -53,12 +53,13 @@
Session session = jbpmContext.getSession();
if (session != null) {
valueToUpdate = (ByteArray) session.get(ByteArray.class, new Long(this.value.getId()), LockMode.UPGRADE);
- valueToUpdate.update((ByteArray) value);
+ if( valueToUpdate != null ) {
+ valueToUpdate.update((ByteArray) value);
+ }
}
}
// if for some reason, this.value is NOT in the (hibernate) session, update it anyway.
- // -- but then there's something _VERY_ weird and wrong going on.
if( valueToUpdate == null ) {
this.value.update((ByteArray) value);
}
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/bytes/ByteArrayDbTest.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -49,7 +49,7 @@
newTransaction();
ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
byteArray.getId()));
- assertNull(retrievedByteArray.getBytes());
+ assertTrue(retrievedByteArray.getBytes().length == 0);
session.delete(retrievedByteArray);
}
@@ -91,7 +91,7 @@
newTransaction();
ByteArray retrievedByteArray = (ByteArray) session.load(ByteArray.class, new Long(
byteArray.getId()));
- assertNull(retrievedByteArray.getBytes());
+ assertTrue(retrievedByteArray.getBytes().length == 0);
session.delete(retrievedByteArray);
}
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java 2011-11-15 09:52:28 UTC (rev 7045)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java 2011-11-15 11:17:22 UTC (rev 7046)
@@ -24,6 +24,7 @@
import java.util.List;
import org.hibernate.Session;
+import org.jbpm.JbpmConfiguration;
import org.jbpm.context.def.ContextDefinition;
import org.jbpm.context.exe.ContextInstance;
import org.jbpm.context.exe.MySerializableClass;
@@ -49,6 +50,14 @@
}
+ protected JbpmConfiguration getJbpmConfiguration() {
+ if (jbpmConfiguration == null) {
+ // disable logging service to prevent logs from referencing custom object
+ jbpmConfiguration = JbpmConfiguration.parseResource("org/jbpm/context/exe/jbpm.cfg.xml");
+ }
+ return jbpmConfiguration;
+ }
+
protected void tearDown() throws Exception {
super.tearDown();
}
@@ -71,12 +80,12 @@
contextInstance.setVariable("a", new MySerializableClass(555));
processInstance = saveAndReload(processInstance);
- numByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
- numByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
+ int newByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
+ int newByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
// check db ids again
- assertTrue(numByteArrayRows > 0);
- assertTrue(numByteBlockRows > 0);
+ assertTrue(newByteArrayRows > 0);
+ assertTrue(newByteBlockRows > 0);
contextInstance = processInstance.getContextInstance();
assertEquals(new MySerializableClass(555), contextInstance.getVariable("a"));
@@ -84,11 +93,35 @@
// check if db ids are the same
// 1. One ByteArray object for var
// 2. One newValue for 1rst ByteArrayUpdateLog
- // 3. One newValue and one oldValue for 2nd ByteArrayUpdateLog
+ // 3. One newValue
+ // 4. and one oldValue for 2nd ByteArrayUpdateLog
// TOTAL = 4
// If a _NEW_ ByteArray object is made, then there would be 5 ByteArray objects and byte []'s
- assertTrue("Too many ByteArray objects have been made [" + numByteArrayRows + "]", numByteArrayRows == 4 );
- assertTrue("Too many byte [] objects have been persisted [" + numByteBlockRows + "]", numByteBlockRows == 4 );
+ assertTrue("Too many ByteArray objects have been made [" + numByteArrayRows + "!=" + newByteArrayRows + "]", numByteArrayRows == newByteArrayRows );
+ assertTrue("Too many byte [] objects have been persisted [" + numByteBlockRows + "!=" + newByteBlockRows + "]", numByteBlockRows == newByteBlockRows );
+
+ // Check that null's don't cause a problem.
+ contextInstance.setVariable("a", null);
+ processInstance = saveAndReload(processInstance);
+ assertEquals("Null variable not retrieved as null.", null, contextInstance.getVariable("a"));
+
+ newByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
+ newByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
+
+ // 4. One oldValue for 3rd ByteArrayUpdateLog (newValue is null)
+ assertTrue("Too many ByteArray objects have been made [" + numByteArrayRows + "!=" + newByteArrayRows + "]", numByteArrayRows == newByteArrayRows );
+ assertTrue("Too many byte [] objects have been persisted [" + numByteBlockRows + "! >=" + newByteBlockRows + "]", numByteBlockRows >= newByteBlockRows );
+
+ // Refill var
+ contextInstance.setVariable("a", new MySerializableClass(123));
+ processInstance = saveAndReload(processInstance);
+
+ newByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
+ newByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
+
+ // Same as before..
+ assertTrue("Too many ByteArray objects have been made [" + numByteArrayRows + "!=" + newByteArrayRows + "]", numByteArrayRows == newByteArrayRows );
+ assertTrue("Too many byte [] objects have been persisted [" + numByteBlockRows + "!=" + newByteBlockRows + "]", numByteBlockRows == newByteBlockRows );
}
protected int getLatestDbId(String idName, String tableName) {
14 years, 4 months
JBoss JBPM SVN: r7045 - jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-11-15 04:52:28 -0500 (Tue, 15 Nov 2011)
New Revision: 7045
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/MySerializableClass.java
Log:
JBPM3441: Serializable Process Variable de/serialization results in an NPE in a non-trivial case
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/MySerializableClass.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/MySerializableClass.java 2011-11-15 09:50:28 UTC (rev 7044)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/MySerializableClass.java 2011-11-15 09:52:28 UTC (rev 7045)
@@ -28,7 +28,7 @@
private static final long serialVersionUID = 1L;
int member;
- MySerializableClass(int member) {
+ public MySerializableClass(int member) {
this.member = member;
}
14 years, 4 months
JBoss JBPM SVN: r7044 - in jbpm3/branches/jbpm-3.2-soa/core/src: main/java/org/jbpm/context/exe/variableinstance and 2 other directories.
by do-not-reply@jboss.org
Author: marco.rietveld
Date: 2011-11-15 04:50:28 -0500 (Tue, 15 Nov 2011)
New Revision: 7044
Added:
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java
Log:
JBPM3441: Serializable Process Variable de/serialization results in an NPE in a non-trivial case
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java 2011-10-11 03:53:53 UTC (rev 7043)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteArray.java 2011-11-15 09:50:28 UTC (rev 7044)
@@ -66,6 +66,18 @@
this.name = other.name;
}
+ public void update(ByteArray value) {
+ List otherByteBlocks = value.getByteBlocks();
+ // Different than constructor:
+ // 1. clear on empty list.
+ this.byteBlocks.clear();
+ if (otherByteBlocks != null) {
+ // 2. use addAll in order to work as much as possible with JPA/ORM
+ this.byteBlocks.addAll(otherByteBlocks);
+ }
+ this.name = value.name;
+ }
+
public byte[] getBytes() {
return ByteBlockChopper.glueChopsBackTogether(byteBlocks);
}
@@ -108,4 +120,6 @@
public List getByteBlocks() {
return byteBlocks;
}
+
+
}
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java 2011-10-11 03:53:53 UTC (rev 7043)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/bytes/ByteBlockChopper.java 2011-11-15 09:50:28 UTC (rev 7044)
@@ -79,6 +79,8 @@
int blockCount = byteBlocks.size();
switch (blockCount) {
case 0:
+ // NPE's are never nice
+ byteArray = new byte [0];
break;
case 1:
byteArray = (byte[]) byteBlocks.get(0);
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java 2011-10-11 03:53:53 UTC (rev 7043)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/java/org/jbpm/context/exe/variableinstance/ByteArrayInstance.java 2011-11-15 09:50:28 UTC (rev 7044)
@@ -21,6 +21,7 @@
*/
package org.jbpm.context.exe.variableinstance;
+import org.hibernate.LockMode;
import org.hibernate.Session;
import org.jbpm.JbpmContext;
import org.jbpm.bytes.ByteArray;
@@ -45,15 +46,25 @@
if (token != null) {
token.addLog(new ByteArrayUpdateLog(this, this.value, (ByteArray) value));
}
- // delete old value, otherwise it will be unreachable
if (this.value != null) {
JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
+ ByteArray valueToUpdate = null;
if (jbpmContext != null) {
Session session = jbpmContext.getSession();
- if (session != null) session.delete(this.value);
+ if (session != null) {
+ valueToUpdate = (ByteArray) session.get(ByteArray.class, new Long(this.value.getId()), LockMode.UPGRADE);
+ valueToUpdate.update((ByteArray) value);
+ }
}
+
+ // if for some reason, this.value is NOT in the (hibernate) session, update it anyway.
+ // -- but then there's something _VERY_ weird and wrong going on.
+ if( valueToUpdate == null ) {
+ this.value.update((ByteArray) value);
+ }
}
- // set new value
- this.value = (ByteArray) value;
+ else {
+ this.value = (ByteArray) value;
+ }
}
}
Added: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java (rev 0)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java 2011-11-15 09:50:28 UTC (rev 7044)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.context.exe.variableinstance;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.jbpm.context.def.ContextDefinition;
+import org.jbpm.context.exe.ContextInstance;
+import org.jbpm.context.exe.MySerializableClass;
+import org.jbpm.db.AbstractDbTestCase;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.persistence.db.DbPersistenceService;
+
+public class SerializableInstanceDbTest extends AbstractDbTestCase {
+
+ ProcessInstance processInstance;
+ ContextInstance contextInstance;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ ProcessDefinition processDefinition = new ProcessDefinition(getName());
+ processDefinition.addDefinition(new ContextDefinition());
+ deployProcessDefinition(processDefinition);
+
+ processInstance = new ProcessInstance(processDefinition);
+ contextInstance = processInstance.getContextInstance();
+
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testSerializableVariableKeepsId() {
+ contextInstance.setVariable("a", new MySerializableClass(4));
+ processInstance = saveAndReload(processInstance);
+
+ int numByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
+ int numByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
+
+ // check validation ids
+ assertTrue(numByteArrayRows > 0);
+ assertTrue(numByteBlockRows > 0);
+
+ contextInstance = processInstance.getContextInstance();
+ assertEquals(new MySerializableClass(4), contextInstance.getVariable("a"));
+
+ // update serializeable variable with new value
+ contextInstance.setVariable("a", new MySerializableClass(555));
+ processInstance = saveAndReload(processInstance);
+
+ numByteArrayRows = getLatestDbId("ID_", "JBPM_BYTEARRAY");
+ numByteBlockRows = getLatestDbId("PROCESSFILE_", "JBPM_BYTEBLOCK");
+
+ // check db ids again
+ assertTrue(numByteArrayRows > 0);
+ assertTrue(numByteBlockRows > 0);
+
+ contextInstance = processInstance.getContextInstance();
+ assertEquals(new MySerializableClass(555), contextInstance.getVariable("a"));
+
+ // check if db ids are the same
+ // 1. One ByteArray object for var
+ // 2. One newValue for 1rst ByteArrayUpdateLog
+ // 3. One newValue and one oldValue for 2nd ByteArrayUpdateLog
+ // TOTAL = 4
+ // If a _NEW_ ByteArray object is made, then there would be 5 ByteArray objects and byte []'s
+ assertTrue("Too many ByteArray objects have been made [" + numByteArrayRows + "]", numByteArrayRows == 4 );
+ assertTrue("Too many byte [] objects have been persisted [" + numByteBlockRows + "]", numByteBlockRows == 4 );
+ }
+
+ protected int getLatestDbId(String idName, String tableName) {
+ int id = 0;
+ DbPersistenceService persistenceService = (DbPersistenceService) jbpmContext.getServices()
+ .getPersistenceService();
+ if (persistenceService != null) {
+ Session session = persistenceService.getSession();
+ List res = session.createSQLQuery("select " + idName + " from " + tableName
+ + " order by " + idName + " desc").list();
+ if (res != null && res.size() > 0) {
+ Object obj = res.get(0);
+ log.debug(tableName + "::" + idName + "=" + obj);
+ id = ((java.math.BigInteger) obj).intValue();
+ }
+ }
+ return id;
+
+ }
+}
\ No newline at end of file
Property changes on: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/context/exe/variableinstance/SerializableInstanceDbTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
14 years, 4 months