report the name of the ConnectionProvider along with the other info
This commit is contained in:
parent
879dca2a08
commit
2487390615
|
@ -167,6 +167,7 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl
|
||||||
agroalDataSource.getConfiguration().connectionPoolConfiguration();
|
agroalDataSource.getConfiguration().connectionPoolConfiguration();
|
||||||
final AgroalConnectionFactoryConfiguration acfc = acpc.connectionFactoryConfiguration();
|
final AgroalConnectionFactoryConfiguration acfc = acpc.connectionFactoryConfiguration();
|
||||||
return new DatabaseConnectionInfoImpl(
|
return new DatabaseConnectionInfoImpl(
|
||||||
|
AgroalConnectionProvider.class,
|
||||||
acfc.jdbcUrl(),
|
acfc.jdbcUrl(),
|
||||||
// Attempt to resolve the driver name from the dialect,
|
// Attempt to resolve the driver name from the dialect,
|
||||||
// in case it wasn't explicitly set and access to the
|
// in case it wasn't explicitly set and access to the
|
||||||
|
|
|
@ -152,6 +152,7 @@ public class C3P0ConnectionProvider
|
||||||
dataSource = createDataSource( jdbcUrl, connectionProps, poolSettings );
|
dataSource = createDataSource( jdbcUrl, connectionProps, poolSettings );
|
||||||
|
|
||||||
dbInfoProducer = dialect -> new DatabaseConnectionInfoImpl(
|
dbInfoProducer = dialect -> new DatabaseConnectionInfoImpl(
|
||||||
|
C3P0ConnectionProvider.class,
|
||||||
jdbcUrl,
|
jdbcUrl,
|
||||||
jdbcDriverClass,
|
jdbcDriverClass,
|
||||||
dialect.getVersion(),
|
dialect.getVersion(),
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.util.Map;
|
||||||
import org.hibernate.cfg.JdbcSettings;
|
import org.hibernate.cfg.JdbcSettings;
|
||||||
import org.hibernate.dialect.DatabaseVersion;
|
import org.hibernate.dialect.DatabaseVersion;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.internal.util.NullnessHelper;
|
import org.hibernate.internal.util.NullnessHelper;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
@ -27,6 +28,7 @@ import static org.hibernate.internal.util.StringHelper.nullIfEmpty;
|
||||||
public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
|
public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
|
||||||
public static final String DEFAULT = "undefined/unknown";
|
public static final String DEFAULT = "undefined/unknown";
|
||||||
|
|
||||||
|
private final Class<?> connectionProviderClass;
|
||||||
protected final String jdbcUrl;
|
protected final String jdbcUrl;
|
||||||
protected final String jdbcDriver;
|
protected final String jdbcDriver;
|
||||||
protected final DatabaseVersion dialectVersion;
|
protected final DatabaseVersion dialectVersion;
|
||||||
|
@ -36,6 +38,7 @@ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
|
||||||
protected final Integer poolMaxSize;
|
protected final Integer poolMaxSize;
|
||||||
|
|
||||||
public DatabaseConnectionInfoImpl(
|
public DatabaseConnectionInfoImpl(
|
||||||
|
Class<? extends ConnectionProvider> connectionProviderClass,
|
||||||
String jdbcUrl,
|
String jdbcUrl,
|
||||||
String jdbcDriver,
|
String jdbcDriver,
|
||||||
DatabaseVersion dialectVersion,
|
DatabaseVersion dialectVersion,
|
||||||
|
@ -43,6 +46,7 @@ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
|
||||||
String isolationLevel,
|
String isolationLevel,
|
||||||
Integer poolMinSize,
|
Integer poolMinSize,
|
||||||
Integer poolMaxSize) {
|
Integer poolMaxSize) {
|
||||||
|
this.connectionProviderClass = connectionProviderClass;
|
||||||
this.jdbcUrl = nullIfEmpty( jdbcUrl );
|
this.jdbcUrl = nullIfEmpty( jdbcUrl );
|
||||||
this.jdbcDriver = nullIfEmpty( jdbcDriver );
|
this.jdbcDriver = nullIfEmpty( jdbcDriver );
|
||||||
this.dialectVersion = dialectVersion;
|
this.dialectVersion = dialectVersion;
|
||||||
|
@ -54,6 +58,7 @@ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
|
||||||
|
|
||||||
public DatabaseConnectionInfoImpl(Map<String, Object> settings, Dialect dialect) {
|
public DatabaseConnectionInfoImpl(Map<String, Object> settings, Dialect dialect) {
|
||||||
this(
|
this(
|
||||||
|
null,
|
||||||
determineUrl( settings ),
|
determineUrl( settings ),
|
||||||
determineDriver( settings ),
|
determineDriver( settings ),
|
||||||
dialect.getVersion(),
|
dialect.getVersion(),
|
||||||
|
@ -66,7 +71,7 @@ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseConnectionInfoImpl(Dialect dialect) {
|
public DatabaseConnectionInfoImpl(Dialect dialect) {
|
||||||
this( null, null, dialect.getVersion(), null, null, null, null );
|
this( null, null, null, dialect.getVersion(), null, null, null, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -111,6 +116,7 @@ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
|
||||||
"\n\tDatabase version: " + handleEmpty( dialectVersion ) +
|
"\n\tDatabase version: " + handleEmpty( dialectVersion ) +
|
||||||
"\n\tAutocommit mode: " + handleEmpty( autoCommitMode ) +
|
"\n\tAutocommit mode: " + handleEmpty( autoCommitMode ) +
|
||||||
"\n\tIsolation level: " + handleEmpty( isolationLevel ) +
|
"\n\tIsolation level: " + handleEmpty( isolationLevel ) +
|
||||||
|
"\n\tPool: " + handleEmpty( connectionProviderClass ) +
|
||||||
"\n\tMinimum pool size: " + handleEmpty( poolMinSize ) +
|
"\n\tMinimum pool size: " + handleEmpty( poolMinSize ) +
|
||||||
"\n\tMaximum pool size: " + handleEmpty( poolMaxSize );
|
"\n\tMaximum pool size: " + handleEmpty( poolMaxSize );
|
||||||
}
|
}
|
||||||
|
@ -127,6 +133,10 @@ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
|
||||||
return value != null ? value.toString() : DEFAULT;
|
return value != null ? value.toString() : DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String handleEmpty(Class<?> value) {
|
||||||
|
return value != null ? value.getSimpleName() : DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private static String determineUrl(Map<String, Object> settings) {
|
private static String determineUrl(Map<String, Object> settings) {
|
||||||
|
|
|
@ -150,6 +150,7 @@ public class DatasourceConnectionProviderImpl implements ConnectionProvider, Con
|
||||||
@Override
|
@Override
|
||||||
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
||||||
return new DatabaseConnectionInfoImpl(
|
return new DatabaseConnectionInfoImpl(
|
||||||
|
DatasourceConnectionProviderImpl.class,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
dialect.getVersion(),
|
dialect.getVersion(),
|
||||||
|
|
|
@ -142,6 +142,7 @@ public class DriverManagerConnectionProviderImpl
|
||||||
final ConnectionCreatorFactory factory = getConnectionCreatorFactory( configurationValues, serviceRegistry );
|
final ConnectionCreatorFactory factory = getConnectionCreatorFactory( configurationValues, serviceRegistry );
|
||||||
|
|
||||||
dbInfo = new DatabaseConnectionInfoImpl(
|
dbInfo = new DatabaseConnectionInfoImpl(
|
||||||
|
DriverManagerConnectionProviderImpl.class,
|
||||||
url,
|
url,
|
||||||
driverList,
|
driverList,
|
||||||
SimpleDatabaseVersion.ZERO_VERSION,
|
SimpleDatabaseVersion.ZERO_VERSION,
|
||||||
|
@ -283,6 +284,7 @@ public class DriverManagerConnectionProviderImpl
|
||||||
@Override
|
@Override
|
||||||
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
||||||
return new DatabaseConnectionInfoImpl(
|
return new DatabaseConnectionInfoImpl(
|
||||||
|
DriverManagerConnectionProviderImpl.class,
|
||||||
dbInfo.getJdbcUrl(),
|
dbInfo.getJdbcUrl(),
|
||||||
dbInfo.getJdbcDriver(),
|
dbInfo.getJdbcDriver(),
|
||||||
dialect.getVersion(),
|
dialect.getVersion(),
|
||||||
|
|
|
@ -72,30 +72,29 @@ public class DataSourceBasedMultiTenantConnectionProviderImpl<T>
|
||||||
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
|
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
|
||||||
final ConfigurationService configurationService = serviceRegistry.requireService( ConfigurationService.class );
|
final ConfigurationService configurationService = serviceRegistry.requireService( ConfigurationService.class );
|
||||||
final Object dataSourceConfigValue = configurationService.getSettings().get( DATASOURCE );
|
final Object dataSourceConfigValue = configurationService.getSettings().get( DATASOURCE );
|
||||||
if ( !(dataSourceConfigValue instanceof String) ) {
|
if ( !(dataSourceConfigValue instanceof String configuredJndiName) ) {
|
||||||
throw new HibernateException( "illegal value for configuration setting '" + DATASOURCE + "'" );
|
throw new HibernateException( "illegal value for configuration setting '" + DATASOURCE + "'" );
|
||||||
}
|
}
|
||||||
jndiName = (String) dataSourceConfigValue;
|
jndiName = configuredJndiName;
|
||||||
|
|
||||||
jndiService = serviceRegistry.getService( JndiService.class );
|
jndiService = serviceRegistry.getService( JndiService.class );
|
||||||
if ( jndiService == null ) {
|
if ( jndiService == null ) {
|
||||||
throw new HibernateException( "Could not locate JndiService from DataSourceBasedMultiTenantConnectionProviderImpl" );
|
throw new HibernateException( "Could not locate JndiService from DataSourceBasedMultiTenantConnectionProviderImpl" );
|
||||||
}
|
}
|
||||||
|
|
||||||
final Object namedObject = jndiService.locate( jndiName );
|
final Object namedObject = jndiService.locate( this.jndiName );
|
||||||
if ( namedObject == null ) {
|
if ( namedObject == null ) {
|
||||||
throw new HibernateException( "JNDI name [" + jndiName + "] could not be resolved" );
|
throw new HibernateException( "JNDI name [" + this.jndiName + "] could not be resolved" );
|
||||||
}
|
}
|
||||||
|
else if ( namedObject instanceof DataSource datasource ) {
|
||||||
if ( namedObject instanceof DataSource datasource ) {
|
final int loc = this.jndiName.lastIndexOf( '/' );
|
||||||
final int loc = jndiName.lastIndexOf( '/' );
|
baseJndiNamespace = this.jndiName.substring( 0, loc );
|
||||||
baseJndiNamespace = jndiName.substring( 0, loc );
|
final String prefix = this.jndiName.substring( loc + 1);
|
||||||
final String prefix = jndiName.substring(loc + 1);
|
|
||||||
tenantIdentifierForAny = (T) prefix;
|
tenantIdentifierForAny = (T) prefix;
|
||||||
dataSourceMap().put( tenantIdentifierForAny, datasource );
|
dataSourceMap().put( tenantIdentifierForAny, datasource );
|
||||||
}
|
}
|
||||||
else if ( namedObject instanceof Context ) {
|
else if ( namedObject instanceof Context ) {
|
||||||
baseJndiNamespace = jndiName;
|
baseJndiNamespace = this.jndiName;
|
||||||
final Object configuredTenantId =
|
final Object configuredTenantId =
|
||||||
configurationService.getSettings().get( TENANT_IDENTIFIER_TO_USE_FOR_ANY_KEY );
|
configurationService.getSettings().get( TENANT_IDENTIFIER_TO_USE_FOR_ANY_KEY );
|
||||||
tenantIdentifierForAny = (T) configuredTenantId;
|
tenantIdentifierForAny = (T) configuredTenantId;
|
||||||
|
@ -106,7 +105,7 @@ public class DataSourceBasedMultiTenantConnectionProviderImpl<T>
|
||||||
else {
|
else {
|
||||||
throw new HibernateException(
|
throw new HibernateException(
|
||||||
"Unknown object type [" + namedObject.getClass().getName() +
|
"Unknown object type [" + namedObject.getClass().getName() +
|
||||||
"] found in JNDI location [" + jndiName + "]"
|
"] found in JNDI location [" + this.jndiName + "]"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,6 +118,7 @@ public class DataSourceBasedMultiTenantConnectionProviderImpl<T>
|
||||||
@Override
|
@Override
|
||||||
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
||||||
return new DatabaseConnectionInfoImpl(
|
return new DatabaseConnectionInfoImpl(
|
||||||
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
dialect.getVersion(),
|
dialect.getVersion(),
|
||||||
|
|
|
@ -95,6 +95,7 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura
|
||||||
@Override
|
@Override
|
||||||
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
||||||
return new DatabaseConnectionInfoImpl(
|
return new DatabaseConnectionInfoImpl(
|
||||||
|
HikariCPConnectionProvider.class,
|
||||||
hikariConfig.getJdbcUrl(),
|
hikariConfig.getJdbcUrl(),
|
||||||
// Attempt to resolve the driver name from the dialect, in case it wasn't explicitly set and access to
|
// Attempt to resolve the driver name from the dialect, in case it wasn't explicitly set and access to
|
||||||
// the database metadata is allowed
|
// the database metadata is allowed
|
||||||
|
|
|
@ -182,6 +182,7 @@ public class UCPConnectionProvider implements ConnectionProvider, Configurable,
|
||||||
@Override
|
@Override
|
||||||
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
|
||||||
return new DatabaseConnectionInfoImpl(
|
return new DatabaseConnectionInfoImpl(
|
||||||
|
UCPConnectionProvider.class,
|
||||||
ucpDS.getURL(),
|
ucpDS.getURL(),
|
||||||
ucpDS.getConnectionFactoryClassName(),
|
ucpDS.getConnectionFactoryClassName(),
|
||||||
dialect.getVersion(),
|
dialect.getVersion(),
|
||||||
|
|
Loading…
Reference in New Issue