13
13
import java .util .ServiceConfigurationError ;
14
14
import java .util .ServiceLoader ;
15
15
import java .util .concurrent .CompletionStage ;
16
+ import java .util .function .Supplier ;
16
17
17
18
import org .hibernate .engine .jdbc .spi .JdbcServices ;
18
19
import org .hibernate .engine .jdbc .spi .SqlExceptionHelper ;
31
32
32
33
import io .vertx .core .Future ;
33
34
import io .vertx .core .Vertx ;
35
+ import io .vertx .core .net .NetClientOptions ;
34
36
import io .vertx .sqlclient .Pool ;
35
37
import io .vertx .sqlclient .PoolOptions ;
36
38
import io .vertx .sqlclient .SqlConnectOptions ;
39
+ import io .vertx .sqlclient .impl .Utils ;
37
40
import io .vertx .sqlclient .spi .Driver ;
38
41
39
- import static java .util .Collections .singletonList ;
40
-
41
42
/**
42
43
* A pool of reactive connections backed by a Vert.x {@link Pool}.
43
44
* The {@code Pool} itself is backed by an instance of {@link Vertx}
@@ -189,7 +190,7 @@ protected Pool createPool(URI uri) {
189
190
*
190
191
* @return the new {@link Pool}
191
192
*/
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 ) {
193
194
try {
194
195
// First try to load the Pool using the standard ServiceLoader pattern
195
196
// This only works if exactly 1 Driver is on the classpath.
@@ -198,8 +199,9 @@ protected Pool createPool(URI uri, SqlConnectOptions connectOptions, PoolOptions
198
199
catch (ServiceConfigurationError e ) {
199
200
// Backup option if multiple drivers are on the classpath.
200
201
// 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 );
203
205
}
204
206
}
205
207
@@ -222,15 +224,14 @@ protected URI jdbcUrl(Map<?,?> configurationValues) {
222
224
* so we need to disambiguate according to the scheme specified
223
225
* in the given {@link URI}.
224
226
*
225
- * @param uri the JDBC URL or database URI
227
+ * @param uri the JDBC URL or database URI
226
228
* @param originalError the error that was thrown
227
- *
228
229
* @return the disambiguated {@link Driver}
229
230
*/
230
- private Driver findDriver (URI uri , ServiceConfigurationError originalError ) {
231
+ private Driver < SqlConnectOptions > findDriver (URI uri , ServiceConfigurationError originalError ) {
231
232
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 ) ) {
234
235
String driverName = d .getClass ().getCanonicalName ();
235
236
if ( matchesScheme ( driverName , scheme ) ) {
236
237
LOG .selectedDriver ( driverName );
0 commit comments