mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Add placeholder BlockSource implementation to DB.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package org.briarproject.bramble.db;
|
||||
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.io.BlockSource;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
class BlockSourceImpl implements BlockSource {
|
||||
|
||||
private final DatabaseComponent db;
|
||||
|
||||
@Inject
|
||||
BlockSourceImpl(DatabaseComponent db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockCount(MessageId m) throws DbException {
|
||||
return db.transactionWithResult(true, txn -> db.getBlockCount(txn, m));
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBlock(MessageId m, int blockNumber) throws DbException {
|
||||
return db.transactionWithResult(true, txn ->
|
||||
db.getBlock(txn, m, blockNumber));
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.db.DbRunnable;
|
||||
import org.briarproject.bramble.api.db.Metadata;
|
||||
import org.briarproject.bramble.api.db.MigrationListener;
|
||||
import org.briarproject.bramble.api.db.NoSuchBlockException;
|
||||
import org.briarproject.bramble.api.db.NoSuchContactException;
|
||||
import org.briarproject.bramble.api.db.NoSuchGroupException;
|
||||
import org.briarproject.bramble.api.db.NoSuchLocalAuthorException;
|
||||
@@ -420,6 +421,26 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockCount(Transaction transaction, MessageId m)
|
||||
throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsMessage(txn, m))
|
||||
throw new NoSuchMessageException();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getBlock(Transaction transaction, MessageId m,
|
||||
int blockNumber) throws DbException {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsMessage(txn, m))
|
||||
throw new NoSuchMessageException();
|
||||
if (blockNumber != 0)
|
||||
throw new NoSuchBlockException();
|
||||
return db.getMessage(txn, m).getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contact getContact(Transaction transaction, ContactId c)
|
||||
throws DbException {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.briarproject.bramble.db;
|
||||
import org.briarproject.bramble.api.db.DatabaseComponent;
|
||||
import org.briarproject.bramble.api.db.DatabaseConfig;
|
||||
import org.briarproject.bramble.api.event.EventBus;
|
||||
import org.briarproject.bramble.api.io.BlockSource;
|
||||
import org.briarproject.bramble.api.lifecycle.ShutdownManager;
|
||||
import org.briarproject.bramble.api.sync.MessageFactory;
|
||||
import org.briarproject.bramble.api.system.Clock;
|
||||
@@ -31,4 +32,9 @@ public class DatabaseModule {
|
||||
return new DatabaseComponentImpl<>(db, Connection.class, eventBus,
|
||||
shutdown);
|
||||
}
|
||||
|
||||
@Provides
|
||||
BlockSource provideBlockSource(BlockSourceImpl blockSource) {
|
||||
return blockSource;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user