mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Use new transaction wrappers.
This commit is contained in:
@@ -167,32 +167,24 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
Feed feed = feedFactory.createFeed(url, sf);
|
Feed feed = feedFactory.createFeed(url, sf);
|
||||||
|
|
||||||
// store feed metadata and new blog
|
// store feed metadata and new blog
|
||||||
Transaction txn = db.startTransaction(false);
|
db.transaction(false, txn -> {
|
||||||
try {
|
|
||||||
blogManager.addBlog(txn, feed.getBlog());
|
blogManager.addBlog(txn, feed.getBlog());
|
||||||
List<Feed> feeds = getFeeds(txn);
|
List<Feed> feeds = getFeeds(txn);
|
||||||
feeds.add(feed);
|
feeds.add(feed);
|
||||||
storeFeeds(txn, feeds);
|
storeFeeds(txn, feeds);
|
||||||
db.commitTransaction(txn);
|
});
|
||||||
} finally {
|
|
||||||
db.endTransaction(txn);
|
|
||||||
}
|
|
||||||
|
|
||||||
// post entries
|
// post entries
|
||||||
long lastEntryTime = postFeedEntries(feed, sf.getEntries());
|
long lastEntryTime = postFeedEntries(feed, sf.getEntries());
|
||||||
Feed updatedFeed = feedFactory.updateFeed(feed, sf, lastEntryTime);
|
Feed updatedFeed = feedFactory.updateFeed(feed, sf, lastEntryTime);
|
||||||
|
|
||||||
// store feed metadata again to also store last entry time
|
// store feed metadata again to also store last entry time
|
||||||
txn = db.startTransaction(false);
|
db.transaction(false, txn -> {
|
||||||
try {
|
|
||||||
List<Feed> feeds = getFeeds(txn);
|
List<Feed> feeds = getFeeds(txn);
|
||||||
feeds.remove(feed);
|
feeds.remove(feed);
|
||||||
feeds.add(updatedFeed);
|
feeds.add(updatedFeed);
|
||||||
storeFeeds(txn, feeds);
|
storeFeeds(txn, feeds);
|
||||||
db.commitTransaction(txn);
|
});
|
||||||
} finally {
|
|
||||||
db.endTransaction(txn);
|
|
||||||
}
|
|
||||||
|
|
||||||
return updatedFeed;
|
return updatedFeed;
|
||||||
}
|
}
|
||||||
@@ -200,14 +192,9 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
@Override
|
@Override
|
||||||
public void removeFeed(Feed feed) throws DbException {
|
public void removeFeed(Feed feed) throws DbException {
|
||||||
LOG.info("Removing RSS feed...");
|
LOG.info("Removing RSS feed...");
|
||||||
Transaction txn = db.startTransaction(false);
|
// this will call removingBlog() where the feed itself gets removed
|
||||||
try {
|
db.transaction(false, txn ->
|
||||||
// this will call removingBlog() where the feed itself gets removed
|
blogManager.removeBlog(txn, feed.getBlog()));
|
||||||
blogManager.removeBlog(txn, feed.getBlog());
|
|
||||||
db.commitTransaction(txn);
|
|
||||||
} finally {
|
|
||||||
db.endTransaction(txn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -375,9 +362,8 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
long postFeedEntries(Feed feed, List<SyndEntry> entries)
|
long postFeedEntries(Feed feed, List<SyndEntry> entries)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
|
|
||||||
long lastEntryTime = feed.getLastEntryTime();
|
return db.transactionWithResult(false, txn -> {
|
||||||
Transaction txn = db.startTransaction(false);
|
long lastEntryTime = feed.getLastEntryTime();
|
||||||
try {
|
|
||||||
//noinspection Java8ListSort
|
//noinspection Java8ListSort
|
||||||
sort(entries, getEntryComparator());
|
sort(entries, getEntryComparator());
|
||||||
for (SyndEntry entry : entries) {
|
for (SyndEntry entry : entries) {
|
||||||
@@ -396,11 +382,8 @@ class FeedManagerImpl implements FeedManager, EventListener, OpenDatabaseHook,
|
|||||||
if (entryTime > lastEntryTime) lastEntryTime = entryTime;
|
if (entryTime > lastEntryTime) lastEntryTime = entryTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
db.commitTransaction(txn);
|
return lastEntryTime;
|
||||||
} finally {
|
});
|
||||||
db.endTransaction(txn);
|
|
||||||
}
|
|
||||||
return lastEntryTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postEntry(Transaction txn, Feed feed, SyndEntry entry) {
|
private void postEntry(Transaction txn, Feed feed, SyndEntry entry) {
|
||||||
|
|||||||
@@ -137,17 +137,14 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
|||||||
Message msg = getMessage(blogGroupId);
|
Message msg = getMessage(blogGroupId);
|
||||||
BlogPost post = new BlogPost(msg, null, localAuthor);
|
BlogPost post = new BlogPost(msg, null, localAuthor);
|
||||||
|
|
||||||
context.checking(new Expectations() {{
|
context.checking(new DbExpectations() {{
|
||||||
oneOf(db).startTransaction(false);
|
oneOf(db).transactionWithResult(with(false), withDbCallable(txn));
|
||||||
will(returnValue(txn));
|
|
||||||
oneOf(clock).currentTimeMillis();
|
oneOf(clock).currentTimeMillis();
|
||||||
will(returnValue(42L));
|
will(returnValue(42L));
|
||||||
oneOf(blogPostFactory).createBlogPost(feed.getBlogId(), 42L, null,
|
oneOf(blogPostFactory).createBlogPost(feed.getBlogId(), 42L, null,
|
||||||
localAuthor, text);
|
localAuthor, text);
|
||||||
will(returnValue(post));
|
will(returnValue(post));
|
||||||
oneOf(blogManager).addLocalPost(txn, post);
|
oneOf(blogManager).addLocalPost(txn, post);
|
||||||
oneOf(db).commitTransaction(txn);
|
|
||||||
oneOf(db).endTransaction(txn);
|
|
||||||
}});
|
}});
|
||||||
feedManager.postFeedEntries(feed, entries);
|
feedManager.postFeedEntries(feed, entries);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user