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
- import static java .util .stream .Collectors .toList ;
41
-
42
42
/**
43
43
* A pool of reactive connections backed by a Vert.x {@link Pool}.
44
44
* The {@code Pool} itself is backed by an instance of {@link Vertx}
@@ -190,7 +190,7 @@ protected Pool createPool(URI uri) {
190
190
*
191
191
* @return the new {@link Pool}
192
192
*/
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 ) {
194
194
try {
195
195
// First try to load the Pool using the standard ServiceLoader pattern
196
196
// This only works if exactly 1 Driver is on the classpath.
@@ -199,8 +199,9 @@ protected Pool createPool(URI uri, SqlConnectOptions connectOptions, PoolOptions
199
199
catch (ServiceConfigurationError e ) {
200
200
// Backup option if multiple drivers are on the classpath.
201
201
// 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 );
204
205
}
205
206
}
206
207
@@ -223,15 +224,14 @@ protected URI jdbcUrl(Map<?,?> configurationValues) {
223
224
* so we need to disambiguate according to the scheme specified
224
225
* in the given {@link URI}.
225
226
*
226
- * @param uri the JDBC URL or database URI
227
+ * @param uri the JDBC URL or database URI
227
228
* @param originalError the error that was thrown
228
- *
229
229
* @return the disambiguated {@link Driver}
230
230
*/
231
- private Driver findDriver (URI uri , ServiceConfigurationError originalError ) {
231
+ private Driver < SqlConnectOptions > findDriver (URI uri , ServiceConfigurationError originalError ) {
232
232
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 ) ) {
235
235
String driverName = d .getClass ().getCanonicalName ();
236
236
if ( matchesScheme ( driverName , scheme ) ) {
237
237
LOG .selectedDriver ( driverName );
@@ -247,7 +247,7 @@ private Driver findDriver(URI uri, ServiceConfigurationError originalError) {
247
247
if ( selected .size () > 1 ) {
248
248
List <String > driverClasses = selected .stream ()
249
249
.map ( driver -> driver .getClass ().getCanonicalName () )
250
- .collect ( toList () );
250
+ .toList ();
251
251
throw new ConfigurationException ( "Multiple drivers found matching for URI scheme \" " + scheme + "\" . Please, pick one: " + driverClasses , originalError );
252
252
}
253
253
return selected .get ( 0 );
0 commit comments