forked from Qortal-Forker/qortal
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:
29
src/repository/hsqldb/HSQLDBBlockTransactionRepository.java
Normal file
29
src/repository/hsqldb/HSQLDBBlockTransactionRepository.java
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user