Skip to content

Commit 7dbe887

Browse files
committed
[#2036] Upgrade Vert.x SQL client to 5.0.0.CR4
1 parent 9917783 commit 7dbe887

File tree

23 files changed

+80
-149
lines changed

23 files changed

+80
-149
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ext {
2222
// Example:
2323
// ./gradlew build -PvertxSqlClientVersion=4.0.0-SNAPSHOT
2424
if ( !project.hasProperty( 'vertxSqlClientVersion' ) ) {
25-
vertxSqlClientVersion = '4.5.13'
25+
vertxSqlClientVersion = '5.0.0.CR4'
2626
}
2727

2828
testcontainersVersion = '1.20.4'

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

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: 1 addition & 1 deletion
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;

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() );
@@ -209,33 +208,19 @@ protected CompletionStage<Void> setupSessionFactory(Configuration configuration)
209208
* @return a {@link CompletionStage} void that succeeds when the factory is ready.
210209
*/
211210
protected CompletionStage<Void> setupSessionFactory(Supplier<Configuration> confSupplier) {
212-
CompletableFuture<Void> future = new CompletableFuture<>();
213-
testOnContext.vertx()
211+
return testOnContext.vertx()
214212
.executeBlocking(
215213
// schema generation is a blocking operation and so it causes an
216214
// exception when run on the Vert.x event loop. So call it using
217215
// Vertx.executeBlocking()
218-
promise -> startFactoryManager( promise, confSupplier ),
219-
event -> {
220-
if ( event.succeeded() ) {
221-
future.complete( null );
222-
}
223-
else {
224-
future.completeExceptionally( event.cause() );
225-
}
226-
}
227-
);
228-
return future;
229-
}
230-
231-
private void startFactoryManager(Promise<Object> p, Supplier<Configuration> confSupplier) {
232-
try {
233-
factoryManager.start( () -> createHibernateSessionFactory( confSupplier.get() ) );
234-
p.complete();
235-
}
236-
catch (Throwable e) {
237-
p.fail( e );
238-
}
216+
() -> startFactoryManager( confSupplier ),
217+
false
218+
).toCompletionStage().thenCompose( CompletionStages::voidFuture );
219+
}
220+
221+
private Object startFactoryManager(Supplier<Configuration> confSupplier) {
222+
factoryManager.start( () -> createHibernateSessionFactory( confSupplier.get() ) );
223+
return null;
239224
}
240225

