From 24873906155e15996f72e92c1c43d87d4c886b0f Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sat, 21 Dec 2024 22:40:08 +0100 Subject: [PATCH] report the name of the ConnectionProvider along with the other info --- .../internal/AgroalConnectionProvider.java | 1 + .../c3p0/internal/C3P0ConnectionProvider.java | 1 + .../internal/DatabaseConnectionInfoImpl.java | 12 +++++++++- .../DatasourceConnectionProviderImpl.java | 1 + .../DriverManagerConnectionProviderImpl.java | 2 ++ ...asedMultiTenantConnectionProviderImpl.java | 22 +++++++++---------- .../internal/HikariCPConnectionProvider.java | 1 + .../internal/UCPConnectionProvider.java | 1 + 8 files changed, 29 insertions(+), 12 deletions(-) diff --git a/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java b/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java index 40fdf741d2ce..f568266400d1 100644 --- a/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java +++ b/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java @@ -167,6 +167,7 @@ public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) { 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 diff --git a/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java b/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java index a47a80ad4a9f..b9e10ed0d872 100644 --- a/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java +++ b/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java @@ -152,6 +152,7 @@ public void configure(Map properties) { dataSource = createDataSource( jdbcUrl, connectionProps, poolSettings ); dbInfoProducer = dialect -> new DatabaseConnectionInfoImpl( + C3P0ConnectionProvider.class, jdbcUrl, jdbcDriverClass, dialect.getVersion(), diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatabaseConnectionInfoImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatabaseConnectionInfoImpl.java index 1c956f914678..14859f5f75ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatabaseConnectionInfoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatabaseConnectionInfoImpl.java @@ -9,6 +9,7 @@ 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 @@ 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 connectionProviderClass, String jdbcUrl, String jdbcDriver, DatabaseVersion dialectVersion, @@ -43,6 +46,7 @@ public DatabaseConnectionInfoImpl( 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 DatabaseConnectionInfoImpl( public DatabaseConnectionInfoImpl(Map settings, Dialect dialect) { this( + null, determineUrl( settings ), determineDriver( settings ), dialect.getVersion(), @@ -66,7 +71,7 @@ public DatabaseConnectionInfoImpl(Map settings, 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 @@ -111,6 +116,7 @@ public String toInfoString() { "\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 @@ private static String handleEmpty(Integer value) { 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 settings) { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatasourceConnectionProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatasourceConnectionProviderImpl.java index 547c80de115e..310a6a84ba61 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatasourceConnectionProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatasourceConnectionProviderImpl.java @@ -150,6 +150,7 @@ public boolean supportsAggressiveRelease() { @Override public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) { return new DatabaseConnectionInfoImpl( + DatasourceConnectionProviderImpl.class, null, null, dialect.getVersion(), diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java index b640b51d1007..1aed92862d28 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java @@ -142,6 +142,7 @@ private static ConnectionCreator buildCreator( final ConnectionCreatorFactory factory = getConnectionCreatorFactory( configurationValues, serviceRegistry ); dbInfo = new DatabaseConnectionInfoImpl( + DriverManagerConnectionProviderImpl.class, url, driverList, SimpleDatabaseVersion.ZERO_VERSION, @@ -283,6 +284,7 @@ public boolean supportsAggressiveRelease() { @Override public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) { return new DatabaseConnectionInfoImpl( + DriverManagerConnectionProviderImpl.class, dbInfo.getJdbcUrl(), dbInfo.getJdbcDriver(), dialect.getVersion(), diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java index 4d5357a63831..9f1da9c64d99 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java @@ -72,30 +72,29 @@ private Map dataSourceMap() { 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 @@ else if ( namedObject instanceof Context ) { 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 void stop() { @Override public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) { return new DatabaseConnectionInfoImpl( + null, null, null, dialect.getVersion(), diff --git a/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariCPConnectionProvider.java b/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariCPConnectionProvider.java index 16ab7c8b777e..1be0ff666846 100644 --- a/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariCPConnectionProvider.java +++ b/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariCPConnectionProvider.java @@ -95,6 +95,7 @@ public boolean supportsAggressiveRelease() { @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 diff --git a/hibernate-ucp/src/main/java/org/hibernate/oracleucp/internal/UCPConnectionProvider.java b/hibernate-ucp/src/main/java/org/hibernate/oracleucp/internal/UCPConnectionProvider.java index 871f77192792..7e48bd18bdcc 100644 --- a/hibernate-ucp/src/main/java/org/hibernate/oracleucp/internal/UCPConnectionProvider.java +++ b/hibernate-ucp/src/main/java/org/hibernate/oracleucp/internal/UCPConnectionProvider.java @@ -182,6 +182,7 @@ public boolean supportsAggressiveRelease() { @Override public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) { return new DatabaseConnectionInfoImpl( + UCPConnectionProvider.class, ucpDS.getURL(), ucpDS.getConnectionFactoryClassName(), dialect.getVersion(),