Skip to content

Commit fa5e269

Browse files
committed
WIP - Try to remove what gets in the way of Hibernate Reactive checking the DB version
1 parent 5be7611 commit fa5e269

File tree

5 files changed

+68
-36
lines changed

5 files changed

+68
-36
lines changed

extensions/hibernate-reactive/runtime/src/main/java/io/quarkus/hibernate/reactive/runtime/FastBootHibernateReactivePersistenceProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ private EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String
179179
}
180180
}
181181

182+
// Allow detection of driver/database capabilities on runtime init (was disabled during static init)
183+
runtimeSettingsBuilder.put("hibernate.boot.allow_jdbc_metadata_access", "true");
184+
182185
if (!puConfig.unsupportedProperties().isEmpty()) {
183186
log.warnf("Persistence-unit [%s] sets unsupported properties."
184187
+ " These properties may not work correctly, and even if they do,"

extensions/hibernate-reactive/runtime/src/main/java/io/quarkus/hibernate/reactive/runtime/boot/registry/PreconfiguredReactiveServiceRegistryBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.hibernate.reactive.engine.jdbc.mutation.internal.ReactiveMutationExecutorServiceInitiator;
2525
import org.hibernate.reactive.loader.ast.internal.ReactiveBatchLoaderFactoryInitiator;
2626
import org.hibernate.reactive.provider.service.NativeParametersHandling;
27+
import org.hibernate.reactive.provider.service.NoJdbcEnvironmentInitiator;
2728
import org.hibernate.reactive.provider.service.NoJtaPlatformInitiator;
2829
import org.hibernate.reactive.provider.service.ReactiveMarkerServiceInitiator;
2930
import org.hibernate.reactive.provider.service.ReactivePersisterClassResolverInitiator;
@@ -53,7 +54,6 @@
5354
import io.quarkus.hibernate.orm.runtime.service.bytecodeprovider.QuarkusRuntimeBytecodeProviderInitiator;
5455
import io.quarkus.hibernate.reactive.runtime.customized.CheckingVertxContextInitiator;
5556
import io.quarkus.hibernate.reactive.runtime.customized.QuarkusNoJdbcConnectionProviderInitiator;
56-
import io.quarkus.hibernate.reactive.runtime.customized.QuarkusNoJdbcEnvironmentInitiator;
5757

5858
/**
5959
* Helps to instantiate a ServiceRegistryBuilder from a previous state. This
@@ -189,8 +189,7 @@ private static List<StandardServiceInitiator<?>> buildQuarkusServiceInitiatorLis
189189
// TODO disable?
190190
serviceInitiators.add(SchemaManagementToolInitiator.INSTANCE);
191191

192-
// Replaces JdbcEnvironmentInitiator.INSTANCE :
193-
serviceInitiators.add(new QuarkusNoJdbcEnvironmentInitiator(rs.getDialect()));
192+
serviceInitiators.add(NoJdbcEnvironmentInitiator.INSTANCE);
194193

195194
// Custom one!
196195
serviceInitiators.add(QuarkusJndiServiceInitiator.INSTANCE);

extensions/hibernate-reactive/runtime/src/main/java/io/quarkus/hibernate/reactive/runtime/customized/QuarkusNoJdbcEnvironmentInitiator.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

extensions/hibernate-reactive/runtime/src/main/java/io/quarkus/hibernate/reactive/runtime/customized/QuarkusReactiveConnectionPoolInitiator.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import java.util.Map;
44

55
import org.hibernate.boot.registry.StandardServiceInitiator;
6-
import org.hibernate.engine.jdbc.spi.JdbcServices;
76
import org.hibernate.reactive.pool.ReactiveConnectionPool;
8-
import org.hibernate.reactive.pool.impl.ExternalSqlClientPool;
97
import org.hibernate.service.spi.ServiceRegistryImplementor;
108

119
import io.quarkus.hibernate.orm.runtime.migration.MultiTenancyStrategy;
@@ -33,8 +31,7 @@ public ReactiveConnectionPool initiateService(Map configurationValues, ServiceRe
3331
// nothing to do, but given the separate hierarchies have to handle this here.
3432
return null;
3533
}
36-
final JdbcServices jdbcService = registry.getService(JdbcServices.class);
37-
return new ExternalSqlClientPool(pool, jdbcService.getSqlStatementLogger(), jdbcService.getSqlExceptionHelper());
34+
return new QuarkusSqlClientPool(pool);
3835
}
3936

4037
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package io.quarkus.hibernate.reactive.runtime.customized;
2+
3+
import java.util.concurrent.CompletionStage;
4+
5+
import org.hibernate.engine.jdbc.spi.JdbcServices;
6+
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
7+
import org.hibernate.engine.jdbc.spi.SqlStatementLogger;
8+
import org.hibernate.reactive.pool.impl.SqlClientPool;
9+
import org.hibernate.reactive.util.impl.CompletionStages;
10+
import org.hibernate.service.spi.ServiceRegistryAwareService;
11+
import org.hibernate.service.spi.ServiceRegistryImplementor;
12+
13+
import io.vertx.sqlclient.Pool;
14+
15+
/**
16+
* An alternative implementation of {@link org.hibernate.reactive.pool.impl.ExternalSqlClientPool}
17+
* which retrieves SQL loggers / exception handlers lazily,
18+
* to avoid a circular dependency JdbcEnvironment => pool => JdbcServices => JdbcEnvironment.
19+
*/
20+
public class QuarkusSqlClientPool extends SqlClientPool
21+
implements ServiceRegistryAwareService {
22+
23+
private final Pool pool;
24+
private SqlStatementLogger sqlStatementLogger;
25+
private SqlExceptionHelper sqlExceptionHelper;
26+
private ServiceRegistryImplementor serviceRegistry;
27+
28+
public QuarkusSqlClientPool(Pool pool) {
29+
this.pool = pool;
30+
}
31+
32+
@Override
33+
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
34+
this.serviceRegistry = serviceRegistry;
35+
this.sqlStatementLogger = serviceRegistry.getService(SqlStatementLogger.class);
36+
}
37+
38+
@Override
39+
protected Pool getPool() {
40+
return pool;
41+
}
42+
43+
@Override
44+
protected SqlStatementLogger getSqlStatementLogger() {
45+
return sqlStatementLogger;
46+
}
47+
48+
@Override
49+
public SqlExceptionHelper getSqlExceptionHelper() {
50+
if (sqlExceptionHelper == null) {
51+
sqlExceptionHelper = serviceRegistry
52+
.getService(JdbcServices.class).getSqlExceptionHelper();
53+
}
54+
return sqlExceptionHelper;
55+
}
56+
57+
@Override
58+
public CompletionStage<Void> getCloseFuture() {
59+
// Closing is handled by Quarkus.
60+
return CompletionStages.voidFuture();
61+
}
62+
}

0 commit comments

Comments
 (0)