mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
Return transports that have no properties.
This commit is contained in:
@@ -1454,10 +1454,13 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
String sql = "SELECT contactId, key, value"
|
String sql = "SELECT contactTransports.contactId, key, value"
|
||||||
+ " FROM contactTransportProperties"
|
+ " FROM contactTransports"
|
||||||
+ " WHERE transportId = ?"
|
+ " LEFT OUTER JOIN contactTransportProperties"
|
||||||
+ " ORDER BY contactId";
|
+ " ON contactTransports.transportId"
|
||||||
|
+ " = contactTransportProperties.transportId"
|
||||||
|
+ " WHERE contactTransports.transportId = ?"
|
||||||
|
+ " ORDER BY contactTransports.contactId";
|
||||||
ps = txn.prepareStatement(sql);
|
ps = txn.prepareStatement(sql);
|
||||||
ps.setBytes(1, t.getBytes());
|
ps.setBytes(1, t.getBytes());
|
||||||
rs = ps.executeQuery();
|
rs = ps.executeQuery();
|
||||||
@@ -1471,7 +1474,10 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
p = new TransportProperties();
|
p = new TransportProperties();
|
||||||
properties.put(id, p);
|
properties.put(id, p);
|
||||||
}
|
}
|
||||||
p.put(rs.getString(2), rs.getString(3));
|
// Key and value may be null due to the left outer join
|
||||||
|
String key = rs.getString(2);
|
||||||
|
String value = rs.getString(3);
|
||||||
|
if(key != null && value != null) p.put(key, value);
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
ps.close();
|
ps.close();
|
||||||
|
|||||||
@@ -999,7 +999,7 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact with some transport properties
|
// Add a contact with a transport
|
||||||
assertEquals(contactId, db.addContact(txn, secret));
|
assertEquals(contactId, db.addContact(txn, secret));
|
||||||
db.setTransports(txn, contactId, remoteTransports, 1);
|
db.setTransports(txn, contactId, remoteTransports, 1);
|
||||||
assertEquals(remoteProperties,
|
assertEquals(remoteProperties,
|
||||||
@@ -1018,8 +1018,17 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
assertEquals(remoteProperties1,
|
assertEquals(remoteProperties1,
|
||||||
db.getRemoteProperties(txn, transportId));
|
db.getRemoteProperties(txn, transportId));
|
||||||
|
|
||||||
// Remove the transport properties
|
// Remove the transport properties but leave the transport
|
||||||
db.setTransports(txn, contactId, Collections.<Transport>emptyList(), 3);
|
properties1 = new TransportProperties();
|
||||||
|
remoteTransport1 = new Transport(transportId, remoteIndex, properties1);
|
||||||
|
remoteTransports1 = Collections.singletonList(remoteTransport1);
|
||||||
|
remoteProperties1 = Collections.singletonMap(contactId, properties1);
|
||||||
|
db.setTransports(txn, contactId, remoteTransports1, 3);
|
||||||
|
assertEquals(remoteProperties1,
|
||||||
|
db.getRemoteProperties(txn, transportId));
|
||||||
|
|
||||||
|
// Remove the transport
|
||||||
|
db.setTransports(txn, contactId, Collections.<Transport>emptyList(), 4);
|
||||||
assertEquals(Collections.emptyMap(),
|
assertEquals(Collections.emptyMap(),
|
||||||
db.getRemoteProperties(txn, transportId));
|
db.getRemoteProperties(txn, transportId));
|
||||||
|
|
||||||
@@ -1035,13 +1044,12 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
// Allocate a transport index
|
// Allocate a transport index
|
||||||
assertEquals(localIndex, db.addTransport(txn, transportId));
|
assertEquals(localIndex, db.addTransport(txn, transportId));
|
||||||
|
|
||||||
// Set the local transport properties
|
// Set the transport properties
|
||||||
db.setLocalProperties(txn, transportId, properties);
|
db.setLocalProperties(txn, transportId, properties);
|
||||||
assertEquals(Collections.singletonList(properties),
|
assertEquals(Collections.singletonList(properties),
|
||||||
db.getLocalTransports(txn));
|
db.getLocalTransports(txn));
|
||||||
|
|
||||||
// Remove the local transport properties - the transport itself will
|
// Remove the transport properties but leave the transport
|
||||||
// not be removed
|
|
||||||
db.setLocalProperties(txn, transportId, new TransportProperties());
|
db.setLocalProperties(txn, transportId, new TransportProperties());
|
||||||
assertEquals(Collections.singletonList(Collections.emptyMap()),
|
assertEquals(Collections.singletonList(Collections.emptyMap()),
|
||||||
db.getLocalTransports(txn));
|
db.getLocalTransports(txn));
|
||||||
@@ -1084,7 +1092,7 @@ public class H2DatabaseTest extends TestCase {
|
|||||||
Database<Connection> db = open(false);
|
Database<Connection> db = open(false);
|
||||||
Connection txn = db.startTransaction();
|
Connection txn = db.startTransaction();
|
||||||
|
|
||||||
// Add a contact with some transport properties
|
// Add a contact with a transport
|
||||||
assertEquals(contactId, db.addContact(txn, secret));
|
assertEquals(contactId, db.addContact(txn, secret));
|
||||||
db.setTransports(txn, contactId, remoteTransports, 1);
|
db.setTransports(txn, contactId, remoteTransports, 1);
|
||||||
assertEquals(remoteProperties,
|
assertEquals(remoteProperties,
|
||||||
|
|||||||
Reference in New Issue
Block a user