mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Merge branch '1232-get-pending-contact' into 'master'
Add method to get a pending contact See merge request briar/briar!1110
This commit is contained in:
@@ -127,6 +127,12 @@ class ContactManagerImpl implements ContactManager {
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PendingContact getPendingContact(Transaction txn, PendingContactId p)
|
||||
throws DbException {
|
||||
return db.getPendingContact(txn, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Pair<PendingContact, PendingContactState>> getPendingContacts()
|
||||
throws DbException {
|
||||
|
||||
@@ -496,6 +496,14 @@ interface Database<T> {
|
||||
*/
|
||||
long getNextSendTime(T txn, ContactId c) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns the pending contact with the given ID.
|
||||
* <p/>
|
||||
* Read-only.
|
||||
*/
|
||||
PendingContact getPendingContact(T txn, PendingContactId p)
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Returns all pending contacts.
|
||||
* <p/>
|
||||
|
||||
@@ -712,6 +712,15 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
return db.getNextSendTime(txn, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PendingContact getPendingContact(Transaction transaction,
|
||||
PendingContactId p) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsPendingContact(txn, p))
|
||||
throw new NoSuchPendingContactException();
|
||||
return db.getPendingContact(txn, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PendingContact> getPendingContacts(
|
||||
Transaction transaction) throws DbException {
|
||||
|
||||
@@ -2205,6 +2205,30 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PendingContact getPendingContact(Connection txn, PendingContactId p)
|
||||
throws DbException {
|
||||
PreparedStatement ps = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
String sql = "SELECT publicKey, alias, timestamp"
|
||||
+ " FROM pendingContacts"
|
||||
+ " WHERE pendingContactId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, p.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
if (!rs.next()) throw new DbStateException();
|
||||
PublicKey publicKey = new AgreementPublicKey(rs.getBytes(1));
|
||||
String alias = rs.getString(2);
|
||||
long timestamp = rs.getLong(3);
|
||||
return new PendingContact(p, publicKey, alias, timestamp);
|
||||
} catch (SQLException e) {
|
||||
tryToClose(rs, LOG, WARNING);
|
||||
tryToClose(ps, LOG, WARNING);
|
||||
throw new DbException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PendingContact> getPendingContacts(Connection txn)
|
||||
throws DbException {
|
||||
|
||||
Reference in New Issue
Block a user