Skip to content

Commit 709a5fa

Browse files
committed
[hibernate#2036] Upgrade Vert.x SQL client to 5.0.0
1 parent 0c60e3e commit 709a5fa

File tree

30 files changed

+149
-210
lines changed

30 files changed

+149
-210
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ Learn more at <http://hibernate.org/reactive>.
3030

3131
Hibernate Reactive has been tested with:
3232

33-
- Java 17, 21, 24
33+
- Java 11, 17, 21, 23
3434
- PostgreSQL 16
35-
- MySQL 9
35+
- MySQL 8
3636
- MariaDB 11
37-
- Db2 12
37+
- Db2 11
3838
- CockroachDB v24
3939
- MS SQL Server 2022
4040
- Oracle 23
41-
- [Hibernate ORM][] 7.0.0.CR1
42-
- [Vert.x Reactive PostgreSQL Client](https://vertx.io/docs/vertx-pg-client/java/) 4.5.14
43-
- [Vert.x Reactive MySQL Client](https://vertx.io/docs/vertx-mysql-client/java/) 4.5.14
44-
- [Vert.x Reactive Db2 Client](https://vertx.io/docs/vertx-db2-client/java/) 4.5.14
45-
- [Vert.x Reactive MS SQL Server Client](https://vertx.io/docs/vertx-mssql-client/java/) 4.5.14
46-
- [Vert.x Reactive Oracle Client](https://vertx.io/docs/vertx-oracle-client/java/) 4.5.14
41+
- [Hibernate ORM][] 7.0.0.CR2
42+
- [Vert.x Reactive PostgreSQL Client](https://vertx.io/docs/vertx-pg-client/java/) 5.0.0
43+
- [Vert.x Reactive MySQL Client](https://vertx.io/docs/vertx-mysql-client/java/) 5.0.0
44+
- [Vert.x Reactive Db2 Client](https://vertx.io/docs/vertx-db2-client/java/) 5.0.0
45+
- [Vert.x Reactive MS SQL Server Client](https://vertx.io/docs/vertx-mssql-client/java/) 5.0.0
46+
- [Vert.x Reactive Oracle Client](https://vertx.io/docs/vertx-oracle-client/java/) 5.0.0
4747
- [Quarkus][Quarkus] via the Hibernate Reactive extension
4848

4949
[PostgreSQL]: https://www.postgresql.org

build.gradle

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,21 @@ ext {
2222
// Example:
2323
// ./gradlew build -PvertxSqlClientVersion=4.0.0-SNAPSHOT
2424
if ( !project.hasProperty( 'vertxSqlClientVersion' ) ) {
25-
vertxSqlClientVersion = '4.5.14'
25+
vertxSqlClientVersion = '5.0.0'
2626
}
2727

28-
testcontainersVersion = '1.20.6'
28+
testcontainersVersion = '1.20.4'
2929

3030
logger.lifecycle "Vert.x SQL Client Version: " + project.vertxSqlClientVersion
3131
}
3232

33+
// Publishing to Sonatype (Maven Central):
34+
nexusPublishing {
35+
repositories {
36+
sonatype()
37+
}
38+
}
39+
3340
subprojects {
3441
apply plugin: 'java-library'
3542
apply plugin: 'com.diffplug.spotless'

documentation/src/main/asciidoc/reference/introduction.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Optionally, you might also add any of the following additional features:
8989
| Hibernate Validator | `org.hibernate.validator:hibernate-validator` and `org.glassfish:jakarta.el`
9090
| Compile-time checking for your HQL queries | `org.hibernate:query-validator`
9191
| Second-level cache support via JCache and EHCache | `org.hibernate.orm:hibernate-jcache` along with `org.ehcache:ehcache`
92-
| SCRAM authentication support for PostgreSQL | `com.ongres.scram:client:2.1`
92+
| SCRAM authentication support for PostgreSQL | `com.ongres.scram:scram-client:3.1`
9393
|===
9494

9595
You might also add the Hibernate {enhancer}[bytecode enhancer] to your

examples/native-sql-example/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies {
4040
runtimeOnly "org.apache.logging.log4j:log4j-core:2.20.0"
4141

4242
// Allow authentication to PostgreSQL using SCRAM:
43-
runtimeOnly 'com.ongres.scram:client:2.1'
43+
runtimeOnly 'com.ongres.scram:scram-client:3.1'
4444
}
4545

4646
// Optional: enable the bytecode enhancements

examples/session-example/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies {
4141
runtimeOnly "org.apache.logging.log4j:log4j-core:2.20.0"
4242

4343
// Allow authentication to PostgreSQL using SCRAM:
44-
runtimeOnly 'com.ongres.scram:client:2.1'
44+
runtimeOnly 'com.ongres.scram:scram-client:3.1'
4545
}
4646

4747
// Optional: enable the bytecode enhancements

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ hibernateOrmVersion = 7.0.0.CR2
4040
# Override default Hibernate ORM Gradle plugin version
4141
# Using the stable version because I don't know how to configure the build to download the snapshot version from
4242
# a remote repository
43-
#hibernateOrmGradlePluginVersion = 7.0.0.CR1
43+
#hibernateOrmGradlePluginVersion = 7.0.0.CR2
4444

4545
# If set to true, skip Hibernate ORM version parsing (default is true, if set to null)
4646
# this is required when using intervals or weird versions or the build will fail
4747
#skipOrmVersionParsing = true
4848

4949
# Override default Vert.x Sql client version
50-
#vertxSqlClientVersion = 4.5.14-SNAPSHOT
50+
#vertxSqlClientVersion = 5.0.0-SNAPSHOT
5151

5252
# Override default Vert.x Web client and server versions. For integration tests, both default to vertxSqlClientVersion
53-
#vertxWebVersion = 4.5.14
54-
#vertxWebtClientVersion = 4.5.14
53+
#vertxWebVersion = 5.0.0
54+
#vertxWebtClientVersion = 5.0.0
5555

hibernate-reactive-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies {
3939
testImplementation "io.vertx:vertx-micrometer-metrics:${vertxSqlClientVersion}"
4040

4141
// Optional dependency of vertx-pg-client, essential when connecting via SASL SCRAM
42-
testImplementation 'com.ongres.scram:client:2.1'
42+
testImplementation 'com.ongres.scram:scram-client:3.1'
4343

4444
// JUnit Jupiter
4545
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'

hibernate-reactive-core/src/main/java/org/hibernate/reactive/context/impl/VertxContext.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.lang.invoke.MethodHandles;
99

1010
import io.vertx.core.Vertx;
11-
import io.vertx.core.impl.ContextInternal;
11+
import io.vertx.core.internal.ContextInternal;
1212

1313
import org.hibernate.reactive.context.Context;
1414
import org.hibernate.reactive.logging.impl.Log;
@@ -36,7 +36,7 @@ public void injectServices(ServiceRegistryImplementor serviceRegistry) {
3636

3737
@Override
3838
public <T> void put(Key<T> key, T instance) {
39-
final io.vertx.core.Context context = Vertx.currentContext();
39+
final ContextInternal context = currentContext();
4040
if ( context != null ) {
4141
if ( trace ) LOG.tracef( "Putting key,value in context: [%1$s, %2$s]", key, instance );
4242
context.putLocal( key, instance );
@@ -47,9 +47,13 @@ public <T> void put(Key<T> key, T instance) {
4747
}
4848
}
4949

50+
private static ContextInternal currentContext() {
51+
return (ContextInternal) Vertx.currentContext();
52+
}
53+
5054
@Override
5155
public <T> T get(Key<T> key) {
52-
final io.vertx.core.Context context = Vertx.currentContext();
56+
final ContextInternal context = currentContext();
5357
if ( context != null ) {
5458
T local = context.getLocal( key );
5559
if ( trace ) LOG.tracef( "Getting value %2$s from context for key %1$s", key, local );
@@ -63,7 +67,7 @@ public <T> T get(Key<T> key) {
6367

6468
@Override
6569
public void remove(Key<?> key) {
66-
final io.vertx.core.Context context = Vertx.currentContext();
70+
final ContextInternal context = currentContext();
6771
if ( context != null ) {
6872
boolean removed = context.removeLocal( key );
6973
if ( trace ) LOG.tracef( "Key %s removed from context: %s", key, removed );
@@ -75,14 +79,15 @@ public void remove(Key<?> key) {
7579

7680
@Override
7781
public void execute(Runnable runnable) {
78-
final io.vertx.core.Context currentContext = Vertx.currentContext();
82+
final io.vertx.core.Context currentContext = currentContext();
7983
if ( currentContext == null ) {
8084
if ( trace ) LOG.tracef( "Not in a Vert.x context, checking the VertxInstance service" );
8185
final io.vertx.core.Context newContext = vertxInstance.getVertx().getOrCreateContext();
8286
// Ensure we don't run on the root context, which is globally scoped:
8387
// that could lead to unintentionally share the same session with other streams.
8488
ContextInternal newContextInternal = (ContextInternal) newContext;
8589
final ContextInternal duplicate = newContextInternal.duplicate();
90+
8691
if ( trace ) LOG.tracef( "Using duplicated context from VertxInstance: %s", duplicate );
8792
duplicate.runOnContext( x -> runnable.run() );
8893
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/id/impl/BlockingIdentifierGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
import io.vertx.core.Context;
1616
import io.vertx.core.Vertx;
17-
import io.vertx.core.net.impl.pool.CombinerExecutor;
18-
import io.vertx.core.net.impl.pool.Executor;
19-
import io.vertx.core.net.impl.pool.Task;
17+
import io.vertx.core.internal.pool.CombinerExecutor;
18+
import io.vertx.core.internal.pool.Executor;
19+
import io.vertx.core.internal.pool.Task;
2020

2121
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
2222

@@ -44,7 +44,7 @@ public abstract class BlockingIdentifierGenerator implements ReactiveIdentifierG
4444
//modification access.
4545
//This replaces the synchronization blocks one would see in a similar
4646
//service in Hibernate ORM, but using a non-blocking cooperative design.
47-
private final CombinerExecutor executor = new CombinerExecutor( state );
47+
private final CombinerExecutor<GeneratorState> executor = new CombinerExecutor<>( state );
4848

4949
/**
5050
* Allocate a new block, by obtaining the next "hi" value from the database

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.ServiceConfigurationError;
1414
import java.util.ServiceLoader;
1515
import java.util.concurrent.CompletionStage;
16+
import java.util.function.Supplier;
1617

1718
import org.hibernate.engine.jdbc.spi.JdbcServices;
1819
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
@@ -31,13 +32,13 @@
3132

3233
import io.vertx.core.Future;
3334
import io.vertx.core.Vertx;
35+
import io.vertx.core.net.NetClientOptions;
3436
import io.vertx.sqlclient.Pool;
3537
import io.vertx.sqlclient.PoolOptions;
3638
import io.vertx.sqlclient.SqlConnectOptions;
39+
import io.vertx.sqlclient.impl.Utils;
3740
import io.vertx.sqlclient.spi.Driver;
3841

39-
import static java.util.Collections.singletonList;
40-
4142
/**
4243
* A pool of reactive connections backed by a Vert.x {@link Pool}.
4344
* The {@code Pool} itself is backed by an instance of {@link Vertx}
@@ -189,7 +190,7 @@ protected Pool createPool(URI uri) {
189190
*
190191
* @return the new {@link Pool}
191192
*/
192-
protected Pool createPool(URI uri, SqlConnectOptions connectOptions, PoolOptions poolOptions, Vertx vertx) {
193+
protected <T extends SqlConnectOptions> Pool createPool(URI uri, T connectOptions, PoolOptions poolOptions, Vertx vertx) {
193194
try {
194195
// First try to load the Pool using the standard ServiceLoader pattern
195196
// This only works if exactly 1 Driver is on the classpath.
@@ -198,8 +199,9 @@ protected Pool createPool(URI uri, SqlConnectOptions connectOptions, PoolOptions
198199
catch (ServiceConfigurationError e) {
199200
// Backup option if multiple drivers are on the classpath.
200201
// We will be able to remove this once Vertx 3.9.2 is available
201-
final Driver driver = findDriver( uri, e );
202-
return driver.createPool( vertx, singletonList( connectOptions ), poolOptions );
202+
final Driver<SqlConnectOptions> driver = findDriver( uri, e );
203+
Supplier<Future<SqlConnectOptions>> database = Utils.singletonSupplier( driver.downcast( connectOptions ) );
204+
return driver.createPool( vertx, database, poolOptions, new NetClientOptions(), null );
203205
}
204206
}
205207

@@ -222,15 +224,14 @@ protected URI jdbcUrl(Map<?,?> configurationValues) {
222224
* so we need to disambiguate according to the scheme specified
223225
* in the given {@link URI}.
224226
*
225-
* @param uri the JDBC URL or database URI
227+
* @param uri the JDBC URL or database URI
226228
* @param originalError the error that was thrown
227-
*
228229
* @return the disambiguated {@link Driver}
229230
*/
230-
private Driver findDriver(URI uri, ServiceConfigurationError originalError) {
231+
private Driver<SqlConnectOptions> findDriver(URI uri, ServiceConfigurationError originalError) {
231232
String scheme = scheme( uri );
232-
List<Driver> selected = new ArrayList<>();
233-
for ( Driver d : ServiceLoader.load( Driver.class ) ) {
233+
List<Driver<SqlConnectOptions>> selected = new ArrayList<>();
234+
for ( Driver<SqlConnectOptions> d : ServiceLoader.load( Driver.class ) ) {
234235
String driverName = d.getClass().getCanonicalName();
235236
if ( matchesScheme( driverName, scheme ) ) {
236237
LOG.selectedDriver( driverName );

hibernate-reactive-core/src/test/java/org/hibernate/reactive/BaseReactiveTest.java

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import java.util.Collection;
99
import java.util.List;
10-
import java.util.concurrent.CompletableFuture;
1110
import java.util.concurrent.CompletionStage;
1211
import java.util.function.Supplier;
1312

@@ -29,6 +28,7 @@
2928
import org.hibernate.reactive.provider.service.ReactiveGenerationTarget;
3029
import org.hibernate.reactive.stage.Stage;
3130
import org.hibernate.reactive.testing.SessionFactoryManager;
31+
import org.hibernate.reactive.util.impl.CompletionStages;
3232
import org.hibernate.tool.schema.spi.SchemaManagementTool;
3333

3434
import org.junit.jupiter.api.AfterAll;
@@ -41,7 +41,6 @@
4141
import io.micrometer.core.instrument.Metrics;
4242
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
4343
import io.smallrye.mutiny.Uni;
44-
import io.vertx.core.Promise;
4544
import io.vertx.core.VertxOptions;
4645
import io.vertx.junit5.RunTestOnContext;
4746
import io.vertx.junit5.Timeout;
@@ -75,7 +74,7 @@ public abstract class BaseReactiveTest {
7574
* Configure Vertx JUnit5 test context
7675
*/
7776
@RegisterExtension
78-
static RunTestOnContext testOnContext = new RunTestOnContext( vertxOptions() );
77+
static RunTestOnContext testOnContext = new RunTestOnContext( vertxOptions(), false );
7978

8079
private static VertxOptions vertxOptions() {
8180
Metrics.addRegistry( new SimpleMeterRegistry() );
@@ -217,33 +216,19 @@ protected CompletionStage<Void> setupSessionFactory(Configuration configuration)
217216
* @return a {@link CompletionStage} void that succeeds when the factory is ready.
218217
*/
219218
protected CompletionStage<Void> setupSessionFactory(Supplier<Configuration> confSupplier) {
220-
CompletableFuture<Void> future = new CompletableFuture<>();
221-
testOnContext.vertx()
219+
return testOnContext.vertx()
222220
.executeBlocking(
223221
// schema generation is a blocking operation and so it causes an
224222
// exception when run on the Vert.x event loop. So call it using
225223
// Vertx.executeBlocking()
226-
promise -> startFactoryManager( promise, confSupplier ),
227-
event -> {
228-
if ( event.succeeded() ) {
229-
future.complete( null );
230-
}
231-
else {
232-
future.completeExceptionally( event.cause() );
233-
}
234-
}
235-
);
236-
return future;
237-
}
238-
239-
private void startFactoryManager(Promise<Object> p, Supplier<Configuration> confSupplier) {
240-
try {
241-
factoryManager.start( () -> createHibernateSessionFactory( confSupplier.get() ) );
242-
p.complete();
243-
}
244-
catch (Throwable e) {
245-
p.fail( e );
246-
}
224+
() -> startFactoryManager( confSupplier ),
225+
false
226+
).toCompletionStage().thenCompose( CompletionStages::voidFuture );
227+
}
228+
229+
private Object startFactoryManager(Supplier<Configuration> confSupplier) {
230+
factoryManager.start( () -> createHibernateSessionFactory( confSupplier.get() ) );
231+
return null;
247232
}
248233

249234
private SessionFactory createHibernateSessionFactory(Configuration configuration) {

0 commit comments

Comments
 (0)