Skip to content

Commit 4b1857b

Browse files
committed
[#2036] Upgrade Vert.x SQL client to 5.0.0.CR4
1 parent d9cd9bf commit 4b1857b

File tree

23 files changed

+87
-158
lines changed

23 files changed

+87
-158
lines changed

build.gradle

+1-1
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.12'
25+
vertxSqlClientVersion = '5.0.0.CR4'
2626
}
2727

2828
testcontainersVersion = '1.20.4'

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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+10-11
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
*/
66
package org.hibernate.reactive.id.impl;
77

8-
import io.vertx.core.Context;
9-
import io.vertx.core.Vertx;
10-
import io.vertx.core.net.impl.pool.CombinerExecutor;
11-
import io.vertx.core.net.impl.pool.Executor;
12-
import io.vertx.core.net.impl.pool.Task;
8+
import java.util.Objects;
9+
import java.util.concurrent.CompletableFuture;
10+
import java.util.concurrent.CompletionStage;
1311

1412
import org.hibernate.reactive.id.ReactiveIdentifierGenerator;
1513
import org.hibernate.reactive.session.ReactiveConnectionSupplier;
1614

17-
import java.util.Objects;
18-
import java.util.concurrent.CompletableFuture;
19-
import java.util.concurrent.CompletionStage;
15+
import io.vertx.core.Context;
16+
import io.vertx.core.Vertx;
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
@@ -138,7 +138,6 @@ public Task execute(GeneratorState state) {
138138
// value in the table, so just increment the lo
139139
// value and return the next id in the block
140140
completedFuture( local ).whenComplete( this::acceptAsReturnValue );
141-
return null;
142141
}
143142
else {
144143
nextHiValue( connectionSupplier )
@@ -155,8 +154,8 @@ public Task execute(GeneratorState state) {
155154
} );
156155
}
157156
} );
158-
return null;
159157
}
158+
return null;
160159
}
161160

162161
private void acceptAsReturnValue(final Long aLong, final Throwable throwable) {

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

+12-12
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,14 +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-
import static java.util.stream.Collectors.toList;
41-
4242
/**
4343
* A pool of reactive connections backed by a Vert.x {@link Pool}.
4444
* The {@code Pool} itself is backed by an instance of {@link Vertx}
@@ -190,7 +190,7 @@ protected Pool createPool(URI uri) {
190190
*
191191
* @return the new {@link Pool}
192192
*/
193-
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) {
194194
try {
195195
// First try to load the Pool using the standard ServiceLoader pattern
196196
// This only works if exactly 1 Driver is on the classpath.
@@ -199,8 +199,9 @@ protected Pool createPool(URI uri, SqlConnectOptions connectOptions, PoolOptions
199199
catch (ServiceConfigurationError e) {
200200
// Backup option if multiple drivers are on the classpath.
201201
// We will be able to remove this once Vertx 3.9.2 is available
202-
final Driver driver = findDriver( uri, e );
203-
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 );
204205
}
205206
}
206207

@@ -223,15 +224,14 @@ protected URI jdbcUrl(Map<?,?> configurationValues) {
223224
* so we need to disambiguate according to the scheme specified
224225
* in the given {@link URI}.
225226
*
226-
* @param uri the JDBC URL or database URI
227+
* @param uri the JDBC URL or database URI
227228
* @param originalError the error that was thrown
228-
*
229229
* @return the disambiguated {@link Driver}
230230
*/
231-
private Driver findDriver(URI uri, ServiceConfigurationError originalError) {
231+
private Driver<SqlConnectOptions> findDriver(URI uri, ServiceConfigurationError originalError) {
232232
String scheme = scheme( uri );
233-
List<Driver> selected = new ArrayList<>();
234-
for ( Driver d : ServiceLoader.load( Driver.class ) ) {
233+
List<Driver<SqlConnectOptions>> selected = new ArrayList<>();
234+
for ( Driver<SqlConnectOptions> d : ServiceLoader.load( Driver.class ) ) {
235235
String driverName = d.getClass().getCanonicalName();
236236
if ( matchesScheme( driverName, scheme ) ) {
237237
LOG.selectedDriver( driverName );
@@ -247,7 +247,7 @@ private Driver findDriver(URI uri, ServiceConfigurationError originalError) {
247247
if ( selected.size() > 1 ) {
248248
List<String> driverClasses = selected.stream()
249249
.map( driver -> driver.getClass().getCanonicalName() )
250-
.collect( toList() );
250+
.toList();
251251
throw new ConfigurationException( "Multiple drivers found matching for URI scheme \"" + scheme + "\". Please, pick one: " + driverClasses, originalError );
252252
}
253253
return selected.get( 0 );

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

+11-26
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

@@ -27,6 +26,7 @@
2726
import org.hibernate.reactive.provider.service.ReactiveGenerationTarget;
2827
import org.hibernate.reactive.stage.Stage;
2928
import org.hibernate.reactive.testing.SessionFactoryManager;
29+
import org.hibernate.reactive.util.impl.CompletionStages;
3030
import org.hibernate.tool.schema.spi.SchemaManagementTool;
3131

3232
import org.junit.jupiter.api.AfterAll;
@@ -39,7 +39,6 @@
3939
import io.micrometer.core.instrument.Metrics;
4040
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
4141
import io.smallrye.mutiny.Uni;
42-
import io.vertx.core.Promise;
4342
import io.vertx.core.VertxOptions;
4443
import io.vertx.junit5.RunTestOnContext;
4544
import io.vertx.junit5.Timeout;
@@ -73,7 +72,7 @@ public abstract class BaseReactiveTest {
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
Metrics.addRegistry( new SimpleMeterRegistry() );
@@ -205,33 +204,19 @@ protected CompletionStage<Void> setupSessionFactory(Configuration configuration)
205204
* @return a {@link CompletionStage} void that succeeds when the factory is ready.
206205
*/
207206
protected CompletionStage<Void> setupSessionFactory(Supplier<Configuration> confSupplier) {
208-
CompletableFuture<Void> future = new CompletableFuture<>();
209-
testOnContext.vertx()
207+
return testOnContext.vertx()
210208
.executeBlocking(
211209
// schema generation is a blocking operation and so it causes an
212210
// exception when run on the Vert.x event loop. So call it using
213211
// Vertx.executeBlocking()
214-
promise -> startFactoryManager( promise, confSupplier ),
215-
event -> {
216-
if ( event.succeeded() ) {
217-
future.complete( null );
218-
}
219-
else {
220-
future.completeExceptionally( event.cause() );
221-
}
222-
}
223-
);
224-
return future;
225-
}
226-
227-
private void startFactoryManager(Promise<Object> p, Supplier<Configuration> confSupplier) {
228-
try {
229-
factoryManager.start( () -> createHibernateSessionFactory( confSupplier.get() ) );
230-
p.complete();
231-
}
232-
catch (Throwable e) {
233-
p.fail( e );
234-
}
212+
() -> startFactoryManager( confSupplier ),
213+
false
214+
).toCompletionStage().thenCompose( CompletionStages::voidFuture );
215+
}
216+
217+
private Object startFactoryManager(Supplier<Configuration> confSupplier) {
218+
factoryManager.start( () -> createHibernateSessionFactory( confSupplier.get() ) );
219+
return null;
235220
}
236221

237222
private SessionFactory createHibernateSessionFactory(Configuration configuration) {

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

+12-26
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

+1-1
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}"

0 commit comments

Comments
 (0)