mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Add transactional versions of BlogManager methods
This commit is contained in:
@@ -257,12 +257,19 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
public void addLocalComment(LocalAuthor author, GroupId groupId,
|
||||
@Nullable String comment, BlogPostHeader parentHeader)
|
||||
throws DbException {
|
||||
db.transaction(false, txn -> {
|
||||
addLocalComment(txn, author, groupId, comment, parentHeader);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLocalComment(Transaction txn, LocalAuthor author,
|
||||
GroupId groupId, @Nullable String comment,
|
||||
BlogPostHeader parentHeader) throws DbException {
|
||||
MessageType type = parentHeader.getType();
|
||||
if (type != POST && type != COMMENT)
|
||||
throw new IllegalArgumentException("Comment on unknown type!");
|
||||
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
// Wrap post that we are commenting on
|
||||
MessageId parentOriginalId =
|
||||
@@ -291,13 +298,10 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
message.getId(), meta);
|
||||
BlogPostAddedEvent event = new BlogPostAddedEvent(groupId, h, true);
|
||||
txn.attach(event);
|
||||
db.commitTransaction(txn);
|
||||
} catch (FormatException e) {
|
||||
throw new DbException(e);
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new IllegalArgumentException("Invalid key of author", e);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,18 +434,17 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
|
||||
@Override
|
||||
public Collection<Blog> getBlogs() throws DbException {
|
||||
return db.transactionWithResult(true, this::getBlogs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Blog> getBlogs(Transaction txn) throws DbException {
|
||||
try {
|
||||
List<Blog> blogs = new ArrayList<>();
|
||||
Collection<Group> groups;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
groups = db.getGroups(txn, CLIENT_ID, MAJOR_VERSION);
|
||||
for (Group g : groups) {
|
||||
blogs.add(blogFactory.parseBlog(g));
|
||||
}
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
Collection<Group> groups =
|
||||
db.getGroups(txn, CLIENT_ID, MAJOR_VERSION);
|
||||
for (Group g : groups) {
|
||||
blogs.add(blogFactory.parseBlog(g));
|
||||
}
|
||||
return blogs;
|
||||
} catch (FormatException e) {
|
||||
@@ -556,10 +559,18 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
|
||||
@Override
|
||||
public void setReadFlag(MessageId m, boolean read) throws DbException {
|
||||
db.transaction(true, txn -> {
|
||||
setReadFlag(txn, m, read);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadFlag(Transaction txn, MessageId m, boolean read)
|
||||
throws DbException {
|
||||
try {
|
||||
BdfDictionary meta = new BdfDictionary();
|
||||
meta.put(KEY_READ, read);
|
||||
clientHelper.mergeMessageMetadata(m, meta);
|
||||
clientHelper.mergeMessageMetadata(txn, m, meta);
|
||||
} catch (FormatException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user