Skip to content

Commit

Permalink
[hibernate#754] Allow multitenancy without needing access to ThreadLo…
Browse files Browse the repository at this point in the history
…calPoolManager
  • Loading branch information
DavideD committed May 14, 2021
1 parent 134fca9 commit 7482fb3
Showing 1 changed file with 27 additions and 14 deletions.
Expand Up @@ -104,6 +104,21 @@ protected ThreadLocalPoolManager createPools(URI uri) {
return createPools( uri, configuration.connectOptions( uri ), configuration.poolOptions(), vertx.getVertx() );
}

/**
* Create a new {@link ThreadLocalPoolManager} for the given JDBC URL or database URI,
* connection pool options, and the given instance of {@link Vertx}.
*
* @param uri JDBC URL or database URI
* @param connectOptions the connection options
* @param poolOptions the connection pooling options
* @param vertx the instance of {@link Vertx} to be used by the pool
*
* @return the new {@link ThreadLocalPoolManager}
*/
protected ThreadLocalPoolManager createPools(URI uri, SqlConnectOptions connectOptions, PoolOptions poolOptions, Vertx vertx) {
return new ThreadLocalPoolManager( () -> createPool( uri, connectOptions, poolOptions, vertx ) );
}

/**
* Create a new {@link Pool} for the given JDBC URL or database URI,
* connection pool options, and the given instance of {@link Vertx}.
Expand All @@ -115,20 +130,18 @@ protected ThreadLocalPoolManager createPools(URI uri) {
*
* @return the new {@link Pool}
*/
protected ThreadLocalPoolManager createPools(URI uri, SqlConnectOptions connectOptions, PoolOptions poolOptions, Vertx vertx) {
return new ThreadLocalPoolManager( () -> {
try {
// First try to load the Pool using the standard ServiceLoader pattern
// This only works if exactly 1 Driver is on the classpath.
return Pool.pool( vertx, connectOptions, poolOptions );
}
catch (ServiceConfigurationError e) {
// Backup option if multiple drivers are on the classpath.
// We will be able to remove this once Vertx 3.9.2 is available
final Driver driver = findDriver( uri, e );
return driver.createPool( vertx, connectOptions, poolOptions );
}
});
protected Pool createPool(URI uri, SqlConnectOptions connectOptions, PoolOptions poolOptions, Vertx vertx) {
try {
// First try to load the Pool using the standard ServiceLoader pattern
// This only works if exactly 1 Driver is on the classpath.
return Pool.pool( vertx, connectOptions, poolOptions );
}
catch (ServiceConfigurationError e) {
// Backup option if multiple drivers are on the classpath.
// We will be able to remove this once Vertx 3.9.2 is available
final Driver driver = findDriver( uri, e );
return driver.createPool( vertx, connectOptions, poolOptions );
}
}

/**
Expand Down

0 comments on commit 7482fb3

Please sign in to comment.