allow adding contacts within an existing transactions

This commit is contained in:
Torsten Grote
2016-02-29 15:29:18 -03:00
parent 51c3528efa
commit e2d64e0a8c
2 changed files with 25 additions and 7 deletions

View File

@@ -46,6 +46,18 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
removeHooks.add(hook);
}
@Override
public ContactId addContact(Transaction txn, Author remote, AuthorId local,
SecretKey master,long timestamp, boolean alice, boolean active)
throws DbException {
ContactId c = db.addContact(txn, remote, local, active);
keyManager.addContact(txn, c, master, timestamp, alice);
Contact contact = db.getContact(txn, c);
for (AddContactHook hook : addHooks)
hook.addingContact(txn, contact);
return c;
}
@Override
public ContactId addContact(Author remote, AuthorId local, SecretKey master,
long timestamp, boolean alice, boolean active)
@@ -53,11 +65,8 @@ class ContactManagerImpl implements ContactManager, RemoveIdentityHook {
ContactId c;
Transaction txn = db.startTransaction(false);
try {
c = db.addContact(txn, remote, local, active);
keyManager.addContact(txn, c, master, timestamp, alice);
Contact contact = db.getContact(txn, c);
for (AddContactHook hook : addHooks)
hook.addingContact(txn, contact);
c = addContact(txn, remote, local, master, timestamp, alice,
active);
txn.setComplete();
} finally {
db.endTransaction(txn);