1313import java .util .ServiceConfigurationError ;
1414import java .util .ServiceLoader ;
1515import java .util .concurrent .CompletionStage ;
16+ import java .util .function .Supplier ;
1617
1718import org .hibernate .engine .jdbc .spi .JdbcServices ;
1819import org .hibernate .engine .jdbc .spi .SqlExceptionHelper ;
3132
3233import io .vertx .core .Future ;
3334import io .vertx .core .Vertx ;
35+ import io .vertx .core .net .NetClientOptions ;
3436import io .vertx .sqlclient .Pool ;
3537import io .vertx .sqlclient .PoolOptions ;
3638import io .vertx .sqlclient .SqlConnectOptions ;
39+ import io .vertx .sqlclient .impl .Utils ;
3740import 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 );
0 commit comments