mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 13:49:53 +01:00
Added size-unlimited version of Database.getSendableMessages().
This commit is contained in:
@@ -270,6 +270,16 @@ interface Database<T> {
|
|||||||
*/
|
*/
|
||||||
int getSendability(T txn, MessageId m) throws DbException;
|
int getSendability(T txn, MessageId m) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the IDs of some messages that are eligible to be sent to the
|
||||||
|
* given contact.
|
||||||
|
* <p>
|
||||||
|
* Locking: contacts read, messages read, messageStatuses read,
|
||||||
|
* subscriptions read.
|
||||||
|
*/
|
||||||
|
Collection<MessageId> getSendableMessages(T txn, ContactId c)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the IDs of some messages that are eligible to be sent to the
|
* Returns the IDs of some messages that are eligible to be sent to the
|
||||||
* given contact, with a total size less than or equal to the given size.
|
* given contact, with a total size less than or equal to the given size.
|
||||||
|
|||||||
@@ -564,8 +564,7 @@ DatabaseCleaner.Callback {
|
|||||||
try {
|
try {
|
||||||
T txn = db.startTransaction();
|
T txn = db.startTransaction();
|
||||||
try {
|
try {
|
||||||
sendable = db.getSendableMessages(txn, c,
|
sendable = db.getSendableMessages(txn, c);
|
||||||
Integer.MAX_VALUE);
|
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
} catch(DbException e) {
|
} catch(DbException e) {
|
||||||
db.abortTransaction(txn);
|
db.abortTransaction(txn);
|
||||||
|
|||||||
@@ -1185,6 +1185,58 @@ abstract class JdbcDatabase implements Database<Connection> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<MessageId> getSendableMessages(Connection txn,
|
||||||
|
ContactId c) throws DbException {
|
||||||
|
PreparedStatement ps = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
// Do we have any sendable private messages?
|
||||||
|
String sql = "SELECT messages.messageId FROM messages"
|
||||||
|
+ " JOIN statuses ON messages.messageId = statuses.messageId"
|
||||||
|
+ " WHERE messages.contactId = ? AND status = ?"
|
||||||
|
+ " ORDER BY timestamp";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setInt(1, c.getInt());
|
||||||
|
ps.setShort(2, (short) Status.NEW.ordinal());
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
Collection<MessageId> ids = new ArrayList<MessageId>();
|
||||||
|
while(rs.next()) ids.add(new MessageId(rs.getBytes(2)));
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
if(LOG.isLoggable(Level.FINE))
|
||||||
|
LOG.fine(ids.size() + " sendable private messages");
|
||||||
|
// Do we have any sendable group messages?
|
||||||
|
sql = "SELECT messages.messageId FROM messages"
|
||||||
|
+ " JOIN contactSubscriptions"
|
||||||
|
+ " ON messages.groupId = contactSubscriptions.groupId"
|
||||||
|
+ " JOIN visibilities"
|
||||||
|
+ " ON messages.groupId = visibilities.groupId"
|
||||||
|
+ " AND contactSubscriptions.contactId = visibilities.contactId"
|
||||||
|
+ " JOIN statuses"
|
||||||
|
+ " ON messages.messageId = statuses.messageId"
|
||||||
|
+ " AND contactSubscriptions.contactId = statuses.contactId"
|
||||||
|
+ " WHERE contactSubscriptions.contactId = ?"
|
||||||
|
+ " AND timestamp >= start"
|
||||||
|
+ " AND status = ?"
|
||||||
|
+ " AND sendability > ZERO()"
|
||||||
|
+ " ORDER BY timestamp";
|
||||||
|
ps = txn.prepareStatement(sql);
|
||||||
|
ps.setInt(1, c.getInt());
|
||||||
|
ps.setShort(2, (short) Status.NEW.ordinal());
|
||||||
|
rs = ps.executeQuery();
|
||||||
|
while(rs.next()) ids.add(new MessageId(rs.getBytes(2)));
|
||||||
|
rs.close();
|
||||||
|
ps.close();
|
||||||
|
if(LOG.isLoggable(Level.FINE))
|
||||||
|
LOG.fine(ids.size() + " sendable private and group messages");
|
||||||
|
return ids;
|
||||||
|
} catch(SQLException e) {
|
||||||
|
tryToClose(rs);
|
||||||
|
tryToClose(ps);
|
||||||
|
throw new DbException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<MessageId> getSendableMessages(Connection txn,
|
public Collection<MessageId> getSendableMessages(Connection txn,
|
||||||
ContactId c, int capacity) throws DbException {
|
ContactId c, int capacity) throws DbException {
|
||||||
PreparedStatement ps = null;
|
PreparedStatement ps = null;
|
||||||
|
|||||||
@@ -826,8 +826,7 @@ public abstract class DatabaseComponentTest extends TestCase {
|
|||||||
allowing(database).containsContact(txn, contactId);
|
allowing(database).containsContact(txn, contactId);
|
||||||
will(returnValue(true));
|
will(returnValue(true));
|
||||||
// Get the sendable message IDs
|
// Get the sendable message IDs
|
||||||
oneOf(database).getSendableMessages(txn, contactId,
|
oneOf(database).getSendableMessages(txn, contactId);
|
||||||
Integer.MAX_VALUE);
|
|
||||||
will(returnValue(sendable));
|
will(returnValue(sendable));
|
||||||
// Try to add both IDs to the writer - only manage to add one
|
// Try to add both IDs to the writer - only manage to add one
|
||||||
oneOf(offerWriter).writeMessageId(messageId);
|
oneOf(offerWriter).writeMessageId(messageId);
|
||||||
|
|||||||
Reference in New Issue
Block a user