From d42b49afc2f458af41c936d253a927f53e0d2275 Mon Sep 17 00:00:00 2001
From: Torsten Grote <t@grobox.de>
Date: Wed, 27 Apr 2016 20:18:56 -0300
Subject: [PATCH] Allow to get a forum from the ForumManager within a
 transaction

---
 .../briarproject/api/forum/ForumManager.java  |  3 +++
 .../briarproject/forum/ForumManagerImpl.java  | 22 ++++++++++++-------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/briar-api/src/org/briarproject/api/forum/ForumManager.java b/briar-api/src/org/briarproject/api/forum/ForumManager.java
index bd5657b01b..7c619294be 100644
--- a/briar-api/src/org/briarproject/api/forum/ForumManager.java
+++ b/briar-api/src/org/briarproject/api/forum/ForumManager.java
@@ -31,6 +31,9 @@ public interface ForumManager {
 	/** Returns the forum with the given ID. */
 	Forum getForum(GroupId g) throws DbException;
 
+	/** Returns the forum with the given ID. */
+	Forum getForum(Transaction txn, GroupId g) throws DbException;
+
 	/** Returns all forums to which the user subscribes. */
 	Collection<Forum> getForums() throws DbException;
 
diff --git a/briar-core/src/org/briarproject/forum/ForumManagerImpl.java b/briar-core/src/org/briarproject/forum/ForumManagerImpl.java
index 63d4a2db83..d2a2b14d8a 100644
--- a/briar-core/src/org/briarproject/forum/ForumManagerImpl.java
+++ b/briar-core/src/org/briarproject/forum/ForumManagerImpl.java
@@ -141,15 +141,21 @@ class ForumManagerImpl implements ForumManager {
 
 	@Override
 	public Forum getForum(GroupId g) throws DbException {
+		Forum forum;
+		Transaction txn = db.startTransaction(true);
 		try {
-			Group group;
-			Transaction txn = db.startTransaction(true);
-			try {
-				group = db.getGroup(txn, g);
-				txn.setComplete();
-			} finally {
-				db.endTransaction(txn);
-			}
+			forum = getForum(txn, g);
+			txn.setComplete();
+		} finally {
+			db.endTransaction(txn);
+		}
+		return forum;
+	}
+
+	@Override
+	public Forum getForum(Transaction txn, GroupId g) throws DbException {
+		try {
+			Group group = db.getGroup(txn, g);
 			return parseForum(group);
 		} catch (FormatException e) {
 			throw new DbException(e);
-- 
GitLab