More work on repository

No need for database.DB class as the code is specific to HSQLDB so moved into relevant repository.hsqldb classes.

Top-level Repository instance (e.g. HSQLDBRepository) is used within subclasses, e.g. HSQLDBBlockRepository, so they
can share the same repository state, like underlying SQL Connection for easier transactional support.

HSQLDBRepository subclasses now call checkedExecute() on top-level repository instance, instead of passing Connection
to obsolete DB.checkedExecute.

No need for qora.block.BlockFactory any more as those methods are now in repository.

More work on Blocks and Transactions in general.
This commit is contained in:
catbref
2018-06-12 10:21:03 +01:00
parent 6a2a172ee8
commit d45c33fe90
20 changed files with 375 additions and 633 deletions

View File

@@ -0,0 +1,29 @@
package repository.hsqldb;
import java.sql.SQLException;
import data.block.BlockTransactionData;
import repository.BlockTransactionRepository;
import repository.DataException;
public class HSQLDBBlockTransactionRepository implements BlockTransactionRepository {
protected HSQLDBRepository repository;
public HSQLDBBlockTransactionRepository(HSQLDBRepository repository) {
this.repository = repository;
}
public void save(BlockTransactionData blockTransactionData) throws DataException {
HSQLDBSaver saveHelper = new HSQLDBSaver("BlockTransactions");
saveHelper.bind("block_signature", blockTransactionData.getBlockSignature()).bind("sequence", blockTransactionData.getSequence())
.bind("transaction_signature", blockTransactionData.getTransactionSignature());
try {
saveHelper.execute(this.repository.connection);
} catch (SQLException e) {
throw new DataException("Unable to save BlockTransaction into repository", e);
}
}
}