Replace transaction.setComplete() by database.commitTransaction()

This commit is contained in:
Torsten Grote
2016-10-31 08:47:11 -02:00
parent 36f087c512
commit b34b4623ed
39 changed files with 259 additions and 241 deletions

View File

@@ -52,11 +52,17 @@ public interface DatabaseComponent {
Transaction startTransaction(boolean readOnly) throws DbException;
/**
* Ends a transaction. If the transaction is marked as complete, the
* transaction is committed and any events attached to the transaction are
* broadcast; otherwise the transaction is aborted.
* Commits a transaction to the database.
*/
void endTransaction(Transaction txn) throws DbException;
void commitTransaction(Transaction txn) throws DbException;
/**
* Ends a transaction. If the transaction has not been committed,
* it will be aborted. If the transaction has been committed,
* any events attached to the transaction are broadcast.
* The database lock will be released in either case.
*/
void endTransaction(Transaction txn);
/**
* Stores a contact associated with the given local and remote pseudonyms,

View File

@@ -15,7 +15,7 @@ public class Transaction {
private final boolean readOnly;
private List<Event> events = null;
private boolean complete = false;
private boolean committed = false;
public Transaction(Object txn, boolean readOnly) {
this.txn = txn;
@@ -55,18 +55,18 @@ public class Transaction {
}
/**
* Returns true if the transaction is ready to be committed.
* Returns true if the transaction has been committed.
*/
public boolean isComplete() {
return complete;
public boolean isCommitted() {
return committed;
}
/**
* Marks the transaction as ready to be committed. This method must not be
* called more than once.
* Marks the transaction as committed. This method should only be called
* by the DatabaseComponent. It must not be called more than once.
*/
public void setComplete() {
if (complete) throw new IllegalStateException();
complete = true;
public void setCommitted() {
if (committed) throw new IllegalStateException();
committed = true;
}
}