Add transactional DB interface.

This commit is contained in:
akwizgran
2017-11-15 10:11:39 +00:00
parent a384450c36
commit 3bcc532b4b
4 changed files with 77 additions and 0 deletions

View File

@@ -76,6 +76,32 @@ public interface DatabaseComponent {
*/
void endTransaction(Transaction txn);
/**
* Runs the given task within a transaction.
*/
void transaction(boolean readOnly, DbRunnable<DbException> task)
throws DbException;
/**
* Runs the given task within a transaction and returns the result of the
* task.
*/
<R> R transactionWithResult(boolean readOnly,
DbCallable<R, DbException> task) throws DbException;
/**
* Runs the given task within a transaction.
*/
<E extends Exception> void throwingTransaction(boolean readOnly,
DbRunnable<E> task) throws DbException, E;
/**
* Runs the given task within a transaction and returns the result of the
* task.
*/
<R, E extends Exception> R throwingTransactionWithResult(boolean readOnly,
DbCallable<R, E> task) throws DbException, E;
/**
* Stores a contact associated with the given local and remote pseudonyms,
* and returns an ID for the contact.

View File

@@ -0,0 +1,6 @@
package org.briarproject.bramble.api.db;
public interface DbCallable<R, E extends Exception> {
R call(Transaction txn) throws DbException, E;
}

View File

@@ -0,0 +1,6 @@
package org.briarproject.bramble.api.db;
public interface DbRunnable<E extends Exception> {
void run(Transaction txn) throws DbException, E;
}