241226
private SessionFactory createHibernateSessionFactory(Configuration configuration) {

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

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

88
import java.net.URI;
99
import java.util.Map;
10-
import java.util.function.Function;
1110
import java.util.stream.Collectors;
1211

1312
import org.hibernate.reactive.MyCurrentTenantIdentifierResolver.Tenant;
1413
import org.hibernate.reactive.pool.impl.DefaultSqlClientPool;
1514

16-
import io.vertx.core.AsyncResult;
17-
import io.vertx.core.Context;
1815
import io.vertx.core.Future;
19-
import io.vertx.core.Handler;
2016
import io.vertx.core.Vertx;
2117
import io.vertx.sqlclient.Pool;
2218
import io.vertx.sqlclient.PoolOptions;
@@ -58,8 +54,18 @@ protected Pool createPool(URI uri, SqlConnectOptions connectOptions, PoolOptions
5854
return pools;
5955
}
6056

61-
private Pool createPool(URI uri, SqlConnectOptions connectOptions, PoolOptions poolOptions, Vertx vertx, Tenant tenant) {
62-
return super.createPool( changeDbName( uri, tenant ), changeDbName( connectOptions, tenant ), poolOptions, vertx );
57+
private Pool createPool(
58+
URI uri,
59+
SqlConnectOptions connectOptions,
60+
PoolOptions poolOptions,
61+
Vertx vertx,
62+
Tenant tenant) {
63+
return super.createPool(
64+
changeDbName( uri, tenant ),
65+
changeDbName( connectOptions, tenant ),
66+
poolOptions,
67+
vertx
68+
);
6369
}
6470

6571
/**
@@ -100,11 +106,6 @@ public Pool getTenantPool(Tenant tenantId) {
100106
return poolMap.get( tenantId );
101107
}
102108

103-
@Override
104-
public void getConnection(Handler<AsyncResult<SqlConnection>> handler) {
105-
poolMap.get( defaultTenantId ).getConnection( handler );
106-
}
107-
108109
@Override
109110
public Future<SqlConnection> getConnection() {
110111
return poolMap.get( defaultTenantId ).getConnection();
@@ -125,21 +126,6 @@ public PreparedQuery<RowSet<Row>> preparedQuery(String sql, PrepareOptions optio
125126
return poolMap.get( defaultTenantId ).preparedQuery( sql, options );
126127
}
127128

128-
@Override
129-
public void close(Handler<AsyncResult<Void>> handler) {
130-
poolMap.forEach( (tenant, pool) -> pool.close( handler ) );
131-
}
132-
133-
@Override
134-
public Pool connectHandler(Handler<SqlConnection> handler) {
135-
return poolMap.get( defaultTenantId ).connectHandler( handler );
136-
}
137-
138-
@Override
139-
public Pool connectionProvider(Function<Context, Future<SqlConnection>> provider) {
140-
return poolMap.get( defaultTenantId ).connectionProvider( provider );
141-
}
142-
143129
@Override
144130
public int size() {
145131
return poolMap.get( defaultTenantId ).size();

integration-tests/bytecode-enhancements-it/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies {
3030
runtimeOnly "io.vertx:vertx-pg-client:${vertxSqlClientVersion}"
3131

3232
// Allow authentication to PostgreSQL using SCRAM:
33-
runtimeOnly 'com.ongres.scram:client:2.1'
33+
runtimeOnly 'com.ongres.scram:scram-client:3.1'
3434

3535
// logging
3636
runtimeOnly "org.apache.logging.log4j:log4j-core:${log4jVersion}"

integration-tests/bytecode-enhancements-it/src/test/java/org/hibernate/reactive/it/BaseReactiveIT.java

Lines changed: 9 additions & 24 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.concurrent.TimeUnit;
1312
import java.util.function.Supplier;
@@ -20,6 +19,7 @@
2019
import org.hibernate.reactive.provider.ReactiveServiceRegistryBuilder;
2120
import org.hibernate.reactive.provider.Settings;
2221
import org.hibernate.reactive.stage.Stage;
22+
import org.hibernate.reactive.util.impl.CompletionStages;
2323

2424
import org.junit.jupiter.api.AfterAll;
2525
import org.junit.jupiter.api.AfterEach;
@@ -29,7 +29,6 @@
2929
import org.junit.jupiter.api.extension.RegisterExtension;
3030

3131
import io.smallrye.mutiny.Uni;
32-
import io.vertx.core.Promise;
3332
import io.vertx.core.VertxOptions;
3433
import io.vertx.junit5.RunTestOnContext;
3534
import io.vertx.junit5.VertxExtension;
@@ -73,7 +72,7 @@ public abstract class BaseReactiveIT {
7372
* Configure Vertx JUnit5 test context
7473
*/
7574
@RegisterExtension
76-
static RunTestOnContext testOnContext = new RunTestOnContext( vertxOptions() );
75+
static RunTestOnContext testOnContext = new RunTestOnContext( vertxOptions(), false );
7776

7877
private static VertxOptions vertxOptions() {
7978
return new VertxOptions()
@@ -202,33 +201,19 @@ protected CompletionStage<Void> setupSessionFactory(Configuration configuration)
202201
* @return a {@link CompletionStage} void that succeeds when the factory is ready.
203202
*/
204203
protected CompletionStage<Void> setupSessionFactory(Supplier<Configuration> confSupplier) {
205-
CompletableFuture<Void> future = new CompletableFuture<>();
206-
testOnContext.vertx()
204+
return testOnContext.vertx()
207205
.executeBlocking(
208206
// schema generation is a blocking operation and so it causes an
209207
// exception when run on the Vert.x event loop. So call it using
210208
// Vertx.executeBlocking()
211-
promise -> startFactoryManager( promise, confSupplier ),
212-
event -> {
213-
if ( event.succeeded() ) {
214-
future.complete( null );
215-
}
216-
else {
217-
future.completeExceptionally( event.cause() );
218-
}
219-
}
220-
);
221-
return future;
209+
() -> startFactoryManager( confSupplier ),
210+
true
211+
).toCompletionStage().thenCompose( CompletionStages::voidFuture );
222212
}
223213

224-
private void startFactoryManager(Promise<Object> p, Supplier<Configuration> confSupplier) {
225-
try {
226-
ormSessionFactory = createHibernateSessionFactory( confSupplier.get() );
227-
p.complete();
228-
}
229-
catch (Throwable e) {
230-
p.fail( e );
231-
}
214+
private Object startFactoryManager(Supplier<Configuration> confSupplier) {
215+
ormSessionFactory = createHibernateSessionFactory( confSupplier.get() );
216+
return null;
232217
}
233218

234219
private SessionFactory createHibernateSessionFactory(Configuration configuration) {

integration-tests/hibernate-validator-postgres-it/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232
runtimeOnly "io.vertx:vertx-pg-client:${vertxSqlClientVersion}"
3333

3434
// Allow authentication to PostgreSQL using SCRAM:
35-
runtimeOnly 'com.ongres.scram:client:2.1'
35+
runtimeOnly 'com.ongres.scram:scram-client:3.1'
3636

3737
// logging
3838
runtimeOnly "org.apache.logging.log4j:log4j-core:${log4jVersion}"

0 commit comments

Comments
 (0)