mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-15 12:19:54 +01:00
Code cleanup: import static, use == to compare enum values.
This commit is contained in:
@@ -523,9 +523,8 @@ interface Database<T> {
|
||||
throws DbException;
|
||||
|
||||
/**
|
||||
* Removes outstanding messages that have been acknowledged. Any of the
|
||||
* messages that are still considered outstanding (Status.SENT) with
|
||||
* respect to the given contact are now considered seen (Status.SEEN).
|
||||
* Marks any of the given messages that are considered outstanding with
|
||||
* respect to the given contact as seen by the contact.
|
||||
* <p>
|
||||
* Locking: contact read, message write.
|
||||
*/
|
||||
@@ -625,9 +624,8 @@ interface Database<T> {
|
||||
|
||||
/**
|
||||
* If the database contains the given message and it belongs to a group
|
||||
* that is visible to the given contact, sets the status of the message
|
||||
* with respect to the contact to Status.SEEN and returns true; otherwise
|
||||
* returns false.
|
||||
* that is visible to the given contact, marks the message as seen by the
|
||||
* contact and returns true; otherwise returns false.
|
||||
* <p>
|
||||
* Locking: contact read, message write, subscription read.
|
||||
*/
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package net.sf.briar.db;
|
||||
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static net.sf.briar.api.Rating.GOOD;
|
||||
import static net.sf.briar.db.DatabaseConstants.BYTES_PER_SWEEP;
|
||||
import static net.sf.briar.db.DatabaseConstants.CRITICAL_FREE_SPACE;
|
||||
import static net.sf.briar.db.DatabaseConstants.MAX_BYTES_BETWEEN_SPACE_CHECKS;
|
||||
import static net.sf.briar.db.DatabaseConstants.MAX_MS_BETWEEN_SPACE_CHECKS;
|
||||
import static net.sf.briar.db.DatabaseConstants.MIN_FREE_SPACE;
|
||||
import static net.sf.briar.db.Status.NEW;
|
||||
import static net.sf.briar.db.Status.SEEN;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -274,11 +277,11 @@ DatabaseCleaner.Callback {
|
||||
boolean stored = db.addGroupMessage(txn, m);
|
||||
// Mark the message as seen by the sender
|
||||
MessageId id = m.getId();
|
||||
if(sender != null) db.setStatus(txn, sender, id, Status.SEEN);
|
||||
if(sender != null) db.setStatus(txn, sender, id, SEEN);
|
||||
if(stored) {
|
||||
// Mark the message as unseen by other contacts
|
||||
for(ContactId c : db.getContacts(txn)) {
|
||||
if(!c.equals(sender)) db.setStatus(txn, c, id, Status.NEW);
|
||||
if(!c.equals(sender)) db.setStatus(txn, c, id, NEW);
|
||||
}
|
||||
// Calculate and store the message's sendability
|
||||
int sendability = calculateSendability(txn, m);
|
||||
@@ -301,7 +304,7 @@ DatabaseCleaner.Callback {
|
||||
int sendability = 0;
|
||||
// One point for a good rating
|
||||
AuthorId a = m.getAuthor();
|
||||
if(a != null && db.getRating(txn, a) == Rating.GOOD) sendability++;
|
||||
if(a != null && db.getRating(txn, a) == GOOD) sendability++;
|
||||
// One point per sendable child (backward inclusion)
|
||||
sendability += db.getNumberOfSendableChildren(txn, m.getId());
|
||||
return sendability;
|
||||
@@ -438,8 +441,8 @@ DatabaseCleaner.Callback {
|
||||
if(m.getAuthor() != null) throw new IllegalArgumentException();
|
||||
if(!db.addPrivateMessage(txn, m, c)) return false;
|
||||
MessageId id = m.getId();
|
||||
if(incoming) db.setStatus(txn, c, id, Status.SEEN);
|
||||
else db.setStatus(txn, c, id, Status.NEW);
|
||||
if(incoming) db.setStatus(txn, c, id, SEEN);
|
||||
else db.setStatus(txn, c, id, NEW);
|
||||
// Count the bytes stored
|
||||
synchronized(spaceLock) {
|
||||
bytesStoredSinceLastCheck += m.getSerialised().length;
|
||||
@@ -518,7 +521,7 @@ DatabaseCleaner.Callback {
|
||||
messageLock.readLock().unlock();
|
||||
}
|
||||
if(messages.isEmpty()) return null;
|
||||
// Record the message as sent
|
||||
// Record the messages as sent
|
||||
messageLock.writeLock().lock();
|
||||
try {
|
||||
T txn = db.startTransaction();
|
||||
@@ -1553,9 +1556,9 @@ DatabaseCleaner.Callback {
|
||||
Rating old = db.setRating(txn, a, r);
|
||||
changed = (old != r);
|
||||
// Update the sendability of the author's messages
|
||||
if(r == Rating.GOOD && old != Rating.GOOD)
|
||||
if(r == GOOD && old != GOOD)
|
||||
updateAuthorSendability(txn, a, true);
|
||||
else if(r != Rating.GOOD && old == Rating.GOOD)
|
||||
else if(r != GOOD && old == GOOD)
|
||||
updateAuthorSendability(txn, a, false);
|
||||
db.commitTransaction(txn);
|
||||
} catch(DbException e) {
|
||||
|
||||
@@ -3,7 +3,11 @@ package net.sf.briar.db;
|
||||
import static java.sql.Types.BINARY;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static net.sf.briar.api.Rating.UNRATED;
|
||||
import static net.sf.briar.db.DatabaseConstants.RETENTION_MODULUS;
|
||||
import static net.sf.briar.db.Status.NEW;
|
||||
import static net.sf.briar.db.Status.SEEN;
|
||||
import static net.sf.briar.db.Status.SENT;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -649,9 +653,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
String sql = "UPDATE statuses SET status = ?"
|
||||
+ " WHERE messageId = ? AND contactId = ? AND status = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setShort(1, (short) Status.SENT.ordinal());
|
||||
ps.setShort(1, (short) SENT.ordinal());
|
||||
ps.setInt(3, c.getInt());
|
||||
ps.setShort(4, (short) Status.NEW.ordinal());
|
||||
ps.setShort(4, (short) NEW.ordinal());
|
||||
for(MessageId m : sent) {
|
||||
ps.setBytes(2, m.getBytes());
|
||||
ps.addBatch();
|
||||
@@ -1227,7 +1231,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " ORDER BY timestamp DESC LIMIT ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setShort(2, (short) Status.NEW.ordinal());
|
||||
ps.setShort(2, (short) NEW.ordinal());
|
||||
ps.setInt(3, maxMessages);
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
@@ -1255,7 +1259,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " ORDER BY timestamp DESC LIMIT ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setShort(2, (short) Status.NEW.ordinal());
|
||||
ps.setShort(2, (short) NEW.ordinal());
|
||||
ps.setInt(3, maxMessages - ids.size());
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()) ids.add(new MessageId(rs.getBytes(2)));
|
||||
@@ -1341,7 +1345,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
rs = ps.executeQuery();
|
||||
Rating r;
|
||||
if(rs.next()) r = Rating.values()[rs.getByte(1)];
|
||||
else r = Rating.UNRATED;
|
||||
else r = UNRATED;
|
||||
if(rs.next()) throw new DbStateException();
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1391,7 +1395,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, m.getBytes());
|
||||
ps.setInt(2, c.getInt());
|
||||
ps.setShort(3, (short) Status.NEW.ordinal());
|
||||
ps.setShort(3, (short) NEW.ordinal());
|
||||
rs = ps.executeQuery();
|
||||
byte[] raw = null;
|
||||
if(rs.next()) {
|
||||
@@ -1423,7 +1427,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, m.getBytes());
|
||||
ps.setInt(2, c.getInt());
|
||||
ps.setShort(3, (short) Status.NEW.ordinal());
|
||||
ps.setShort(3, (short) NEW.ordinal());
|
||||
rs = ps.executeQuery();
|
||||
if(rs.next()) {
|
||||
int length = rs.getInt(1);
|
||||
@@ -1638,7 +1642,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " ORDER BY timestamp DESC";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setShort(2, (short) Status.NEW.ordinal());
|
||||
ps.setShort(2, (short) NEW.ordinal());
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
int total = 0;
|
||||
@@ -1670,7 +1674,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " ORDER BY timestamp DESC";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setShort(2, (short) Status.NEW.ordinal());
|
||||
ps.setShort(2, (short) NEW.ordinal());
|
||||
rs = ps.executeQuery();
|
||||
while(rs.next()) {
|
||||
int length = rs.getInt(1);
|
||||
@@ -1995,7 +1999,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " LIMIT ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setShort(2, (short) Status.NEW.ordinal());
|
||||
ps.setShort(2, (short) NEW.ordinal());
|
||||
ps.setInt(3, 1);
|
||||
rs = ps.executeQuery();
|
||||
boolean found = rs.next();
|
||||
@@ -2022,7 +2026,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " LIMIT ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setShort(2, (short) Status.NEW.ordinal());
|
||||
ps.setShort(2, (short) NEW.ordinal());
|
||||
ps.setInt(3, 1);
|
||||
rs = ps.executeQuery();
|
||||
found = rs.next();
|
||||
@@ -2100,9 +2104,9 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
String sql = "UPDATE statuses SET status = ?"
|
||||
+ " WHERE messageId = ? AND contactId = ? AND status = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setShort(1, (short) Status.SEEN.ordinal());
|
||||
ps.setShort(1, (short) SEEN.ordinal());
|
||||
ps.setInt(3, c.getInt());
|
||||
ps.setShort(4, (short) Status.SENT.ordinal());
|
||||
ps.setShort(4, (short) SENT.ordinal());
|
||||
for(MessageId m : acked) {
|
||||
ps.setBytes(2, m.getBytes());
|
||||
ps.addBatch();
|
||||
@@ -2417,7 +2421,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
if(rs.next()) throw new DbStateException();
|
||||
rs.close();
|
||||
ps.close();
|
||||
if(!old.equals(r)) {
|
||||
if(old != r) {
|
||||
sql = "UPDATE ratings SET rating = ? WHERE authorId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setShort(1, (short) r.ordinal());
|
||||
@@ -2430,8 +2434,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
// No rating row exists - create one if necessary
|
||||
rs.close();
|
||||
ps.close();
|
||||
old = Rating.UNRATED;
|
||||
if(!old.equals(r)) {
|
||||
old = UNRATED;
|
||||
if(old != r) {
|
||||
sql = "INSERT INTO ratings (authorId, rating)"
|
||||
+ " VALUES (?, ?)";
|
||||
ps = txn.prepareStatement(sql);
|
||||
@@ -2625,7 +2629,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
if(rs.next()) throw new DbStateException();
|
||||
rs.close();
|
||||
ps.close();
|
||||
if(!old.equals(Status.SEEN) && !old.equals(s)) {
|
||||
if(old != SEEN && old != s) {
|
||||
sql = "UPDATE statuses SET status = ?"
|
||||
+ " WHERE messageId = ? AND contactId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
@@ -2685,7 +2689,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
sql = "UPDATE statuses SET status = ?"
|
||||
+ " WHERE messageId = ? AND contactId = ?";
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setShort(1, (short) Status.SEEN.ordinal());
|
||||
ps.setShort(1, (short) SEEN.ordinal());
|
||||
ps.setBytes(2, m.getBytes());
|
||||
ps.setInt(3, c.getInt());
|
||||
int affected = ps.executeUpdate();
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.sf.briar.messaging.duplex;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
import static net.sf.briar.api.Rating.GOOD;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -21,7 +22,6 @@ import java.util.logging.Logger;
|
||||
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.FormatException;
|
||||
import net.sf.briar.api.Rating;
|
||||
import net.sf.briar.api.db.DatabaseComponent;
|
||||
import net.sf.briar.api.db.DatabaseExecutor;
|
||||
import net.sf.briar.api.db.DbException;
|
||||
@@ -147,7 +147,7 @@ abstract class DuplexConnection implements DatabaseListener {
|
||||
dbExecutor.execute(new GenerateAcks());
|
||||
} else if(e instanceof RatingChangedEvent) {
|
||||
RatingChangedEvent r = (RatingChangedEvent) e;
|
||||
if(r.getRating() == Rating.GOOD && canSendOffer.getAndSet(false))
|
||||
if(r.getRating() == GOOD && canSendOffer.getAndSet(false))
|
||||
dbExecutor.execute(new GenerateOffer());
|
||||
} else if(e instanceof RemoteRetentionTimeUpdatedEvent) {
|
||||
dbExecutor.execute(new GenerateRetentionAck());
|
||||
|
||||
Reference in New Issue
Block a user