HHH-18224 - standardize logging of database connection
HHH-18224 - add database logging info support also to MultiTenantConnectionProvider. Log output through subsystem logging. HHH-18224 - remove duplicated database info logging HHH-18224 - complete refactor of DatabaseConnectionInfo and add more info HHH-18224 - add standard database info logging to the proxool connection provider HHH-18224 - add min/max pool sizes to standard db logging Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
parent
e33bcfcf81
commit
f556ba9e90
|
@ -9,6 +9,7 @@ package org.hibernate.agroal.internal;
|
||||||
|
|
||||||
import io.agroal.api.AgroalDataSource;
|
import io.agroal.api.AgroalDataSource;
|
||||||
import io.agroal.api.configuration.AgroalConnectionFactoryConfiguration;
|
import io.agroal.api.configuration.AgroalConnectionFactoryConfiguration;
|
||||||
|
import io.agroal.api.configuration.AgroalConnectionPoolConfiguration;
|
||||||
import io.agroal.api.configuration.supplier.AgroalConnectionFactoryConfigurationSupplier;
|
import io.agroal.api.configuration.supplier.AgroalConnectionFactoryConfigurationSupplier;
|
||||||
import io.agroal.api.configuration.supplier.AgroalPropertiesReader;
|
import io.agroal.api.configuration.supplier.AgroalPropertiesReader;
|
||||||
import io.agroal.api.security.NamePrincipal;
|
import io.agroal.api.security.NamePrincipal;
|
||||||
|
@ -17,11 +18,12 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.cfg.AgroalSettings;
|
import org.hibernate.cfg.AgroalSettings;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
import org.hibernate.service.spi.Stoppable;
|
import org.hibernate.service.spi.Stoppable;
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
@ -30,6 +32,10 @@ import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
|
import static org.hibernate.cfg.AgroalSettings.AGROAL_CONFIG_PREFIX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConnectionProvider based on Agroal connection pool
|
* ConnectionProvider based on Agroal connection pool
|
||||||
* To use this ConnectionProvider set: <pre> hibernate.connection.provider_class AgroalConnectionProvider </pre>
|
* To use this ConnectionProvider set: <pre> hibernate.connection.provider_class AgroalConnectionProvider </pre>
|
||||||
|
@ -54,18 +60,26 @@ import java.util.function.Function;
|
||||||
*/
|
*/
|
||||||
public class AgroalConnectionProvider implements ConnectionProvider, Configurable, Stoppable {
|
public class AgroalConnectionProvider implements ConnectionProvider, Configurable, Stoppable {
|
||||||
|
|
||||||
public static final String CONFIG_PREFIX = AgroalSettings.AGROAL_CONFIG_PREFIX + ".";
|
public static final String CONFIG_PREFIX = AGROAL_CONFIG_PREFIX + ".";
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Logger LOGGER = Logger.getLogger( AgroalConnectionProvider.class );
|
private static final Logger LOGGER = Logger.getLogger( AgroalConnectionProvider.class );
|
||||||
private AgroalDataSource agroalDataSource = null;
|
private AgroalDataSource agroalDataSource = null;
|
||||||
|
private DatabaseConnectionInfo dbInfo;
|
||||||
|
|
||||||
// --- Configurable
|
// --- Configurable
|
||||||
|
|
||||||
private static void resolveIsolationSetting(Map<String, Object> properties, AgroalConnectionFactoryConfigurationSupplier cf) {
|
private static String extractIsolationAsString(Map<String, Object> properties) {
|
||||||
Integer isolation = ConnectionProviderInitiator.extractIsolation( properties );
|
Integer isolation = ConnectionProviderInitiator.extractIsolation( properties );
|
||||||
if ( isolation != null ) {
|
if ( isolation != null ) {
|
||||||
// Agroal resolves transaction isolation from the 'nice' name
|
// Agroal resolves transaction isolation from the 'nice' name
|
||||||
String isolationString = ConnectionProviderInitiator.toIsolationNiceName( isolation );
|
return ConnectionProviderInitiator.toIsolationNiceName( isolation );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void resolveIsolationSetting(Map<String, Object> properties, AgroalConnectionFactoryConfigurationSupplier cf) {
|
||||||
|
String isolationString = extractIsolationAsString( properties );
|
||||||
|
if ( isolationString != null ) {
|
||||||
cf.jdbcTransactionIsolation( AgroalConnectionFactoryConfiguration.TransactionIsolation.valueOf( isolationString ) );
|
cf.jdbcTransactionIsolation( AgroalConnectionFactoryConfiguration.TransactionIsolation.valueOf( isolationString ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,6 +108,18 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl
|
||||||
} ) );
|
} ) );
|
||||||
|
|
||||||
agroalDataSource = AgroalDataSource.from( agroalProperties );
|
agroalDataSource = AgroalDataSource.from( agroalProperties );
|
||||||
|
|
||||||
|
// For logging purposes
|
||||||
|
AgroalConnectionPoolConfiguration acpc = agroalDataSource.getConfiguration().connectionPoolConfiguration();
|
||||||
|
AgroalConnectionFactoryConfiguration acfc = acpc.connectionFactoryConfiguration();
|
||||||
|
dbInfo = new DatabaseConnectionInfoImpl()
|
||||||
|
.setDBUrl( acfc.jdbcUrl() )
|
||||||
|
.setDBDriverName( acfc.connectionProviderClass().toString() )
|
||||||
|
.setDBAutoCommitMode( Boolean.toString(acfc.autoCommit()) )
|
||||||
|
.setDBIsolationLevel( acfc.jdbcTransactionIsolation() != null ?
|
||||||
|
ConnectionProviderInitiator.toIsolationNiceName( acfc.jdbcTransactionIsolation().level() ) : null )
|
||||||
|
.setDBMinPoolSize( String.valueOf(acpc.minSize()) )
|
||||||
|
.setDBMaxPoolSize( String.valueOf(acpc.maxSize()) );
|
||||||
}
|
}
|
||||||
catch ( Exception e ) {
|
catch ( Exception e ) {
|
||||||
throw new HibernateException( e );
|
throw new HibernateException( e );
|
||||||
|
@ -121,6 +147,11 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return dbInfo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
||||||
return ConnectionProvider.class.equals( unwrapType )
|
return ConnectionProvider.class.equals( unwrapType )
|
||||||
|
|
|
@ -21,7 +21,9 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||||
import org.hibernate.cfg.C3p0Settings;
|
import org.hibernate.cfg.C3p0Settings;
|
||||||
import org.hibernate.cfg.JdbcSettings;
|
import org.hibernate.cfg.JdbcSettings;
|
||||||
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.internal.util.PropertiesHelper;
|
import org.hibernate.internal.util.PropertiesHelper;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
|
@ -61,7 +63,7 @@ public class C3P0ConnectionProvider
|
||||||
// hibernate sensibly lets default to minPoolSize, but we'll let users
|
// hibernate sensibly lets default to minPoolSize, but we'll let users
|
||||||
// override it with the c3p0-style property if they want.
|
// override it with the c3p0-style property if they want.
|
||||||
private static final String C3P0_STYLE_INITIAL_POOL_SIZE = "c3p0.initialPoolSize";
|
private static final String C3P0_STYLE_INITIAL_POOL_SIZE = "c3p0.initialPoolSize";
|
||||||
|
private DatabaseConnectionInfo dbInfo;
|
||||||
private DataSource ds;
|
private DataSource ds;
|
||||||
private Integer isolation;
|
private Integer isolation;
|
||||||
private boolean autocommit;
|
private boolean autocommit;
|
||||||
|
@ -121,13 +123,12 @@ public class C3P0ConnectionProvider
|
||||||
JdbcSettings.URL,
|
JdbcSettings.URL,
|
||||||
JdbcSettings.JPA_JDBC_URL
|
JdbcSettings.JPA_JDBC_URL
|
||||||
);
|
);
|
||||||
|
|
||||||
final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( props );
|
final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( props );
|
||||||
|
|
||||||
C3P0_MSG_LOGGER.c3p0UsingDriver( jdbcDriverClass, jdbcUrl );
|
|
||||||
C3P0_MSG_LOGGER.connectionProperties( ConfigurationHelper.maskOut( connectionProps, "password" ) );
|
C3P0_MSG_LOGGER.connectionProperties( ConfigurationHelper.maskOut( connectionProps, "password" ) );
|
||||||
|
|
||||||
autocommit = getBoolean( JdbcSettings.AUTOCOMMIT, props );
|
autocommit = getBoolean( JdbcSettings.AUTOCOMMIT, props );
|
||||||
C3P0_MSG_LOGGER.autoCommitMode( autocommit );
|
|
||||||
|
|
||||||
if ( jdbcDriverClass == null ) {
|
if ( jdbcDriverClass == null ) {
|
||||||
C3P0_MSG_LOGGER.jdbcDriverNotSpecified();
|
C3P0_MSG_LOGGER.jdbcDriverNotSpecified();
|
||||||
|
@ -141,11 +142,13 @@ public class C3P0ConnectionProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Integer minPoolSize = null;
|
||||||
|
Integer maxPoolSize = null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//swaldman 2004-02-07: modify to allow null values to signify fall through to c3p0 PoolConfig defaults
|
//swaldman 2004-02-07: modify to allow null values to signify fall through to c3p0 PoolConfig defaults
|
||||||
final Integer minPoolSize = getInteger( C3p0Settings.C3P0_MIN_SIZE, props );
|
minPoolSize = getInteger( C3p0Settings.C3P0_MIN_SIZE, props );
|
||||||
final Integer maxPoolSize = getInteger( C3p0Settings.C3P0_MAX_SIZE, props );
|
maxPoolSize = getInteger( C3p0Settings.C3P0_MAX_SIZE, props );
|
||||||
final Integer maxIdleTime = getInteger( C3p0Settings.C3P0_TIMEOUT, props );
|
final Integer maxIdleTime = getInteger( C3p0Settings.C3P0_TIMEOUT, props );
|
||||||
final Integer maxStatements = getInteger( C3p0Settings.C3P0_MAX_STATEMENTS, props );
|
final Integer maxStatements = getInteger( C3p0Settings.C3P0_MAX_STATEMENTS, props );
|
||||||
final Integer acquireIncrement = getInteger( C3p0Settings.C3P0_ACQUIRE_INCREMENT, props );
|
final Integer acquireIncrement = getInteger( C3p0Settings.C3P0_ACQUIRE_INCREMENT, props );
|
||||||
|
@ -187,19 +190,26 @@ public class C3P0ConnectionProvider
|
||||||
|
|
||||||
final DataSource unpooled = DataSources.unpooledDataSource( jdbcUrl, connectionProps );
|
final DataSource unpooled = DataSources.unpooledDataSource( jdbcUrl, connectionProps );
|
||||||
|
|
||||||
final Map<String,Object> allProps = new HashMap<>();
|
final Map<String, Object> allProps = new HashMap<>();
|
||||||
allProps.putAll( props );
|
allProps.putAll( props );
|
||||||
allProps.putAll( PropertiesHelper.map(c3props) );
|
allProps.putAll( PropertiesHelper.map(c3props) );
|
||||||
|
|
||||||
ds = DataSources.pooledDataSource( unpooled, allProps );
|
ds = DataSources.pooledDataSource( unpooled, allProps );
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
C3P0_LOGGER.error( C3P0_MSG_LOGGER.unableToInstantiateC3p0ConnectionPool(), e );
|
C3P0_LOGGER.error( C3P0_MSG_LOGGER.unableToInstantiateC3p0ConnectionPool(), e );;
|
||||||
throw new HibernateException( C3P0_MSG_LOGGER.unableToInstantiateC3p0ConnectionPool(), e );
|
throw new HibernateException( C3P0_MSG_LOGGER.unableToInstantiateC3p0ConnectionPool(), e );
|
||||||
}
|
}
|
||||||
|
|
||||||
isolation = ConnectionProviderInitiator.extractIsolation( props );
|
isolation = ConnectionProviderInitiator.extractIsolation( props );
|
||||||
C3P0_MSG_LOGGER.jdbcIsolationLevel( ConnectionProviderInitiator.toIsolationNiceName( isolation ) );
|
|
||||||
|
dbInfo = new DatabaseConnectionInfoImpl()
|
||||||
|
.setDBUrl( jdbcUrl )
|
||||||
|
.setDBDriverName( jdbcDriverClass )
|
||||||
|
.setDBAutoCommitMode( Boolean.toString( autocommit ) )
|
||||||
|
.setDBIsolationLevel( isolation != null ? ConnectionProviderInitiator.toIsolationNiceName( isolation ) : null )
|
||||||
|
.setDBMinPoolSize( String.valueOf(minPoolSize) )
|
||||||
|
.setDBMaxPoolSize( String.valueOf(maxPoolSize) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -207,6 +217,11 @@ public class C3P0ConnectionProvider
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return dbInfo;
|
||||||
|
}
|
||||||
|
|
||||||
private void setOverwriteProperty(
|
private void setOverwriteProperty(
|
||||||
String hibernateStyleKey,
|
String hibernateStyleKey,
|
||||||
String c3p0StyleKey,
|
String c3p0StyleKey,
|
||||||
|
@ -237,6 +252,7 @@ public class C3P0ConnectionProvider
|
||||||
}
|
}
|
||||||
catch (SQLException sqle) {
|
catch (SQLException sqle) {
|
||||||
C3P0_MSG_LOGGER.unableToDestroyC3p0ConnectionPool( sqle );
|
C3P0_MSG_LOGGER.unableToDestroyC3p0ConnectionPool( sqle );
|
||||||
|
throw new HibernateException( "Unable to destroy the connection pool", sqle );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,16 +50,6 @@ public interface C3P0MessageLogger extends ConnectionPoolingLogger {
|
||||||
+ "properties. Hibernate-style property '%1$s' will be used and c3p0-style property '%2$s' will be ignored!", id = 10001)
|
+ "properties. Hibernate-style property '%1$s' will be used and c3p0-style property '%2$s' will be ignored!", id = 10001)
|
||||||
void bothHibernateAndC3p0StylesSet(String hibernateStyle,String c3p0Style);
|
void bothHibernateAndC3p0StylesSet(String hibernateStyle,String c3p0Style);
|
||||||
|
|
||||||
/**
|
|
||||||
* Log a message (INFO) about which Driver class is being used.
|
|
||||||
*
|
|
||||||
* @param jdbcDriverClass The JDBC Driver class
|
|
||||||
* @param jdbcUrl The JDBC URL
|
|
||||||
*/
|
|
||||||
@LogMessage(level = INFO)
|
|
||||||
@Message(value = "C3P0 using driver: %s at URL: %s", id = 10002)
|
|
||||||
void c3p0UsingDriver(String jdbcDriverClass, String jdbcUrl);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a message about not being able to find the JDBC driver class
|
* Build a message about not being able to find the JDBC driver class
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,115 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||||
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
|
*/
|
||||||
|
package org.hibernate.engine.jdbc.connections.internal;
|
||||||
|
|
||||||
|
import org.hibernate.dialect.DatabaseVersion;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
|
||||||
|
import static org.hibernate.dialect.SimpleDatabaseVersion.ZERO_VERSION;
|
||||||
|
import static org.hibernate.dialect.SimpleDatabaseVersion.NO_VERSION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jan Schatteman
|
||||||
|
*/
|
||||||
|
public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
|
||||||
|
|
||||||
|
public static final String DEFAULT = "undefined/unknown";
|
||||||
|
|
||||||
|
protected String dbUrl = DEFAULT;
|
||||||
|
protected String dbDriverName = DEFAULT;
|
||||||
|
protected DatabaseVersion dbVersion = ZERO_VERSION;
|
||||||
|
protected String dbAutoCommitMode = DEFAULT;
|
||||||
|
protected String dbIsolationLevel = DEFAULT;
|
||||||
|
protected String dbMinPoolSize = DEFAULT;
|
||||||
|
protected String dbMaxPoolSize = DEFAULT;
|
||||||
|
|
||||||
|
public DatabaseConnectionInfoImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo setDBUrl(String dbUrl) {
|
||||||
|
this.dbUrl = dbUrl;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo setDBDriverName(String dbDriverName) {
|
||||||
|
if ( checkValidString(dbDriverName) && isDefaultStringValue(this.dbDriverName) ) {
|
||||||
|
this.dbDriverName = dbDriverName;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo setDBVersion(DatabaseVersion dbVersion) {
|
||||||
|
if ( checkValidVersion(dbVersion) && ZERO_VERSION.equals(this.dbVersion) ) {
|
||||||
|
this.dbVersion = dbVersion;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo setDBAutoCommitMode(String dbAutoCommitMode) {
|
||||||
|
if ( checkValidString(dbAutoCommitMode) && isDefaultStringValue(this.dbAutoCommitMode) ) {
|
||||||
|
this.dbAutoCommitMode = dbAutoCommitMode;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo setDBIsolationLevel(String dbIsolationLevel) {
|
||||||
|
if ( checkValidString(dbIsolationLevel) && isDefaultStringValue(this.dbIsolationLevel) ) {
|
||||||
|
this.dbIsolationLevel = dbIsolationLevel;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo setDBMinPoolSize(String minPoolSize) {
|
||||||
|
if ( checkValidInteger(minPoolSize) ) {
|
||||||
|
this.dbMinPoolSize = minPoolSize;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo setDBMaxPoolSize(String maxPoolSize) {
|
||||||
|
if ( checkValidInteger(maxPoolSize) ) {
|
||||||
|
this.dbMaxPoolSize = maxPoolSize;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkValidInteger(String integerString) {
|
||||||
|
return checkValidString( integerString ) && Integer.parseInt( integerString, 10 ) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkValidString(String value) {
|
||||||
|
return !( StringHelper.isBlank( value ) || "null".equalsIgnoreCase( value ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkValidVersion(DatabaseVersion version) {
|
||||||
|
return version != null && !( version.isSame(ZERO_VERSION) || version.isSame(NO_VERSION) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isDefaultStringValue(String value) {
|
||||||
|
return DEFAULT.equalsIgnoreCase( value );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append( "\tDatabase JDBC URL [" ).append( dbUrl ).append(']');
|
||||||
|
sb.append(sb.length() > 0 ? "\n\t" : "" ).append( "Database driver: " ).append( dbDriverName );
|
||||||
|
sb.append(sb.length() > 0 ? "\n\t" : "" ).append( "Database version: " ).append( dbVersion );
|
||||||
|
sb.append(sb.length() > 0 ? "\n\t" : "" ).append( "Autocommit mode: " ).append( dbAutoCommitMode );
|
||||||
|
sb.append(sb.length() > 0 ? "\n\t" : "" ).append( "Isolation level: " ).append( dbIsolationLevel );
|
||||||
|
sb.append(sb.length() > 0 ? "\n\t" : "" ).append( "Minimum pool size: " ).append( dbMinPoolSize );
|
||||||
|
sb.append(sb.length() > 0 ? "\n\t" : "" ).append( "Maximum pool size: " ).append( dbMaxPoolSize );
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ import javax.sql.DataSource;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.cfg.Environment;
|
import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.engine.jndi.spi.JndiService;
|
import org.hibernate.engine.jndi.spi.JndiService;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
|
@ -38,6 +39,7 @@ public class DatasourceConnectionProviderImpl implements ConnectionProvider, Con
|
||||||
private String pass;
|
private String pass;
|
||||||
private boolean useCredentials;
|
private boolean useCredentials;
|
||||||
private JndiService jndiService;
|
private JndiService jndiService;
|
||||||
|
private String dataSourceJndiName;
|
||||||
|
|
||||||
private boolean available;
|
private boolean available;
|
||||||
|
|
||||||
|
@ -92,6 +94,7 @@ public class DatasourceConnectionProviderImpl implements ConnectionProvider, Con
|
||||||
+ "] configuration property"
|
+ "] configuration property"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
this.dataSourceJndiName = dataSourceJndiName;
|
||||||
if ( jndiService == null ) {
|
if ( jndiService == null ) {
|
||||||
throw new HibernateException( "Unable to locate JndiService to lookup Datasource" );
|
throw new HibernateException( "Unable to locate JndiService to lookup Datasource" );
|
||||||
}
|
}
|
||||||
|
@ -131,4 +134,9 @@ public class DatasourceConnectionProviderImpl implements ConnectionProvider, Con
|
||||||
public boolean supportsAggressiveRelease() {
|
public boolean supportsAggressiveRelease() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return new DatabaseConnectionInfoImpl().setDBUrl( "Connecting through datasource" + dataSourceJndiName );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,10 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Internal;
|
import org.hibernate.Internal;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
import org.hibernate.cfg.JdbcSettings;
|
||||||
import org.hibernate.dialect.Database;
|
import org.hibernate.dialect.Database;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.internal.util.securitymanager.SystemSecurityManager;
|
import org.hibernate.internal.util.securitymanager.SystemSecurityManager;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
|
@ -67,6 +69,8 @@ public class DriverManagerConnectionProviderImpl
|
||||||
|
|
||||||
private volatile PoolState state;
|
private volatile PoolState state;
|
||||||
|
|
||||||
|
private static DatabaseConnectionInfo dbInfo;
|
||||||
|
|
||||||
// create the pool ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// create the pool ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
private volatile ServiceRegistryImplementor serviceRegistry;
|
private volatile ServiceRegistryImplementor serviceRegistry;
|
||||||
|
@ -132,13 +136,10 @@ public class DriverManagerConnectionProviderImpl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( success ) {
|
StringBuilder list = new StringBuilder();
|
||||||
CONNECTIONS_MESSAGE_LOGGER.loadedDriver( driverClassName );
|
if ( !success ) {
|
||||||
}
|
|
||||||
else {
|
|
||||||
//we're hoping that the driver is already loaded
|
//we're hoping that the driver is already loaded
|
||||||
CONNECTIONS_MESSAGE_LOGGER.noDriver( AvailableSettings.DRIVER );
|
CONNECTIONS_MESSAGE_LOGGER.noDriver( AvailableSettings.DRIVER );
|
||||||
StringBuilder list = new StringBuilder();
|
|
||||||
Enumeration<Driver> drivers = DriverManager.getDrivers();
|
Enumeration<Driver> drivers = DriverManager.getDrivers();
|
||||||
while ( drivers.hasMoreElements() ) {
|
while ( drivers.hasMoreElements() ) {
|
||||||
if ( list.length() != 0) {
|
if ( list.length() != 0) {
|
||||||
|
@ -146,7 +147,6 @@ public class DriverManagerConnectionProviderImpl
|
||||||
}
|
}
|
||||||
list.append( drivers.nextElement().getClass().getName() );
|
list.append( drivers.nextElement().getClass().getName() );
|
||||||
}
|
}
|
||||||
CONNECTIONS_MESSAGE_LOGGER.loadedDrivers( list.toString() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( url == null ) {
|
if ( url == null ) {
|
||||||
|
@ -155,8 +155,6 @@ public class DriverManagerConnectionProviderImpl
|
||||||
throw new HibernateException( msg );
|
throw new HibernateException( msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
CONNECTIONS_MESSAGE_LOGGER.usingUrl( url );
|
|
||||||
|
|
||||||
final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( configurationValues );
|
final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( configurationValues );
|
||||||
|
|
||||||
// if debug level is enabled, then log the password, otherwise mask it
|
// if debug level is enabled, then log the password, otherwise mask it
|
||||||
|
@ -168,13 +166,7 @@ public class DriverManagerConnectionProviderImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean autoCommit = ConfigurationHelper.getBoolean( AvailableSettings.AUTOCOMMIT, configurationValues );
|
final boolean autoCommit = ConfigurationHelper.getBoolean( AvailableSettings.AUTOCOMMIT, configurationValues );
|
||||||
CONNECTIONS_MESSAGE_LOGGER.autoCommitMode( autoCommit );
|
|
||||||
|
|
||||||
final Integer isolation = ConnectionProviderInitiator.extractIsolation( configurationValues );
|
final Integer isolation = ConnectionProviderInitiator.extractIsolation( configurationValues );
|
||||||
if ( isolation != null ) {
|
|
||||||
CONNECTIONS_MESSAGE_LOGGER.jdbcIsolationLevel( ConnectionProviderInitiator.toIsolationNiceName( isolation ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
final String initSql = (String) configurationValues.get( INIT_SQL );
|
final String initSql = (String) configurationValues.get( INIT_SQL );
|
||||||
|
|
||||||
final Object connectionCreatorFactory = configurationValues.get( CONNECTION_CREATOR_FACTORY );
|
final Object connectionCreatorFactory = configurationValues.get( CONNECTION_CREATOR_FACTORY );
|
||||||
|
@ -188,7 +180,17 @@ public class DriverManagerConnectionProviderImpl
|
||||||
if ( factory == null ) {
|
if ( factory == null ) {
|
||||||
factory = ConnectionCreatorFactoryImpl.INSTANCE;
|
factory = ConnectionCreatorFactoryImpl.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbInfo = new DatabaseConnectionInfoImpl()
|
||||||
|
.setDBUrl( url )
|
||||||
|
.setDBDriverName( success ? driverClassName : list.toString() )
|
||||||
|
.setDBAutoCommitMode( Boolean.toString( autoCommit ) )
|
||||||
|
.setDBIsolationLevel( isolation != null ? ConnectionProviderInitiator.toIsolationNiceName(isolation) : null )
|
||||||
|
// no standard setting for minimum size?
|
||||||
|
.setDBMaxPoolSize( ConfigurationHelper.getString(JdbcSettings.POOL_SIZE, configurationValues) );
|
||||||
|
|
||||||
return factory.create(
|
return factory.create(
|
||||||
|
|
||||||
driver,
|
driver,
|
||||||
serviceRegistry,
|
serviceRegistry,
|
||||||
url,
|
url,
|
||||||
|
@ -275,6 +277,11 @@ public class DriverManagerConnectionProviderImpl
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return dbInfo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
||||||
return ConnectionProvider.class.equals( unwrapType ) ||
|
return ConnectionProvider.class.equals( unwrapType ) ||
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.engine.jdbc.connections.spi;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
import org.hibernate.service.spi.Wrapped;
|
import org.hibernate.service.spi.Wrapped;
|
||||||
|
|
||||||
|
@ -69,4 +70,9 @@ public interface ConnectionProvider extends Service, Wrapped {
|
||||||
* @return {@code true} if aggressive releasing is supported; {@code false} otherwise.
|
* @return {@code true} if aggressive releasing is supported; {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
boolean supportsAggressiveRelease();
|
boolean supportsAggressiveRelease();
|
||||||
|
|
||||||
|
default DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return new DatabaseConnectionInfoImpl();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.cfg.MultiTenancySettings;
|
import org.hibernate.cfg.MultiTenancySettings;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.engine.jndi.spi.JndiService;
|
import org.hibernate.engine.jndi.spi.JndiService;
|
||||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
|
@ -47,6 +48,8 @@ public class DataSourceBasedMultiTenantConnectionProviderImpl<T>
|
||||||
private T tenantIdentifierForAny;
|
private T tenantIdentifierForAny;
|
||||||
private String baseJndiNamespace;
|
private String baseJndiNamespace;
|
||||||
|
|
||||||
|
private DatabaseConnectionInfo dbInfo;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DataSource selectAnyDataSource() {
|
protected DataSource selectAnyDataSource() {
|
||||||
return selectDataSource( tenantIdentifierForAny );
|
return selectDataSource( tenantIdentifierForAny );
|
||||||
|
@ -59,6 +62,7 @@ public class DataSourceBasedMultiTenantConnectionProviderImpl<T>
|
||||||
dataSource = (DataSource) jndiService.locate( baseJndiNamespace + '/' + tenantIdentifier );
|
dataSource = (DataSource) jndiService.locate( baseJndiNamespace + '/' + tenantIdentifier );
|
||||||
dataSourceMap().put( tenantIdentifier, dataSource );
|
dataSourceMap().put( tenantIdentifier, dataSource );
|
||||||
}
|
}
|
||||||
|
dbInfo = new DatabaseConnectionInfoImpl().setDBUrl( "Connecting through datasource" + baseJndiNamespace + '/' + tenantIdentifier );
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,4 +123,10 @@ public class DataSourceBasedMultiTenantConnectionProviderImpl<T>
|
||||||
dataSourceMap = null;
|
dataSourceMap = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return dbInfo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||||
|
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
|
*/
|
||||||
|
package org.hibernate.engine.jdbc.connections.spi;
|
||||||
|
|
||||||
|
import org.hibernate.dialect.DatabaseVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jan Schatteman
|
||||||
|
*/
|
||||||
|
public interface DatabaseConnectionInfo {
|
||||||
|
DatabaseConnectionInfo setDBUrl(String dbUrl);
|
||||||
|
|
||||||
|
DatabaseConnectionInfo setDBDriverName(String dbDriverName);
|
||||||
|
|
||||||
|
DatabaseConnectionInfo setDBVersion(DatabaseVersion dbVersion);
|
||||||
|
|
||||||
|
DatabaseConnectionInfo setDBAutoCommitMode(String dbAutoCommitMode);
|
||||||
|
|
||||||
|
DatabaseConnectionInfo setDBIsolationLevel(String dbIsolationLevel);
|
||||||
|
|
||||||
|
DatabaseConnectionInfo setDBMinPoolSize(String minPoolSize);
|
||||||
|
|
||||||
|
DatabaseConnectionInfo setDBMaxPoolSize(String maxPoolSize);
|
||||||
|
|
||||||
|
String toString();
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ package org.hibernate.engine.jdbc.connections.spi;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.service.Service;
|
import org.hibernate.service.Service;
|
||||||
import org.hibernate.service.spi.Wrapped;
|
import org.hibernate.service.spi.Wrapped;
|
||||||
|
|
||||||
|
@ -89,4 +90,9 @@ public interface MultiTenantConnectionProvider<T> extends Service, Wrapped {
|
||||||
* @return {@code true} if aggressive releasing is supported; {@code false} otherwise.
|
* @return {@code true} if aggressive releasing is supported; {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
boolean supportsAggressiveRelease();
|
boolean supportsAggressiveRelease();
|
||||||
|
|
||||||
|
default DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return new DatabaseConnectionInfoImpl();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,9 +17,12 @@ import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||||
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.dialect.SimpleDatabaseVersion;
|
||||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||||
import org.hibernate.engine.jdbc.batch.spi.BatchBuilder;
|
import org.hibernate.engine.jdbc.batch.spi.BatchBuilder;
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
|
||||||
import org.hibernate.engine.jdbc.dialect.spi.DialectFactory;
|
import org.hibernate.engine.jdbc.dialect.spi.DialectFactory;
|
||||||
|
@ -33,6 +36,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.event.internal.EmptyEventManager;
|
import org.hibernate.event.internal.EmptyEventManager;
|
||||||
import org.hibernate.event.spi.EventManager;
|
import org.hibernate.event.spi.EventManager;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.internal.log.ConnectionProviderLogger;
|
||||||
import org.hibernate.jdbc.AbstractReturningWork;
|
import org.hibernate.jdbc.AbstractReturningWork;
|
||||||
import org.hibernate.jpa.internal.MutableJpaComplianceImpl;
|
import org.hibernate.jpa.internal.MutableJpaComplianceImpl;
|
||||||
import org.hibernate.jpa.spi.JpaCompliance;
|
import org.hibernate.jpa.spi.JpaCompliance;
|
||||||
|
@ -120,8 +124,9 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final JdbcEnvironment jdbcEnvironment;
|
||||||
if ( allowJdbcMetadataAccess( configurationValues ) ) {
|
if ( allowJdbcMetadataAccess( configurationValues ) ) {
|
||||||
return getJdbcEnvironmentUsingJdbcMetadata(
|
jdbcEnvironment = getJdbcEnvironmentUsingJdbcMetadata(
|
||||||
configurationValues,
|
configurationValues,
|
||||||
registry,
|
registry,
|
||||||
dialectFactory,
|
dialectFactory,
|
||||||
|
@ -131,7 +136,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
|
||||||
explicitDatabaseVersion);
|
explicitDatabaseVersion);
|
||||||
}
|
}
|
||||||
else if ( explicitDialectConfiguration( explicitDatabaseName, configurationValues ) ) {
|
else if ( explicitDialectConfiguration( explicitDatabaseName, configurationValues ) ) {
|
||||||
return getJdbcEnvironmentWithExplicitConfiguration(
|
jdbcEnvironment = getJdbcEnvironmentWithExplicitConfiguration(
|
||||||
configurationValues,
|
configurationValues,
|
||||||
registry,
|
registry,
|
||||||
dialectFactory,
|
dialectFactory,
|
||||||
|
@ -142,8 +147,29 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator<JdbcEn
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return getJdbcEnvironmentWithDefaults( configurationValues, registry, dialectFactory );
|
jdbcEnvironment = getJdbcEnvironmentWithDefaults( configurationValues, registry, dialectFactory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logDbInfo( registry, jdbcEnvironment );
|
||||||
|
|
||||||
|
return jdbcEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void logDbInfo(ServiceRegistryImplementor registry, JdbcEnvironment jdbcEnvironment) {
|
||||||
|
// Standardized DB info logging
|
||||||
|
DatabaseConnectionInfo databaseConnectionInfo = null;
|
||||||
|
if ( !isMultiTenancyEnabled( registry ) ) {
|
||||||
|
final ConnectionProvider cp = registry.requireService( ConnectionProvider.class );
|
||||||
|
databaseConnectionInfo = cp.getDatabaseConnectionInfo();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final MultiTenantConnectionProvider<?> mcp = registry.getService( MultiTenantConnectionProvider.class );
|
||||||
|
databaseConnectionInfo = mcp.getDatabaseConnectionInfo();
|
||||||
|
}
|
||||||
|
// most likely, the version hasn't been set yet, at least not for the ConnectionProviders that we currently maintain
|
||||||
|
databaseConnectionInfo.setDBVersion( jdbcEnvironment.getDialect().getVersion() );
|
||||||
|
|
||||||
|
ConnectionProviderLogger.INSTANCE.logConnectionDetails( databaseConnectionInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JdbcEnvironmentImpl getJdbcEnvironmentWithDefaults(
|
private static JdbcEnvironmentImpl getJdbcEnvironmentWithDefaults(
|
||||||
|
|
|
@ -47,37 +47,17 @@ public interface ConnectionPoolingLogger extends BasicLogger {
|
||||||
@Message(value = "Using built-in connection pool (not intended for production use)", id = 10001002)
|
@Message(value = "Using built-in connection pool (not intended for production use)", id = 10001002)
|
||||||
void usingHibernateBuiltInConnectionPool();
|
void usingHibernateBuiltInConnectionPool();
|
||||||
|
|
||||||
@LogMessage(level = INFO)
|
|
||||||
@Message(value = "Autocommit mode: %s", id = 10001003)
|
|
||||||
void autoCommitMode(boolean autocommit);
|
|
||||||
|
|
||||||
@Message(value = "No JDBC URL specified by property %s", id = 10001004)
|
@Message(value = "No JDBC URL specified by property %s", id = 10001004)
|
||||||
String jdbcUrlNotSpecified(String property);
|
String jdbcUrlNotSpecified(String property);
|
||||||
|
|
||||||
@LogMessage(level = INFO)
|
|
||||||
@Message(value = "Loaded JDBC driver class: %s", id = 10001005)
|
|
||||||
void loadedDriver(String driverClassName);
|
|
||||||
|
|
||||||
@LogMessage(level = INFO)
|
@LogMessage(level = INFO)
|
||||||
@Message(value = "No JDBC driver class specified by %s", id = 10001010)
|
@Message(value = "No JDBC driver class specified by %s", id = 10001010)
|
||||||
void noDriver(String property);
|
void noDriver(String property);
|
||||||
|
|
||||||
@LogMessage(level = INFO)
|
|
||||||
@Message(value = "Loaded JDBC drivers: %s", id = 10001011)
|
|
||||||
void loadedDrivers(String loadedDrivers);
|
|
||||||
|
|
||||||
@LogMessage(level = INFO)
|
|
||||||
@Message(value = "Connecting with JDBC URL [%s]", id = 10001012)
|
|
||||||
void usingUrl(String url);
|
|
||||||
|
|
||||||
@LogMessage(level = WARN)
|
@LogMessage(level = WARN)
|
||||||
@Message(id = 10001006, value = "No JDBC Driver class was specified by property `jakarta.persistence.jdbc.driver`, `hibernate.driver` or `javax.persistence.jdbc.driver`")
|
@Message(id = 10001006, value = "No JDBC Driver class was specified by property `jakarta.persistence.jdbc.driver`, `hibernate.driver` or `javax.persistence.jdbc.driver`")
|
||||||
void jdbcDriverNotSpecified();
|
void jdbcDriverNotSpecified();
|
||||||
|
|
||||||
@LogMessage(level = INFO)
|
|
||||||
@Message(value = "JDBC isolation level: %s", id = 10001007)
|
|
||||||
void jdbcIsolationLevel(String isolationLevelToString);
|
|
||||||
|
|
||||||
@LogMessage(level = INFO)
|
@LogMessage(level = INFO)
|
||||||
@Message(value = "Cleaning up connection pool [%s]", id = 10001008)
|
@Message(value = "Cleaning up connection pool [%s]", id = 10001008)
|
||||||
void cleaningUpConnectionPool(String url);
|
void cleaningUpConnectionPool(String url);
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
|
*
|
||||||
|
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||||
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
|
*/
|
||||||
|
package org.hibernate.internal.log;
|
||||||
|
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
|
|
||||||
|
import org.jboss.logging.BasicLogger;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
import org.jboss.logging.annotations.LogMessage;
|
||||||
|
import org.jboss.logging.annotations.Message;
|
||||||
|
import org.jboss.logging.annotations.MessageLogger;
|
||||||
|
import org.jboss.logging.annotations.ValidIdRange;
|
||||||
|
|
||||||
|
import static org.jboss.logging.Logger.Level.INFO;
|
||||||
|
|
||||||
|
@MessageLogger( projectCode = "HHH" )
|
||||||
|
@ValidIdRange( min = 10002001, max = 10002100 )
|
||||||
|
@SubSystemLogging(
|
||||||
|
name = ConnectionProviderLogger.LOGGER_NAME,
|
||||||
|
description = "Used to log details of database access through `ConnectionProvider`"
|
||||||
|
)
|
||||||
|
public interface ConnectionProviderLogger extends BasicLogger {
|
||||||
|
String LOGGER_NAME = SubSystemLogging.BASE + ".connections.provider";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static access to the logging instance
|
||||||
|
*/
|
||||||
|
ConnectionProviderLogger INSTANCE = Logger.getMessageLogger(
|
||||||
|
ConnectionProviderLogger.class,
|
||||||
|
LOGGER_NAME
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@LogMessage(level = INFO)
|
||||||
|
@Message(
|
||||||
|
value = "Database info:\n%s",
|
||||||
|
id = 10002001
|
||||||
|
)
|
||||||
|
void logConnectionDetails(DatabaseConnectionInfo databaseConnectionInfo);
|
||||||
|
}
|
|
@ -13,7 +13,9 @@ import java.util.Map;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
import org.hibernate.service.spi.Stoppable;
|
import org.hibernate.service.spi.Stoppable;
|
||||||
|
@ -45,6 +47,8 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura
|
||||||
*/
|
*/
|
||||||
private HikariDataSource hds = null;
|
private HikariDataSource hds = null;
|
||||||
|
|
||||||
|
private DatabaseConnectionInfo dbinfo;
|
||||||
|
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
// Configurable
|
// Configurable
|
||||||
// *************************************************************************
|
// *************************************************************************
|
||||||
|
@ -57,6 +61,13 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura
|
||||||
hcfg = HikariConfigurationUtil.loadConfiguration( props );
|
hcfg = HikariConfigurationUtil.loadConfiguration( props );
|
||||||
hds = new HikariDataSource( hcfg );
|
hds = new HikariDataSource( hcfg );
|
||||||
|
|
||||||
|
dbinfo = new DatabaseConnectionInfoImpl()
|
||||||
|
.setDBUrl( hcfg.getJdbcUrl() )
|
||||||
|
.setDBDriverName( hcfg.getDriverClassName() )
|
||||||
|
.setDBAutoCommitMode( Boolean.toString( hcfg.isAutoCommit() ) )
|
||||||
|
.setDBIsolationLevel( hcfg.getTransactionIsolation() )
|
||||||
|
.setDBMinPoolSize( String.valueOf(hcfg.getMinimumIdle()) )
|
||||||
|
.setDBMaxPoolSize( String.valueOf(hcfg.getMaximumPoolSize()) );
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
throw new HibernateException( e );
|
throw new HibernateException( e );
|
||||||
|
@ -84,6 +95,11 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return dbinfo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
||||||
return ConnectionProvider.class.equals( unwrapType )
|
return ConnectionProvider.class.equals( unwrapType )
|
||||||
|
|
|
@ -20,13 +20,16 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.cfg.JdbcSettings;
|
import org.hibernate.cfg.JdbcSettings;
|
||||||
import org.hibernate.cfg.ProxoolSettings;
|
import org.hibernate.cfg.ProxoolSettings;
|
||||||
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
import org.hibernate.service.spi.Stoppable;
|
import org.hibernate.service.spi.Stoppable;
|
||||||
|
|
||||||
|
import org.logicalcobwebs.proxool.ConnectionPoolDefinitionIF;
|
||||||
import org.logicalcobwebs.proxool.ProxoolException;
|
import org.logicalcobwebs.proxool.ProxoolException;
|
||||||
import org.logicalcobwebs.proxool.ProxoolFacade;
|
import org.logicalcobwebs.proxool.ProxoolFacade;
|
||||||
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
|
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
|
||||||
|
@ -61,6 +64,8 @@ public class ProxoolConnectionProvider
|
||||||
|
|
||||||
private ClassLoaderService classLoaderService;
|
private ClassLoaderService classLoaderService;
|
||||||
|
|
||||||
|
private DatabaseConnectionInfo dbInfo;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
// get a connection from the pool (through DriverManager, cfr. Proxool doc)
|
// get a connection from the pool (through DriverManager, cfr. Proxool doc)
|
||||||
|
@ -115,8 +120,9 @@ public class ProxoolConnectionProvider
|
||||||
final String propFile = (String) props.get( ProxoolSettings.PROXOOL_PROPERTIES );
|
final String propFile = (String) props.get( ProxoolSettings.PROXOOL_PROPERTIES );
|
||||||
final String externalConfig = (String) props.get( ProxoolSettings.PROXOOL_EXISTING_POOL );
|
final String externalConfig = (String) props.get( ProxoolSettings.PROXOOL_EXISTING_POOL );
|
||||||
|
|
||||||
|
String proxoolPoolAlias;
|
||||||
// Default the Proxool alias setting
|
// Default the Proxool alias setting
|
||||||
proxoolAlias = (String) props.get( ProxoolSettings.PROXOOL_POOL_ALIAS );
|
proxoolAlias = proxoolPoolAlias = (String) props.get( ProxoolSettings.PROXOOL_POOL_ALIAS );
|
||||||
|
|
||||||
// Configured outside of Hibernate (i.e. Servlet container, or Java Bean Container
|
// Configured outside of Hibernate (i.e. Servlet container, or Java Bean Container
|
||||||
// already has Proxool pools running, and this provider is to just borrow one of these
|
// already has Proxool pools running, and this provider is to just borrow one of these
|
||||||
|
@ -188,10 +194,22 @@ public class ProxoolConnectionProvider
|
||||||
|
|
||||||
// Remember Isolation level
|
// Remember Isolation level
|
||||||
isolation = ConnectionProviderInitiator.extractIsolation( props );
|
isolation = ConnectionProviderInitiator.extractIsolation( props );
|
||||||
PROXOOL_MESSAGE_LOGGER.jdbcIsolationLevel( ConnectionProviderInitiator.toIsolationNiceName( isolation ) );
|
|
||||||
|
|
||||||
autocommit = getBoolean( JdbcSettings.AUTOCOMMIT, props );
|
autocommit = getBoolean( JdbcSettings.AUTOCOMMIT, props );
|
||||||
PROXOOL_MESSAGE_LOGGER.autoCommitMode( autocommit );
|
|
||||||
|
try {
|
||||||
|
ConnectionPoolDefinitionIF cpd = ProxoolFacade.getConnectionPoolDefinition( proxoolPoolAlias );
|
||||||
|
dbInfo = new DatabaseConnectionInfoImpl()
|
||||||
|
.setDBUrl( cpd.getUrl() )
|
||||||
|
.setDBDriverName( cpd.getDriver() )
|
||||||
|
.setDBIsolationLevel( ConnectionProviderInitiator.toIsolationNiceName(isolation) )
|
||||||
|
.setDBAutoCommitMode( Boolean.toString(autocommit) )
|
||||||
|
.setDBMinPoolSize( String.valueOf(cpd.getMinimumConnectionCount()) )
|
||||||
|
.setDBMaxPoolSize( String.valueOf(cpd.getMaximumConnectionCount()) );
|
||||||
|
}
|
||||||
|
catch (ProxoolException e) {
|
||||||
|
PROXOOL_MESSAGE_LOGGER.warn( "Error while obtaining the database pool information", e );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Reader getConfigStreamReader(String resource) {
|
private Reader getConfigStreamReader(String resource) {
|
||||||
|
@ -240,6 +258,11 @@ public class ProxoolConnectionProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return dbInfo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release all resources held by this provider.
|
* Release all resources held by this provider.
|
||||||
*
|
*
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Map;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||||
|
@ -103,6 +104,11 @@ public class ConnectionProviderDelegate implements
|
||||||
return connectionProvider.supportsAggressiveRelease();
|
return connectionProvider.supportsAggressiveRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return connectionProvider.getDatabaseConnectionInfo();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
||||||
return connectionProvider.isUnwrappableAs( unwrapType );
|
return connectionProvider.isUnwrappableAs( unwrapType );
|
||||||
|
|
|
@ -56,6 +56,7 @@ import org.hibernate.cfg.Environment;
|
||||||
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.internal.build.AllowSysOut;
|
import org.hibernate.internal.build.AllowSysOut;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||||
|
@ -178,6 +179,11 @@ public class JtaAwareConnectionProviderImpl implements ConnectionProvider, Confi
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return delegate.getDatabaseConnectionInfo();
|
||||||
|
}
|
||||||
|
|
||||||
protected Transaction findCurrentTransaction() {
|
protected Transaction findCurrentTransaction() {
|
||||||
try {
|
try {
|
||||||
return TestingJtaPlatformImpl.transactionManager().getTransaction();
|
return TestingJtaPlatformImpl.transactionManager().getTransaction();
|
||||||
|
|
|
@ -20,7 +20,9 @@ import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
|
@ -46,6 +48,8 @@ public class UCPConnectionProvider implements ConnectionProvider, Configurable,
|
||||||
private boolean autoCommit;
|
private boolean autoCommit;
|
||||||
private Integer isolation;
|
private Integer isolation;
|
||||||
|
|
||||||
|
private DatabaseConnectionInfo dbInfo;
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public void configure(Map props) throws HibernateException {
|
public void configure(Map props) throws HibernateException {
|
||||||
|
@ -60,6 +64,14 @@ public class UCPConnectionProvider implements ConnectionProvider, Configurable,
|
||||||
ucpDS = PoolDataSourceFactory.getPoolDataSource();
|
ucpDS = PoolDataSourceFactory.getPoolDataSource();
|
||||||
Properties ucpProps = getConfiguration(props);
|
Properties ucpProps = getConfiguration(props);
|
||||||
configureDataSource(ucpDS, ucpProps);
|
configureDataSource(ucpDS, ucpProps);
|
||||||
|
|
||||||
|
dbInfo = new DatabaseConnectionInfoImpl()
|
||||||
|
.setDBUrl( ucpDS.getURL() )
|
||||||
|
.setDBDriverName( ucpDS.getConnectionFactoryClassName() )
|
||||||
|
.setDBAutoCommitMode( Boolean.toString( autoCommit ) )
|
||||||
|
.setDBIsolationLevel( isolation != null ? ConnectionProviderInitiator.toIsolationConnectionConstantName( isolation ) : null )
|
||||||
|
.setDBMinPoolSize( String.valueOf(ucpDS.getMinPoolSize()) )
|
||||||
|
.setDBMaxPoolSize( String.valueOf(ucpDS.getMaxPoolSize()) );
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
LOGGER.debug( "oracle UCP Configuration failed" );
|
LOGGER.debug( "oracle UCP Configuration failed" );
|
||||||
|
@ -183,6 +195,11 @@ public class UCPConnectionProvider implements ConnectionProvider, Configurable,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return dbInfo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public boolean isUnwrappableAs(Class unwrapType) {
|
public boolean isUnwrappableAs(Class unwrapType) {
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
|
|
||||||
package org.hibernate.vibur.internal;
|
package org.hibernate.vibur.internal;
|
||||||
|
|
||||||
|
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
|
||||||
import org.hibernate.service.UnknownUnwrapTypeException;
|
import org.hibernate.service.UnknownUnwrapTypeException;
|
||||||
import org.hibernate.service.spi.Configurable;
|
import org.hibernate.service.spi.Configurable;
|
||||||
import org.hibernate.service.spi.Stoppable;
|
import org.hibernate.service.spi.Stoppable;
|
||||||
|
@ -50,10 +52,20 @@ public class ViburDBCPConnectionProvider implements ConnectionProvider, Configur
|
||||||
|
|
||||||
private ViburDBCPDataSource dataSource = null;
|
private ViburDBCPDataSource dataSource = null;
|
||||||
|
|
||||||
|
private DatabaseConnectionInfo dbInfo;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(Map<String, Object> configurationValues) {
|
public void configure(Map<String, Object> configurationValues) {
|
||||||
dataSource = new ViburDBCPDataSource( transform( configurationValues ) );
|
dataSource = new ViburDBCPDataSource( transform( configurationValues ) );
|
||||||
dataSource.start();
|
dataSource.start();
|
||||||
|
|
||||||
|
dbInfo = new DatabaseConnectionInfoImpl()
|
||||||
|
.setDBUrl( dataSource.getJdbcUrl() )
|
||||||
|
.setDBDriverName( dataSource.getDriverClassName() )
|
||||||
|
.setDBAutoCommitMode( String.valueOf(dataSource.getDefaultAutoCommit()) )
|
||||||
|
.setDBIsolationLevel( dataSource.getDefaultTransactionIsolation() )
|
||||||
|
.setDBMinPoolSize( String.valueOf(dataSource.getPoolInitialSize()) )
|
||||||
|
.setDBMaxPoolSize( String.valueOf(dataSource.getPoolMaxSize()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -79,6 +91,11 @@ public class ViburDBCPConnectionProvider implements ConnectionProvider, Configur
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DatabaseConnectionInfo getDatabaseConnectionInfo() {
|
||||||
|
return dbInfo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
public boolean isUnwrappableAs(Class<?> unwrapType) {
|
||||||
return ConnectionProvider.class.equals( unwrapType )
|
return ConnectionProvider.class.equals( unwrapType )
|
||||||
|
@ -103,6 +120,7 @@ public class ViburDBCPConnectionProvider implements ConnectionProvider, Configur
|
||||||
if ( driverClassName != null ) {
|
if ( driverClassName != null ) {
|
||||||
result.setProperty( "driverClassName", driverClassName );
|
result.setProperty( "driverClassName", driverClassName );
|
||||||
}
|
}
|
||||||
|
|
||||||
String jdbcUrl = (String) configurationValues.get( URL );
|
String jdbcUrl = (String) configurationValues.get( URL );
|
||||||
if ( jdbcUrl != null ) {
|
if ( jdbcUrl != null ) {
|
||||||
result.setProperty( "jdbcUrl", jdbcUrl );
|
result.setProperty( "jdbcUrl", jdbcUrl );
|
||||||
|
@ -133,7 +151,6 @@ public class ViburDBCPConnectionProvider implements ConnectionProvider, Configur
|
||||||
result.setProperty( key, (String) entry.getValue() );
|
result.setProperty( key, (String) entry.getValue() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue