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