Details
-
Bug
-
Status: Closed
-
Trivial
-
Resolution: Fixed
-
3.0
-
None
Description
The following patch explains the issue... There seems to be a slight chance of 2 DataRows grabbng the same version. Nobody ever complained about this causing a real issue in an app (since two conflicting rows with the same version must belong to the same object, which is rather unlikely), still need to keep our algorithms tight and clean.
diff --git a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java b/framework/cayenne-jdk1.5-unpublished/
index 6a5fd74..8f1854b 100644
— a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java
+++ b/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/DataRow.java
@@ -21,6 +21,7 @@ package org.apache.cayenne;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
import org.apache.cayenne.map.DbRelationship;
import org.apache.cayenne.util.ToStringBuilder;
@@ -35,13 +36,11 @@ import org.apache.cayenne.util.Util;
*/
public class DataRow extends HashMap<String, Object> {
- // "volatile" is supposed to ensure consistency in read and increment operations;
- // is this universally true?
-
// make sure the starting value is different from DataObject default version value - private static volatile long currentVersion = DataObject.DEFAULT_VERSION + 1;
+ private static volatile AtomicLong currentVersion = new AtomicLong(
+ DataObject.DEFAULT_VERSION + 1);
- protected long version = currentVersion++;
+ protected long version = currentVersion.getAndIncrement();
protected long replacesVersion = DataObject.DEFAULT_VERSION;
/**