Skip to content

Commit

Permalink
PLEASE use the newest release in production and NOT THIS VERSION!
Browse files Browse the repository at this point in the history
Refactored BurstIterators for DB Access to JOOQ
- removed db abstraction layer, which is replaced by JOOQ
- allow use of DbIterator and BurstIterator using JOOQ DSLContext
- fixed different vulnerabilities

Please note, there are still several issues which needs to be fixed
before releasing (eg. blocking Connections due to mixed Hikari Pool
Usage by JOOQ and plain JDBC, firebird table name length, etc.):
-
  • Loading branch information
ac0v committed Dec 27, 2017
1 parent d05c2db commit 8d09a04
Show file tree
Hide file tree
Showing 111 changed files with 1,389 additions and 3,079 deletions.
10 changes: 3 additions & 7 deletions src/brs/Burst.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import com.codahale.metrics.MetricRegistry;
import com.github.gquintana.metrics.util.SqlObjectNameFactory;
import brs.db.firebird.FirebirdDbs;
import brs.db.firebird.FirebirdStores;
import brs.db.h2.H2Dbs;
import brs.db.h2.H2Stores;
import brs.db.mariadb.MariadbDbs;
import brs.db.mariadb.MariadbStores;
import brs.db.sql.Db;
import brs.db.store.Dbs;
import brs.db.store.Stores;
Expand All @@ -35,7 +32,7 @@ public final class Burst {
public static final String APPLICATION = "BRS";

private static final String LOG_UNDEF_NAME_DEFAULT = "{} undefined. Default: {}";

public static final MetricRegistry metrics = new MetricRegistry();
private static final Logger logger = LoggerFactory.getLogger(Burst.class);
private static final Properties defaultProperties = new Properties();
Expand Down Expand Up @@ -256,21 +253,20 @@ private static class Init {
case MARIADB:
logger.info("Using mariadb Backend");
dbs = new MariadbDbs();
stores = new MariadbStores();
break;
case FIREBIRD:
logger.info("Using Firebird Backend");
dbs = new FirebirdDbs();
stores = new FirebirdStores();
break;
case H2:
logger.info("Using h2 Backend");
dbs = new H2Dbs();
stores = new H2Stores();
break;
default:
throw new RuntimeException("Error initializing wallet: Unknown database type");
}
stores = new Stores();

TransactionProcessorImpl.getInstance();
BlockchainProcessorImpl.getInstance();

Expand Down
5 changes: 3 additions & 2 deletions src/brs/TransactionDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import brs.schema.tables.records.TransactionRecord;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.List;

import org.jooq.DSLContext;

public interface TransactionDb {
Transaction findTransaction(long transactionId);

Expand All @@ -17,7 +18,7 @@ public interface TransactionDb {

TransactionImpl loadTransaction(TransactionRecord transactionRecord) throws BurstException.ValidationException;

TransactionImpl loadTransaction(Connection con, ResultSet rs) throws BurstException.ValidationException;
TransactionImpl loadTransaction(DSLContext ctx, ResultSet rs) throws BurstException.ValidationException;

List<TransactionImpl> findBlockTransactions(long blockId);

Expand Down
6 changes: 3 additions & 3 deletions src/brs/db/BlockDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import brs.BlockImpl;
import brs.BurstException;

import java.sql.Connection;
import java.sql.ResultSet;

import org.jooq.Record;
import org.jooq.DSLContext;

public interface BlockDb {
BlockImpl findBlock(long blockId);
Expand All @@ -21,9 +21,9 @@ public interface BlockDb {

BlockImpl findLastBlock(int timestamp);

BlockImpl loadBlock(Connection con, ResultSet rs) throws BurstException.ValidationException;
BlockImpl loadBlock(DSLContext ctx, ResultSet rs) throws BurstException.ValidationException;

void saveBlock(Connection con, BlockImpl block);
void saveBlock(DSLContext ctx, BlockImpl block);

// relying on cascade triggers in the database to delete the transactions for all deleted blocks
void deleteBlocksFrom(long blockId);
Expand Down
4 changes: 3 additions & 1 deletion src/brs/db/BurstIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.sql.ResultSet;
import java.util.Iterator;

import org.jooq.DSLContext;

public interface BurstIterator<T> extends Iterator<T>, Iterable<T>, AutoCloseable {
@Override
boolean hasNext();
Expand All @@ -21,6 +23,6 @@ public interface BurstIterator<T> extends Iterator<T>, Iterable<T>, AutoCloseabl
Iterator<T> iterator();

public interface ResultSetReader<T> {
T get(Connection con, ResultSet rs) throws Exception;
T get(DSLContext ctx, ResultSet rs) throws Exception;
}
}
1 change: 1 addition & 0 deletions src/brs/db/BurstKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Factory<T> {

int setPK(PreparedStatement pstmt, int index) throws SQLException;

long[] getPKValues();

interface LongKeyFactory<T> extends Factory<T> {
@Override
Expand Down
21 changes: 10 additions & 11 deletions src/brs/db/EntityTable.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package brs.db;

import brs.db.sql.DbClause;

import java.sql.Connection;
import java.sql.PreparedStatement;
import org.jooq.DSLContext;
import org.jooq.Condition;
import org.jooq.SelectQuery;

public interface EntityTable<T> extends DerivedTable {
void checkAvailable(int height);
Expand All @@ -12,19 +11,19 @@ public interface EntityTable<T> extends DerivedTable {

T get(BurstKey dbKey, int height);

T getBy(DbClause dbClause);
T getBy(Condition condition);

T getBy(DbClause dbClause, int height);
T getBy(Condition condition, int height);

BurstIterator<T> getManyBy(DbClause dbClause, int from, int to);
BurstIterator<T> getManyBy(Condition condition, int from, int to);

BurstIterator<T> getManyBy(DbClause dbClause, int from, int to, String sort);
BurstIterator<T> getManyBy(Condition condition, int from, int to, String sort);

BurstIterator<T> getManyBy(DbClause dbClause, int height, int from, int to);
BurstIterator<T> getManyBy(Condition condition, int height, int from, int to);

BurstIterator<T> getManyBy(DbClause dbClause, int height, int from, int to, String sort);
BurstIterator<T> getManyBy(Condition condition, int height, int from, int to, String sort);

BurstIterator<T> getManyBy(Connection con, PreparedStatement pstmt, boolean cache);
BurstIterator<T> getManyBy(DSLContext ctx, SelectQuery query, boolean cache);

BurstIterator<T> getAll(int from, int to);

Expand Down
19 changes: 9 additions & 10 deletions src/brs/db/VersionedBatchEntityTable.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package brs.db;

import brs.db.sql.DbClause;

import java.sql.Connection;
import java.sql.PreparedStatement;
import org.jooq.DSLContext;
import org.jooq.Condition;
import org.jooq.SelectQuery;

public interface VersionedBatchEntityTable<T> extends DerivedTable, EntityTable<T> {
boolean delete(T t);
Expand All @@ -21,22 +20,22 @@ public interface VersionedBatchEntityTable<T> extends DerivedTable, EntityTable<
T get(BurstKey dbKey, int height);

@Override
T getBy(DbClause dbClause);
T getBy(Condition condition);

@Override
T getBy(DbClause dbClause, int height);
T getBy(Condition condition, int height);

@Override
BurstIterator<T> getManyBy(DbClause dbClause, int from, int to, String sort);
BurstIterator<T> getManyBy(Condition condition, int from, int to, String sort);

@Override
BurstIterator<T> getManyBy(DbClause dbClause, int height, int from, int to);
BurstIterator<T> getManyBy(Condition condition, int height, int from, int to);

@Override
BurstIterator<T> getManyBy(DbClause dbClause, int height, int from, int to, String sort);
BurstIterator<T> getManyBy(Condition condition, int height, int from, int to, String sort);

@Override
BurstIterator<T> getManyBy(Connection con, PreparedStatement pstmt, boolean cache);
BurstIterator<T> getManyBy(DSLContext ctx, SelectQuery query, boolean cache);

@Override
BurstIterator<T> getAll(int from, int to);
Expand Down
59 changes: 0 additions & 59 deletions src/brs/db/firebird/FirebirdATStore.java

This file was deleted.

103 changes: 0 additions & 103 deletions src/brs/db/firebird/FirebirdAccountStore.java

This file was deleted.

27 changes: 0 additions & 27 deletions src/brs/db/firebird/FirebirdAliasStore.java

This file was deleted.

6 changes: 0 additions & 6 deletions src/brs/db/firebird/FirebirdAssetStore.java

This file was deleted.

Loading

0 comments on commit 8d09a04

Please sign in to comment.