Skip to content

Commit

Permalink
report the name of the ConnectionProvider along with the other info
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Dec 22, 2024
1 parent 879dca2 commit 2487390
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public void configure(Map<String, Object> properties) {
dataSource = createDataSource( jdbcUrl, connectionProps, poolSettings );

dbInfoProducer = dialect -> new DatabaseConnectionInfoImpl(
C3P0ConnectionProvider.class,
jdbcUrl,
jdbcDriverClass,
dialect.getVersion(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -36,13 +38,15 @@ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
protected final Integer poolMaxSize;

public DatabaseConnectionInfoImpl(
Class<? extends ConnectionProvider> connectionProviderClass,
String jdbcUrl,
String jdbcDriver,
DatabaseVersion dialectVersion,
String autoCommitMode,
String isolationLevel,
Integer poolMinSize,
Integer poolMaxSize) {
this.connectionProviderClass = connectionProviderClass;
this.jdbcUrl = nullIfEmpty( jdbcUrl );
this.jdbcDriver = nullIfEmpty( jdbcDriver );
this.dialectVersion = dialectVersion;
Expand All @@ -54,6 +58,7 @@ public DatabaseConnectionInfoImpl(

public DatabaseConnectionInfoImpl(Map<String, Object> settings, Dialect dialect) {
this(
null,
determineUrl( settings ),
determineDriver( settings ),
dialect.getVersion(),
Expand All @@ -66,7 +71,7 @@ public DatabaseConnectionInfoImpl(Map<String, Object> 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
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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<String, Object> settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public boolean supportsAggressiveRelease() {
@Override
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
return new DatabaseConnectionInfoImpl(
DatasourceConnectionProviderImpl.class,
null,
null,
dialect.getVersion(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private static ConnectionCreator buildCreator(
final ConnectionCreatorFactory factory = getConnectionCreatorFactory( configurationValues, serviceRegistry );

dbInfo = new DatabaseConnectionInfoImpl(
DriverManagerConnectionProviderImpl.class,
url,
driverList,
SimpleDatabaseVersion.ZERO_VERSION,
Expand Down Expand Up @@ -283,6 +284,7 @@ public boolean supportsAggressiveRelease() {
@Override
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
return new DatabaseConnectionInfoImpl(
DriverManagerConnectionProviderImpl.class,
dbInfo.getJdbcUrl(),
dbInfo.getJdbcDriver(),
dialect.getVersion(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,29 @@ private Map<T, DataSource> 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;
Expand All @@ -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 + "]"
);
}
}
Expand All @@ -119,6 +118,7 @@ public void stop() {
@Override
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
return new DatabaseConnectionInfoImpl(
null,
null,
null,
dialect.getVersion(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public boolean supportsAggressiveRelease() {
@Override
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
return new DatabaseConnectionInfoImpl(
UCPConnectionProvider.class,
ucpDS.getURL(),
ucpDS.getConnectionFactoryClassName(),
dialect.getVersion(),
Expand Down

0 comments on commit 2487390

Please sign in to comment.