Skip to content

Commit

Permalink
For now remove the generic pool creation with list as all implementat…
Browse files Browse the repository at this point in the history
…ion may not support it
  • Loading branch information
vietj committed Jul 1, 2021
1 parent 413ea3f commit d3bda95
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public void tracing01(SqlConnectOptions options) {
}

public void poolConfig01(SqlConnectOptions server1, SqlConnectOptions server2, SqlConnectOptions server3, PoolOptions options) {
Pool pool = Pool.pool(Arrays.asList(server1, server2, server3), options);
// Not generic
}

public void poolConfig02(Pool pool, String sql) {
Expand Down
40 changes: 7 additions & 33 deletions vertx-sql-client/src/main/java/io/vertx/sqlclient/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,19 @@ static Pool pool(SqlConnectOptions connectOptions) {
/**
* Like {@link #pool(Vertx, SqlConnectOptions, PoolOptions)} with a Vert.x instance created automatically.
*/
static Pool pool(SqlConnectOptions connectOptions, PoolOptions poolOptions) {
return pool(Collections.singletonList(connectOptions), poolOptions);
}

/**
* Like {@link #pool(Vertx, List, PoolOptions)} with a Vert.x instance created automatically.
*/
static Pool pool(List<SqlConnectOptions> databases, PoolOptions options) {
SqlConnectOptions connectOptions = databases.get(0);
static Pool pool(SqlConnectOptions database, PoolOptions options) {
List<Driver> candidates = new ArrayList<>(1);
for (Driver d : ServiceLoader.load(Driver.class)) {
if (d.acceptsOptions(connectOptions)) {
if (d.acceptsOptions(database)) {
candidates.add(d);
}
}
if (candidates.size() == 0) {
throw new ServiceConfigurationError("No implementations of " + Driver.class + " found that accept connection options " + connectOptions);
throw new ServiceConfigurationError("No implementations of " + Driver.class + " found that accept connection options " + database);
} else if (candidates.size() > 1) {
throw new ServiceConfigurationError("Multiple implementations of " + Driver.class + " found: " + candidates);
} else {
return candidates.get(0).createPool(null, databases, options);
return candidates.get(0).createPool(null, Collections.singletonList(database), options);
}
}

Expand All @@ -91,36 +83,18 @@ static Pool pool(List<SqlConnectOptions> databases, PoolOptions options) {
* @throws ServiceConfigurationError if no compatible drivers are found, or if multiple compatible drivers are found
*/
static Pool pool(Vertx vertx, SqlConnectOptions database, PoolOptions options) {
return pool(vertx, Collections.singletonList(database), options);
}

/**
* Create a connection pool to the {@code database} with round-robin selection.
* Round-robin is applied when a new connection is created by the pool.
*
* <p> A {@link Driver} will be selected among the drivers found on the classpath returning
* {@code true} when {@link Driver#acceptsOptions(SqlConnectOptions)} applied to the first options
* of the list.
*
* @param databases the list of databases
* @param options the options for creating the pool
* @return the connection pool
* @throws ServiceConfigurationError if no compatible drivers are found, or if multiple compatible drivers are found
*/
static Pool pool(Vertx vertx, List<SqlConnectOptions> databases, PoolOptions options) {
SqlConnectOptions connectOptions = databases.get(0);
List<Driver> candidates = new ArrayList<>(1);
for (Driver d : ServiceLoader.load(Driver.class)) {
if (d.acceptsOptions(connectOptions)) {
if (d.acceptsOptions(database)) {
candidates.add(d);
}
}
if (candidates.size() == 0) {
throw new ServiceConfigurationError("No implementations of " + Driver.class + " found that accept connection options " + connectOptions);
throw new ServiceConfigurationError("No implementations of " + Driver.class + " found that accept connection options " + database);
} else if (candidates.size() > 1) {
throw new ServiceConfigurationError("Multiple implementations of " + Driver.class + " found: " + candidates);
} else {
return candidates.get(0).createPool(vertx, databases, options);
return candidates.get(0).createPool(vertx, Collections.singletonList(database), options);
}
}

Expand Down

0 comments on commit d3bda95

Please sign in to comment.