Commit 0c99ef0e authored by akwizgran's avatar akwizgran

Clean up some duplicated code.

parent faba9a6b
......@@ -98,9 +98,7 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
@Override
public void onDatabaseOpened(Transaction txn) throws DbException {
Account cached = cachedAccount;
if (cached == null)
cachedAccount = cached = loadAccountWithKeyPair(txn);
Account cached = getCachedAccount(txn);
if (shouldStoreAccount) {
db.addAccount(txn, cached);
LOG.info("Account stored");
......@@ -116,32 +114,32 @@ class IdentityManagerImpl implements IdentityManager, OpenDatabaseHook {
@Override
public LocalAuthor getLocalAuthor() throws DbException {
Account cached = cachedAccount;
if (cached == null) {
cachedAccount = cached = db.transactionWithResult(true,
this::loadAccountWithKeyPair);
}
if (cached == null)
cached = db.transactionWithResult(true, this::getCachedAccount);
return cached.getLocalAuthor();
}
@Override
public LocalAuthor getLocalAuthor(Transaction txn) throws DbException {
Account cached = cachedAccount;
if (cached == null)
cachedAccount = cached = loadAccountWithKeyPair(txn);
return cached.getLocalAuthor();
return getCachedAccount(txn).getLocalAuthor();
}
@Override
public byte[][] getHandshakeKeys(Transaction txn) throws DbException {
Account cached = cachedAccount;
if (cached == null)
cachedAccount = cached = loadAccountWithKeyPair(txn);
Account cached = getCachedAccount(txn);
return new byte[][] {
cached.getHandshakePublicKey(),
cached.getHandshakePrivateKey()
};
}
private Account getCachedAccount(Transaction txn) throws DbException {
Account cached = cachedAccount;
if (cached == null)
cachedAccount = cached = loadAccountWithKeyPair(txn);
return cached;
}
private Account loadAccountWithKeyPair(Transaction txn) throws DbException {
Account a = loadAccount(txn);
LOG.info("Account loaded");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment