mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 03:39:05 +01:00
Moved transactions out of database component.
This commit is contained in:
@@ -1,15 +1,38 @@
|
||||
package org.briarproject.api.db;
|
||||
|
||||
/** A wrapper around a database transaction. */
|
||||
/**
|
||||
* A wrapper around a database transaction. Transactions are not thread-safe.
|
||||
*/
|
||||
public class Transaction {
|
||||
|
||||
private final Object txn;
|
||||
private boolean complete = false;
|
||||
|
||||
public Transaction(Object txn) {
|
||||
this.txn = txn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database transaction. The type of the returned object
|
||||
* depends on the database implementation.
|
||||
*/
|
||||
public Object unbox() {
|
||||
return txn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the transaction is ready to be committed.
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return complete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the transaction as ready to be committed. This method must not be
|
||||
* called more than once.
|
||||
*/
|
||||
public void setComplete() {
|
||||
if (complete) throw new IllegalStateException();
|
||||
complete = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user