summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2006-12-06 20:28:21 +0000
committerBrian S. O'Neill <bronee@gmail.com>2006-12-06 20:28:21 +0000
commitdf8eb2861e8ab9d6989bc369b95a44af1ca4394d (patch)
treeaf737882ecb78c9452d7fed2716460fbb220d02c
parent9fb03414506c055d3195debb78ad017094fcea97 (diff)
Enhanced OptimisticLockException message.
-rw-r--r--src/main/java/com/amazon/carbonado/OptimisticLockException.java46
-rw-r--r--src/main/java/com/amazon/carbonado/spi/MasterStorableGenerator.java8
2 files changed, 46 insertions, 8 deletions
diff --git a/src/main/java/com/amazon/carbonado/OptimisticLockException.java b/src/main/java/com/amazon/carbonado/OptimisticLockException.java
index 949537e..909e0c6 100644
--- a/src/main/java/com/amazon/carbonado/OptimisticLockException.java
+++ b/src/main/java/com/amazon/carbonado/OptimisticLockException.java
@@ -30,20 +30,26 @@ public class OptimisticLockException extends PersistException {
private static final long serialVersionUID = 4081788711829580886L;
+ private final Storable mStorable;
+
public OptimisticLockException() {
super();
+ mStorable = null;
}
public OptimisticLockException(String message) {
super(message);
+ mStorable = null;
}
public OptimisticLockException(String message, Throwable cause) {
super(message, cause);
+ mStorable = null;
}
public OptimisticLockException(Throwable cause) {
super(cause);
+ mStorable = null;
}
/**
@@ -68,14 +74,44 @@ public class OptimisticLockException extends PersistException {
* @param savedVersion actual persistent version number of storable
*/
public OptimisticLockException(Object expectedVersion, Object savedVersion) {
- super(makeMessage(expectedVersion, savedVersion));
+ this(expectedVersion, savedVersion, null);
+ }
+
+ /**
+ * @param expectedVersion version number that was expected for persistent
+ * record when update was executed
+ * @param savedVersion actual persistent version number of storable
+ * @param s Storable which was acted upon
+ */
+ public OptimisticLockException(Object expectedVersion, Object savedVersion, Storable s) {
+ super(makeMessage(expectedVersion, savedVersion, s));
+ mStorable = s;
}
- private static String makeMessage(Object expectedVersion, Object savedVersion) {
+ /**
+ * Returns the Storable which was acted upon, or null if not available.
+ */
+ public Storable getStorable() {
+ return mStorable;
+ }
+
+ private static String makeMessage(Object expectedVersion, Object savedVersion, Storable s) {
+ String message;
if (expectedVersion == null && savedVersion == null) {
- return null;
+ message = null;
+ } else {
+ message = "Update acted on version " + expectedVersion +
+ ", but canonical version is " + savedVersion;
}
- return "Update acted on version " + expectedVersion +
- ", but canonical version is " + savedVersion;
+
+ if (s != null) {
+ if (message == null) {
+ message = s.toStringKeyOnly();
+ } else {
+ message = message + ": " + s.toStringKeyOnly();
+ }
+ }
+
+ return message;
}
}
diff --git a/src/main/java/com/amazon/carbonado/spi/MasterStorableGenerator.java b/src/main/java/com/amazon/carbonado/spi/MasterStorableGenerator.java
index 11657de..b3bc830 100644
--- a/src/main/java/com/amazon/carbonado/spi/MasterStorableGenerator.java
+++ b/src/main/java/com/amazon/carbonado/spi/MasterStorableGenerator.java
@@ -546,7 +546,7 @@ public final class MasterStorableGenerator<S extends Storable> {
// if (version support enabled) {
// if (this.getVersionNumber() != saved.getVersionNumber()) {
// throw new OptimisticLockException
- // (this.getVersionNumber(), saved.getVersionNumber());
+ // (this.getVersionNumber(), saved.getVersionNumber(), this);
// }
// }
if (mFeatures.contains(MasterFeature.VERSIONING)) {
@@ -565,8 +565,10 @@ public final class MasterStorableGenerator<S extends Storable> {
b.loadLocal(savedVar);
b.invoke(mInfo.getVersionProperty().getReadMethod());
b.convert(versionType, TypeDesc.OBJECT);
- b.invokeConstructor(optimisticLockType,
- new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT});
+ b.loadThis();
+ b.invokeConstructor
+ (optimisticLockType,
+ new TypeDesc[] {TypeDesc.OBJECT, TypeDesc.OBJECT, storableType});
b.throwObject();
sameVersion.setLocation();
}