|
7 | 7 |
|
8 | 8 | import java.lang.invoke.MethodHandles;
|
9 | 9 | import java.net.URI;
|
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.List; |
10 | 12 | import java.util.Map;
|
11 | 13 | import java.util.ServiceConfigurationError;
|
12 | 14 | import java.util.ServiceLoader;
|
|
37 | 39 | import io.vertx.sqlclient.spi.Driver;
|
38 | 40 |
|
39 | 41 | import static java.util.Collections.singletonList;
|
| 42 | +import static java.util.stream.Collectors.toList; |
40 | 43 |
|
41 | 44 | /**
|
42 | 45 | * A pool of reactive connections backed by a Vert.x {@link Pool}.
|
@@ -227,14 +230,27 @@ protected URI jdbcUrl(Map<?,?> configurationValues) {
|
227 | 230 | */
|
228 | 231 | private Driver findDriver(URI uri, ServiceConfigurationError originalError) {
|
229 | 232 | String scheme = scheme( uri );
|
| 233 | + List<Driver> selected = new ArrayList<>(); |
230 | 234 | for ( Driver d : ServiceLoader.load( Driver.class ) ) {
|
231 | 235 | String driverName = d.getClass().getCanonicalName();
|
232 |
| - LOG.detectedDriver( driverName ); |
233 | 236 | if ( matchesScheme( driverName, scheme ) ) {
|
234 |
| - return d; |
| 237 | + LOG.detectedDriver( driverName, "✓" ); |
| 238 | + selected.add( d ); |
235 | 239 | }
|
| 240 | + else { |
| 241 | + LOG.detectedDriver( driverName, "" ); |
| 242 | + } |
| 243 | + } |
| 244 | + if ( selected.isEmpty() ) { |
| 245 | + throw new ConfigurationException( "No suitable drivers found for URI scheme: " + scheme, originalError ); |
| 246 | + } |
| 247 | + if ( selected.size() > 1 ) { |
| 248 | + List<String> driverClasses = selected.stream() |
| 249 | + .map( driver -> driver.getClass().getCanonicalName() ) |
| 250 | + .collect( toList() ); |
| 251 | + throw new ConfigurationException( "Multiple drivers found matching for URI scheme \"" + scheme + "\". Please, pick one: " + driverClasses, originalError ); |
236 | 252 | }
|
237 |
| - throw new ConfigurationException( "No suitable drivers found for URI scheme: " + scheme, originalError ); |
| 253 | + return selected.get( 0 ); |
238 | 254 | }
|
239 | 255 |
|
240 | 256 | private String scheme(URI uri) {
|
|
0 commit comments