mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Broadcast events after committing transactions.
This commit is contained in:
@@ -49,9 +49,9 @@ public interface DatabaseComponent {
|
||||
Transaction startTransaction() throws DbException;
|
||||
|
||||
/**
|
||||
* Ends a transaction. If the transaction's
|
||||
* {@link Transaction#setComplete() commit} flag is set, the
|
||||
* transaction is committed, otherwise it is aborted.
|
||||
* 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.
|
||||
*/
|
||||
void endTransaction(Transaction txn) throws DbException;
|
||||
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
package org.briarproject.api.db;
|
||||
|
||||
import org.briarproject.api.event.Event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A wrapper around a database transaction. Transactions are not thread-safe.
|
||||
*/
|
||||
public class Transaction {
|
||||
|
||||
private final Object txn;
|
||||
|
||||
private List<Event> events = null;
|
||||
private boolean complete = false;
|
||||
|
||||
public Transaction(Object txn) {
|
||||
@@ -20,6 +28,23 @@ public class Transaction {
|
||||
return txn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches an event to be broadcast when the transaction has been
|
||||
* committed.
|
||||
*/
|
||||
public void attach(Event e) {
|
||||
if (events == null) events = new ArrayList<Event>();
|
||||
events.add(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns any events attached to the transaction.
|
||||
*/
|
||||
public List<Event> getEvents() {
|
||||
if (events == null) return Collections.emptyList();
|
||||
return events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the transaction is ready to be committed.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user