Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Jun 14, 2022
1 parent efd2951 commit 840eb44
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
4 changes: 3 additions & 1 deletion hibernate-reactive-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ dependencies {
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation "io.vertx:vertx-unit:${vertxVersion}"

testImplementation project(':hibernate-reactive-h2')

// Drivers
testImplementation "io.vertx:vertx-pg-client:${vertxVersion}"
testImplementation "io.vertx:vertx-mysql-client:${vertxVersion}"
Expand Down Expand Up @@ -139,7 +141,7 @@ tasks.addRule( "Pattern testDb<id>" ) { String taskName ->
}

// The dbs we want to test when running testAll
def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle']
def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle', 'H2']
task testAll( dependsOn: dbs.collect( [] as HashSet ) { db -> "testDb${db}" } ) {
description = "Run tests for ${dbs}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,31 @@
*/
public class ResultSetAdaptor implements ResultSet {

private static final class EmptyRowIterator implements RowIterator<Row> {

public static final EmptyRowIterator INSTANCE = new EmptyRowIterator();

private EmptyRowIterator() {
}

@Override
public boolean hasNext() {
return false;
}

@Override
public Row next() {
return null;
}
}

private final RowIterator<Row> iterator;
private final RowSet<Row> rows;
private Row row;
private boolean wasNull;

public ResultSetAdaptor(RowSet<Row> rows) {
this.iterator = rows.iterator();
this.iterator = rows != null ? rows.iterator() : EmptyRowIterator.INSTANCE;
this.rows = rows;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public class DefaultSqlClientPoolConfiguration implements SqlClientPoolConfigura
private String user;
private String pass;

protected String getUser() {
return user;
}

protected String getPassword() {
return pass;
}

@Override
public void configure(Map configuration) {
user = getString( Settings.USER, configuration );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ public <T> CompletionStage<T> selectIdentifier(String sql, Object[] paramValues,
translateNulls( paramValues );
return preparedQuery( sql, Tuple.wrap( paramValues ) )
.handle( (rows, throwable) -> convertException( rows, sql, throwable ) )
.thenApply( rowSet -> {
for (Row row: rowSet) {
return row.get(idClass, 0);
}
return null;
} );
.thenApply( rowSet -> identifierFromFirstRow( idClass, rowSet ) );
}

private <T> T identifierFromFirstRow(Class<T> idClass, RowSet<Row> rowSet) {
if ( rowSet != null ) {
for ( Row row : rowSet ) {
return row.get( idClass, 0 );
}
}
return null;
}

@Override
Expand Down Expand Up @@ -170,7 +174,11 @@ public CompletionStage<Integer> update(String sql) {
}

public CompletionStage<Integer> update(String sql, Tuple parameters) {
return preparedQuery( sql, parameters ).thenApply(SqlResult::rowCount);
return preparedQuery( sql, parameters ).thenApply( SqlClientConnection::rowCount );
}

private static Integer rowCount(RowSet<Row> rows) {
return rows == null ? 0 : rows.rowCount();
}

public CompletionStage<int[]> updateBatch(String sql, List<Tuple> parametersBatch) {
Expand All @@ -180,7 +188,7 @@ public CompletionStage<int[]> updateBatch(String sql, List<Tuple> parametersBatc

int i = 0;
RowSet<Row> resultNext = result;
if ( parametersBatch.size() > 0 ) {
if ( result != null && parametersBatch.size() > 0 ) {
final RowIterator<Row> iterator = resultNext.iterator();
if ( iterator.hasNext() ) {
while ( iterator.hasNext() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.hibernate.dialect.CockroachDB201Dialect;
import org.hibernate.dialect.DB297Dialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.MariaDB103Dialect;
import org.hibernate.dialect.MySQL8Dialect;
import org.hibernate.dialect.Oracle12cDialect;
Expand All @@ -35,7 +36,7 @@
/**
* A Hibernate {@link StandardServiceInitiator service initiator} that
* provides an implementation of {@link JdbcEnvironment} that infers
* the Hibernate {@link org.hibernate.dialect.Dialect} from the JDBC URL.
* the Hibernate {@link Dialect} from the JDBC URL.
*/
public class NoJdbcEnvironmentInitiator extends JdbcEnvironmentInitiator {
private static final Log LOG = LoggerFactory.make( Log.class, MethodHandles.lookup() );
Expand Down Expand Up @@ -147,6 +148,9 @@ else if ( url.startsWith( "sqlserver:" ) ) {
else if ( url.startsWith( "oracle:" ) ) {
return Oracle12cDialect.class;
}
else if ( url.startsWith( "h2:" ) ) {
return H2Dialect.class;
}
else {
return null;
}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ logger.lifecycle "Java versions for main code: " + gradle.ext.javaVersions.main
logger.lifecycle "Java versions for tests: " + gradle.ext.javaVersions.test

include 'hibernate-reactive-core'
include 'hibernate-reactive-h2'
include 'session-example'
include 'native-sql-example'
include 'verticle-postgres-it'
Expand Down

0 comments on commit 840eb44

Please sign in to comment.