Use a lock to ensure transaction isolation. #272

This commit is contained in:
akwizgran
2016-03-24 17:18:54 +00:00
parent 9714713d73
commit 1855dbbd2d
22 changed files with 248 additions and 189 deletions

View File

@@ -45,8 +45,9 @@ public interface DatabaseComponent {
/**
* Starts a new transaction and returns an object representing it.
* @param readOnly true if the transaction will only be used for reading.
*/
Transaction startTransaction() throws DbException;
Transaction startTransaction(boolean readOnly) throws DbException;
/**
* Ends a transaction. If the transaction is marked as complete, the

View File

@@ -12,12 +12,14 @@ import java.util.List;
public class Transaction {
private final Object txn;
private final boolean readOnly;
private List<Event> events = null;
private boolean complete = false;
public Transaction(Object txn) {
public Transaction(Object txn, boolean readOnly) {
this.txn = txn;
this.readOnly = readOnly;
}
/**
@@ -28,6 +30,13 @@ public class Transaction {
return txn;
}
/**
* Returns true if the transaction can only be used for reading.
*/
public boolean isReadOnly() {
return readOnly;
}
/**
* Attaches an event to be broadcast when the transaction has been
* committed.