Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8f33ea0

Browse files
committedApr 6, 2022
[#929] H2 module integration
1 parent 8446851 commit 8f33ea0

File tree

8 files changed

+60
-10
lines changed

8 files changed

+60
-10
lines changed
 

‎.github/workflows/tracking-orm-5.build.yml

+19-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
strategy:
9090
matrix:
9191
orm-version: [ '[5.6,5.7)' ]
92-
db: [ 'MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle' ]
92+
db: [ 'MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle', 'H2' ]
9393
steps:
9494
- uses: actions/checkout@v2
9595
- name: Set up JDK 11
@@ -101,3 +101,21 @@ jobs:
101101
- name: Build and Test with ${{ matrix.db }}
102102
run: ./gradlew build -Pdb=${{ matrix.db }} -Pdocker -PhibernateOrmVersion='${{ matrix.orm-version }}' -PskipOrmVersionParsing -PenableJBossSnapshotsRep -PshowStandardOutput
103103

104+
# test_h2:
105+
# name: Test with ${{ matrix.db }} and ORM ${{ matrix.orm-version }}
106+
# runs-on: ubuntu-latest
107+
# strategy:
108+
# matrix:
109+
# orm-version: [ '[5.6,5.7)' ]
110+
# db: [ 'H2' ]
111+
# steps:
112+
# - uses: actions/checkout@v2
113+
# - name: Set up JDK 11
114+
# uses: actions/setup-java@v1
115+
# with:
116+
# java-version: 11
117+
# - name: Print the effective ORM version used
118+
# run: ./gradlew :hibernate-reactive-core:dependencyInsight --dependency org.hibernate:hibernate-core -PhibernateOrmVersion='${{ matrix.orm-version }}' -PskipOrmVersionParsing -PenableJBossSnapshotsRep
119+
# - name: Build and Test with ${{ matrix.db }}
120+
# run: ./gradlew build -Pdb=${{ matrix.db }} -PhibernateOrmVersion='${{ matrix.orm-version }}' -PskipOrmVersionParsing -PenableJBossSnapshotsRep -PshowStandardOutput
121+

‎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.20.2'
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}"
@@ -132,7 +134,7 @@ tasks.addRule( "Pattern testDb<id>" ) { String taskName ->
132134
}
133135

134136
// The dbs we want to test when running testAll
135-
def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle']
137+
def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle', 'H2']
136138
task testAll( dependsOn: dbs.collect( [] as HashSet ) { db -> "testDb${db}" } ) {
137139
description = "Run tests for ${dbs}"
138140
}

‎hibernate-reactive-core/src/main/java/org/hibernate/reactive/adaptor/impl/ResultSetAdaptor.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,17 @@ public class ResultSetAdaptor implements ResultSet {
5151
private boolean wasNull;
5252

5353
public ResultSetAdaptor(RowSet<Row> rows) {
54-
this.iterator = rows.iterator();
54+
this.iterator = rows != null ? rows.iterator() : new RowIterator<Row>() {
55+
@Override
56+
public boolean hasNext() {
57+
return false;
58+
}
59+
60+
@Override
61+
public Row next() {
62+
return null;
63+
}
64+
};
5565
this.rows = rows;
5666
}
5767

‎hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/DefaultSqlClientPoolConfiguration.java

+9-1
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 );
@@ -101,7 +109,7 @@ public SqlConnectOptions connectOptions(URI uri) {
101109
: "";
102110

103111
if ( scheme.equals( "db2" ) && database.indexOf( ':' ) > 0 ) {
104-
// DB2 URLs are a bit odd and have the format:
112+
// DB2 URLs are a bit odd and have the format:-
105113
// jdbc:db2://<HOST>:<PORT>/<DB>:key1=value1;key2=value2;
106114
database = database.substring( 0, database.indexOf( ':' ) );
107115
}

‎hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/ReactiveConnectionPoolInitiator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ReactiveConnectionPoolInitiator() {}
3838
@Override
3939
public ReactiveConnectionPool initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
4040
Object configValue = configurationValues.get( Settings.SQL_CLIENT_POOL );
41-
if (configValue==null) {
41+
if ( configValue == null ) {
4242
return new DefaultSqlClientPool();
4343
}
4444

‎hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/SqlClientConnection.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ public <T> CompletionStage<T> selectIdentifier(String sql, Object[] paramValues,
9696
return preparedQuery( sql, Tuple.wrap( paramValues ) )
9797
.handle( (rows, throwable) -> convertException( rows, sql, throwable ) )
9898
.thenApply( rowSet -> {
99-
for (Row row: rowSet) {
100-
return row.get(idClass, 0);
99+
if ( rowSet != null ) {
100+
for ( Row row : rowSet ) {
101+
return row.get( idClass, 0 );
102+
}
101103
}
102104
return null;
103105
} );
@@ -170,7 +172,12 @@ public CompletionStage<Integer> update(String sql) {
170172
}
171173

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

176183
public CompletionStage<int[]> updateBatch(String sql, List<Tuple> parametersBatch) {
@@ -180,7 +187,7 @@ public CompletionStage<int[]> updateBatch(String sql, List<Tuple> parametersBatc
180187

181188
int i = 0;
182189
RowSet<Row> resultNext = result;
183-
if ( parametersBatch.size() > 0 ) {
190+
if ( result != null && parametersBatch.size() > 0 ) {
184191
final RowIterator<Row> iterator = resultNext.iterator();
185192
if ( iterator.hasNext() ) {
186193
while ( iterator.hasNext() ) {

‎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
}

‎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)
Please sign in to comment.