Skip to content

Commit bfe4110

Browse files
committed
1 parent 7c33cc9 commit bfe4110

File tree

6 files changed

+52
-11
lines changed

6 files changed

+52
-11
lines changed

Diff for: hibernate-reactive-core/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ dependencies {
3131
testImplementation 'org.assertj:assertj-core:3.22.0'
3232
testImplementation "io.vertx:vertx-unit:${vertxVersion}"
3333

34+
testImplementation project(':hibernate-reactive-h2')
35+
3436
// Drivers
3537
testImplementation "io.vertx:vertx-pg-client:${vertxVersion}"
3638
testImplementation "io.vertx:vertx-mysql-client:${vertxVersion}"
@@ -139,7 +141,7 @@ tasks.addRule( "Pattern testDb<id>" ) { String taskName ->
139141
}
140142

141143
// The dbs we want to test when running testAll
142-
def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle']
144+
def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle', 'H2']
143145
task testAll( dependsOn: dbs.collect( [] as HashSet ) { db -> "testDb${db}" } ) {
144146
description = "Run tests for ${dbs}"
145147
}

Diff for: hibernate-reactive-core/src/main/java/org/hibernate/reactive/adaptor/impl/ResultSetAdaptor.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,31 @@
4545
*/
4646
public class ResultSetAdaptor implements ResultSet {
4747

48+
private static final class EmptyRowIterator implements RowIterator<Row> {
49+
50+
public static final EmptyRowIterator INSTANCE = new EmptyRowIterator();
51+
52+
private EmptyRowIterator() {
53+
}
54+
55+
@Override
56+
public boolean hasNext() {
57+
return false;
58+
}
59+
60+
@Override
61+
public Row next() {
62+
return null;
63+
}
64+
}
65+
4866
private final RowIterator<Row> iterator;
4967
private final RowSet<Row> rows;
5068
private Row row;
5169
private boolean wasNull;
5270

5371
public ResultSetAdaptor(RowSet<Row> rows) {
54-
this.iterator = rows.iterator();
72+
this.iterator = rows != null ? rows.iterator() : EmptyRowIterator.INSTANCE;
5573
this.rows = rows;
5674
}
5775

Diff for: hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/DefaultSqlClientPoolConfiguration.java

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public class DefaultSqlClientPoolConfiguration implements SqlClientPoolConfigura
4949
private String user;
5050
private String pass;
5151

52+
protected String getUser() {
53+
return user;
54+
}
55+
56+
protected String getPassword() {
57+
return pass;
58+
}
59+
5260
@Override
5361
public void configure(Map configuration) {
5462
user = getString( Settings.USER, configuration );

Diff for: hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/SqlClientConnection.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ public <T> CompletionStage<T> selectIdentifier(String sql, Object[] paramValues,
9595
translateNulls( paramValues );
9696
return preparedQuery( sql, Tuple.wrap( paramValues ) )
9797
.handle( (rows, throwable) -> convertException( rows, sql, throwable ) )
98-
.thenApply( rowSet -> {
99-
for (Row row: rowSet) {
100-
return row.get(idClass, 0);
101-
}
102-
return null;
103-
} );
98+
.thenApply( rowSet -> identifierFromFirstRow( idClass, rowSet ) );
99+
}
100+
101+
private <T> T identifierFromFirstRow(Class<T> idClass, RowSet<Row> rowSet) {
102+
if ( rowSet != null ) {
103+
for ( Row row : rowSet ) {
104+
return row.get( idClass, 0 );
105+
}
106+
}
107+
return null;
104108
}
105109

106110
@Override
@@ -170,7 +174,11 @@ public CompletionStage<Integer> update(String sql) {
170174
}
171175

172176
public CompletionStage<Integer> update(String sql, Tuple parameters) {
173-
return preparedQuery( sql, parameters ).thenApply(SqlResult::rowCount);
177+
return preparedQuery( sql, parameters ).thenApply( SqlClientConnection::rowCount );
178+
}
179+
180+
private static Integer rowCount(RowSet<Row> rows) {
181+
return rows == null ? 0 : rows.rowCount();
174182
}
175183

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

181189
int i = 0;
182190
RowSet<Row> resultNext = result;
183-
if ( parametersBatch.size() > 0 ) {
191+
if ( result != null && parametersBatch.size() > 0 ) {
184192
final RowIterator<Row> iterator = resultNext.iterator();
185193
if ( iterator.hasNext() ) {
186194
while ( iterator.hasNext() ) {

Diff for: hibernate-reactive-core/src/main/java/org/hibernate/reactive/provider/service/NoJdbcEnvironmentInitiator.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.hibernate.dialect.CockroachDB201Dialect;
1010
import org.hibernate.dialect.DB297Dialect;
1111
import org.hibernate.dialect.Dialect;
12+
import org.hibernate.dialect.H2Dialect;
1213
import org.hibernate.dialect.MariaDB103Dialect;
1314
import org.hibernate.dialect.MySQL8Dialect;
1415
import org.hibernate.dialect.Oracle12cDialect;
@@ -35,7 +36,7 @@
3536
/**
3637
* A Hibernate {@link StandardServiceInitiator service initiator} that
3738
* provides an implementation of {@link JdbcEnvironment} that infers
38-
* the Hibernate {@link org.hibernate.dialect.Dialect} from the JDBC URL.
39+
* the Hibernate {@link Dialect} from the JDBC URL.
3940
*/
4041
public class NoJdbcEnvironmentInitiator extends JdbcEnvironmentInitiator {
4142
private static final Log LOG = LoggerFactory.make( Log.class, MethodHandles.lookup() );
@@ -147,6 +148,9 @@ else if ( url.startsWith( "sqlserver:" ) ) {
147148
else if ( url.startsWith( "oracle:" ) ) {
148149
return Oracle12cDialect.class;
149150
}
151+
else if ( url.startsWith( "h2:" ) ) {
152+
return H2Dialect.class;
153+
}
150154
else {
151155
return null;
152156
}

Diff for: settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ logger.lifecycle "Java versions for main code: " + gradle.ext.javaVersions.main
8282
logger.lifecycle "Java versions for tests: " + gradle.ext.javaVersions.test
8383

8484
include 'hibernate-reactive-core'
85+
include 'hibernate-reactive-h2'
8586
include 'session-example'
8687
include 'native-sql-example'
8788
include 'verticle-postgres-it'

0 commit comments

Comments
 (0)