Permalink
Browse files

Provide more information in StaleTransactionException's caused by fie…

…ld access.
  • Loading branch information...
archiecobbs committed Jun 19, 2018
1 parent 6159629 commit 11b2e9fdcdb2c564700789a2554266df1f330af8
@@ -11,14 +11,16 @@
@SuppressWarnings("serial")
public class StaleTransactionException extends TransactionException {
static final String DEFAULT_MESSAGE = "transaction cannot be accessed because it is no longer usable";
/**
* Constructor.
*
* @param tx the stale transaction
* @throws IllegalArgumentException if {@code tx} is null
*/
public StaleTransactionException(Transaction tx) {
super(tx, "transaction cannot be accessed because it is no longer usable");
super(tx, DEFAULT_MESSAGE);
}
/**
@@ -1766,9 +1766,8 @@ public synchronized void removeVersionChangeListener(VersionChangeListener liste
public synchronized Object readSimpleField(ObjId id, int storageId, boolean updateVersion) {
// Sanity check
if (this.stale)
throw new StaleTransactionException(this);
Preconditions.checkArgument(id != null, "null id");
this.checkStaleFieldAccess(id, storageId);
// Get object info
final ObjInfo info = this.getObjectInfo(id, updateVersion);
@@ -2006,6 +2005,14 @@ String getFieldDescription(ObjId id, int storageId) {
return "field `" + field.getName() + "'";
}
private void checkStaleFieldAccess(ObjId id, int storageId) {
assert Thread.holdsLock(this);
if (this.stale) {
throw new StaleTransactionException(this, "can't access " + this.getFieldDescription(id, storageId)
+ " of " + this.getObjDescription(id) + " :" + StaleTransactionException.DEFAULT_MESSAGE);
}
}
/**
* Read the value of a {@link CounterField} from an object, optionally updating the object's schema version.
*
@@ -2029,9 +2036,8 @@ String getFieldDescription(ObjId id, int storageId) {
public synchronized long readCounterField(ObjId id, int storageId, boolean updateVersion) {
// Sanity check
if (this.stale)
throw new StaleTransactionException(this);
Preconditions.checkArgument(id != null, "null id");
this.checkStaleFieldAccess(id, storageId);
// Get object info
final ObjInfo info = this.getObjectInfo(id, updateVersion);
@@ -2072,9 +2078,8 @@ public synchronized long readCounterField(ObjId id, int storageId, boolean updat
public synchronized void writeCounterField(final ObjId id, final int storageId, final long value, final boolean updateVersion) {
// Sanity check
if (this.stale)
throw new StaleTransactionException(this);
Preconditions.checkArgument(id != null, "null id");
this.checkStaleFieldAccess(id, storageId);
// Get object info
final ObjInfo info = this.getObjectInfo(id, updateVersion);
@@ -2113,8 +2118,7 @@ public synchronized void adjustCounterField(ObjId id, int storageId, long offset
// Sanity check
Preconditions.checkArgument(id != null, "null id");
if (this.stale)
throw new StaleTransactionException(this);
this.checkStaleFieldAccess(id, storageId);
// Optimize away non-change
if (offset == 0)
@@ -2274,9 +2278,8 @@ synchronized boolean hasDefaultValue(ObjId id, SimpleField<?> field) {
int storageId, boolean updateVersion, Class<F> fieldClass, Class<V> valueType) {
// Sanity check
if (this.stale)
throw new StaleTransactionException(this);
Preconditions.checkArgument(id != null, "null id");
this.checkStaleFieldAccess(id, storageId);
// Get object info
final ObjInfo info = this.getObjectInfo(id, updateVersion);

0 comments on commit 11b2e9f

Please sign in to comment.