HHH-9503 - Consistently accept numeric value or Connection constant field name for configuring transaction isolation
This commit is contained in:
parent
1d61210826
commit
d99fb4f5dc
|
@ -197,15 +197,8 @@ public class C3P0ConnectionProvider
|
|||
throw new HibernateException( LOG.unableToInstantiateC3p0ConnectionPool(), e );
|
||||
}
|
||||
|
||||
final String i = (String) props.get( Environment.ISOLATION );
|
||||
if ( StringHelper.isEmpty( i ) ) {
|
||||
isolation = null;
|
||||
}
|
||||
else {
|
||||
isolation = Integer.valueOf( i );
|
||||
LOG.jdbcIsolationLevel( Environment.isolationLevelToString( isolation ) );
|
||||
}
|
||||
|
||||
isolation = ConnectionProviderInitiator.extractIsolation( props );
|
||||
LOG.jdbcIsolationLevel( ConnectionProviderInitiator.toIsolationNiceName( isolation ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.test.c3p0;
|
||||
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.c3p0.internal.C3P0ConnectionProvider;
|
||||
import org.hibernate.connection.BaseTransactionIsolationConfigTest;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class C3p0TransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest {
|
||||
private StandardServiceRegistry ssr;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ssr = new StandardServiceRegistryBuilder().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionProvider getConnectionProviderUnderTest() {
|
||||
C3P0ConnectionProvider provider = new C3P0ConnectionProvider();
|
||||
provider.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
return provider;
|
||||
}
|
||||
}
|
|
@ -8,9 +8,7 @@ package org.hibernate.cfg;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
@ -18,6 +16,7 @@ import java.util.Properties;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Version;
|
||||
import org.hibernate.bytecode.spi.BytecodeProvider;
|
||||
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.ConfigHelper;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
|
@ -160,7 +159,6 @@ public final class Environment implements AvailableSettings {
|
|||
private static final boolean JVM_HAS_TIMESTAMP_BUG;
|
||||
|
||||
private static final Properties GLOBAL_PROPERTIES;
|
||||
private static final Map<Integer,String> ISOLATION_LEVELS;
|
||||
|
||||
private static final Map OBSOLETE_PROPERTIES = new HashMap();
|
||||
private static final Map RENAMED_PROPERTIES = new HashMap();
|
||||
|
@ -189,13 +187,6 @@ public final class Environment implements AvailableSettings {
|
|||
static {
|
||||
Version.logVersion();
|
||||
|
||||
Map<Integer,String> temp = new HashMap<Integer,String>();
|
||||
temp.put( Connection.TRANSACTION_NONE, "NONE" );
|
||||
temp.put( Connection.TRANSACTION_READ_UNCOMMITTED, "READ_UNCOMMITTED" );
|
||||
temp.put( Connection.TRANSACTION_READ_COMMITTED, "READ_COMMITTED" );
|
||||
temp.put( Connection.TRANSACTION_REPEATABLE_READ, "REPEATABLE_READ" );
|
||||
temp.put( Connection.TRANSACTION_SERIALIZABLE, "SERIALIZABLE" );
|
||||
ISOLATION_LEVELS = Collections.unmodifiableMap( temp );
|
||||
GLOBAL_PROPERTIES = new Properties();
|
||||
//Set USE_REFLECTION_OPTIMIZER to false to fix HHH-227
|
||||
GLOBAL_PROPERTIES.setProperty( USE_REFLECTION_OPTIMIZER, Boolean.FALSE.toString() );
|
||||
|
@ -314,14 +305,11 @@ public final class Environment implements AvailableSettings {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the name of a JDBC transaction isolation level
|
||||
*
|
||||
* @see java.sql.Connection
|
||||
* @param isolation as defined by <tt>java.sql.Connection</tt>
|
||||
* @return a human-readable name
|
||||
* @deprecated Use {@link ConnectionProviderInitiator#toIsolationNiceName} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static String isolationLevelToString(int isolation) {
|
||||
return ISOLATION_LEVELS.get( isolation );
|
||||
return ConnectionProviderInitiator.toIsolationNiceName( isolation );
|
||||
}
|
||||
|
||||
public static BytecodeProvider buildBytecodeProvider(Properties properties) {
|
||||
|
|
|
@ -9,21 +9,23 @@ package org.hibernate.engine.jdbc.connections.internal;
|
|||
import java.beans.BeanInfo;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MultiTenancyStrategy;
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.log.DeprecationLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.beans.BeanInfoHelper;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
|
@ -108,7 +110,7 @@ public class ConnectionProviderInitiator implements StandardServiceInitiator<Con
|
|||
if ( providerName != null ) {
|
||||
connectionProvider = instantiateExplicitConnectionProvider( providerName, strategySelector );
|
||||
}
|
||||
else if ( configurationValues.get( Environment.DATASOURCE ) != null ) {
|
||||
else if ( configurationValues.get( AvailableSettings.DATASOURCE ) != null ) {
|
||||
connectionProvider = new DatasourceConnectionProviderImpl();
|
||||
}
|
||||
|
||||
|
@ -131,7 +133,7 @@ public class ConnectionProviderInitiator implements StandardServiceInitiator<Con
|
|||
}
|
||||
|
||||
if ( connectionProvider == null ) {
|
||||
if ( configurationValues.get( Environment.URL ) != null ) {
|
||||
if ( configurationValues.get( AvailableSettings.URL ) != null ) {
|
||||
connectionProvider = new DriverManagerConnectionProviderImpl();
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +171,7 @@ public class ConnectionProviderInitiator implements StandardServiceInitiator<Con
|
|||
}
|
||||
|
||||
private String getConfiguredConnectionProviderName( Map configurationValues ) {
|
||||
String providerName = (String) configurationValues.get( Environment.CONNECTION_PROVIDER );
|
||||
String providerName = (String) configurationValues.get( AvailableSettings.CONNECTION_PROVIDER );
|
||||
if ( LEGACY_CONNECTION_PROVIDER_MAPPING.containsKey( providerName ) ) {
|
||||
final String actualProviderName = LEGACY_CONNECTION_PROVIDER_MAPPING.get( providerName );
|
||||
DeprecationLogger.DEPRECATION_LOGGER.connectionProviderClassDeprecated( providerName, actualProviderName );
|
||||
|
@ -274,15 +276,15 @@ public class ConnectionProviderInitiator implements StandardServiceInitiator<Con
|
|||
}
|
||||
final String key = (String) entry.getKey();
|
||||
final String value = (String) entry.getValue();
|
||||
if ( key.startsWith( Environment.CONNECTION_PREFIX ) ) {
|
||||
if ( key.startsWith( AvailableSettings.CONNECTION_PREFIX ) ) {
|
||||
if ( SPECIAL_PROPERTIES.contains( key ) ) {
|
||||
if ( Environment.USER.equals( key ) ) {
|
||||
if ( AvailableSettings.USER.equals( key ) ) {
|
||||
result.setProperty( "user", value );
|
||||
}
|
||||
}
|
||||
else {
|
||||
result.setProperty(
|
||||
key.substring( Environment.CONNECTION_PREFIX.length() + 1 ),
|
||||
key.substring( AvailableSettings.CONNECTION_PREFIX.length() + 1 ),
|
||||
value
|
||||
);
|
||||
}
|
||||
|
@ -296,15 +298,45 @@ public class ConnectionProviderInitiator implements StandardServiceInitiator<Con
|
|||
|
||||
private static final Set<String> SPECIAL_PROPERTIES;
|
||||
|
||||
private static final Map<String,Integer> ISOLATION_VALUE_MAP;
|
||||
private static final Map<Integer, String> ISOLATION_VALUE_CONSTANT_NAME_MAP;
|
||||
private static final Map<Integer, String> ISOLATION_VALUE_NICE_NAME_MAP;
|
||||
|
||||
static {
|
||||
SPECIAL_PROPERTIES = new HashSet<String>();
|
||||
SPECIAL_PROPERTIES.add( Environment.DATASOURCE );
|
||||
SPECIAL_PROPERTIES.add( Environment.URL );
|
||||
SPECIAL_PROPERTIES.add( Environment.CONNECTION_PROVIDER );
|
||||
SPECIAL_PROPERTIES.add( Environment.POOL_SIZE );
|
||||
SPECIAL_PROPERTIES.add( Environment.ISOLATION );
|
||||
SPECIAL_PROPERTIES.add( Environment.DRIVER );
|
||||
SPECIAL_PROPERTIES.add( Environment.USER );
|
||||
SPECIAL_PROPERTIES.add( AvailableSettings.DATASOURCE );
|
||||
SPECIAL_PROPERTIES.add( AvailableSettings.URL );
|
||||
SPECIAL_PROPERTIES.add( AvailableSettings.CONNECTION_PROVIDER );
|
||||
SPECIAL_PROPERTIES.add( AvailableSettings.POOL_SIZE );
|
||||
SPECIAL_PROPERTIES.add( AvailableSettings.ISOLATION );
|
||||
SPECIAL_PROPERTIES.add( AvailableSettings.DRIVER );
|
||||
SPECIAL_PROPERTIES.add( AvailableSettings.USER );
|
||||
|
||||
ISOLATION_VALUE_MAP = new ConcurrentHashMap<String, Integer>();
|
||||
ISOLATION_VALUE_MAP.put( "TRANSACTION_NONE", Connection.TRANSACTION_NONE );
|
||||
ISOLATION_VALUE_MAP.put( "NONE", Connection.TRANSACTION_NONE );
|
||||
ISOLATION_VALUE_MAP.put( "TRANSACTION_READ_UNCOMMITTED", Connection.TRANSACTION_READ_UNCOMMITTED );
|
||||
ISOLATION_VALUE_MAP.put( "READ_UNCOMMITTED", Connection.TRANSACTION_READ_UNCOMMITTED );
|
||||
ISOLATION_VALUE_MAP.put( "TRANSACTION_READ_COMMITTED", Connection.TRANSACTION_READ_COMMITTED );
|
||||
ISOLATION_VALUE_MAP.put( "READ_COMMITTED", Connection.TRANSACTION_READ_COMMITTED );
|
||||
ISOLATION_VALUE_MAP.put( "TRANSACTION_REPEATABLE_READ", Connection.TRANSACTION_REPEATABLE_READ );
|
||||
ISOLATION_VALUE_MAP.put( "REPEATABLE_READ", Connection.TRANSACTION_REPEATABLE_READ );
|
||||
ISOLATION_VALUE_MAP.put( "TRANSACTION_SERIALIZABLE", Connection.TRANSACTION_SERIALIZABLE );
|
||||
ISOLATION_VALUE_MAP.put( "SERIALIZABLE", Connection.TRANSACTION_SERIALIZABLE );
|
||||
|
||||
ISOLATION_VALUE_CONSTANT_NAME_MAP = new ConcurrentHashMap<Integer, String>();
|
||||
ISOLATION_VALUE_CONSTANT_NAME_MAP.put( Connection.TRANSACTION_NONE, "TRANSACTION_NONE" );
|
||||
ISOLATION_VALUE_CONSTANT_NAME_MAP.put( Connection.TRANSACTION_READ_UNCOMMITTED, "TRANSACTION_READ_UNCOMMITTED" );
|
||||
ISOLATION_VALUE_CONSTANT_NAME_MAP.put( Connection.TRANSACTION_READ_COMMITTED, "TRANSACTION_READ_COMMITTED" );
|
||||
ISOLATION_VALUE_CONSTANT_NAME_MAP.put( Connection.TRANSACTION_REPEATABLE_READ, "TRANSACTION_REPEATABLE_READ" );
|
||||
ISOLATION_VALUE_CONSTANT_NAME_MAP.put( Connection.TRANSACTION_SERIALIZABLE, "TRANSACTION_SERIALIZABLE" );
|
||||
|
||||
ISOLATION_VALUE_NICE_NAME_MAP = new ConcurrentHashMap<Integer, String>();
|
||||
ISOLATION_VALUE_NICE_NAME_MAP.put( Connection.TRANSACTION_NONE, "NONE" );
|
||||
ISOLATION_VALUE_NICE_NAME_MAP.put( Connection.TRANSACTION_READ_UNCOMMITTED, "READ_UNCOMMITTED" );
|
||||
ISOLATION_VALUE_NICE_NAME_MAP.put( Connection.TRANSACTION_READ_COMMITTED, "READ_COMMITTED" );
|
||||
ISOLATION_VALUE_NICE_NAME_MAP.put( Connection.TRANSACTION_REPEATABLE_READ, "REPEATABLE_READ" );
|
||||
ISOLATION_VALUE_NICE_NAME_MAP.put( Connection.TRANSACTION_SERIALIZABLE, "SERIALIZABLE" );
|
||||
}
|
||||
|
||||
// Connection properties (map value) that automatically need set if the
|
||||
|
@ -315,6 +347,81 @@ public class ConnectionProviderInitiator implements StandardServiceInitiator<Con
|
|||
static {
|
||||
CONDITIONAL_PROPERTIES = new HashMap<String, String>();
|
||||
// Oracle requires that includeSynonyms=true in order for getColumns to work using a table synonym name.
|
||||
CONDITIONAL_PROPERTIES.put( Environment.ENABLE_SYNONYMS, "includeSynonyms" );
|
||||
CONDITIONAL_PROPERTIES.put( AvailableSettings.ENABLE_SYNONYMS, "includeSynonyms" );
|
||||
}
|
||||
|
||||
public static Integer extractIsolation(Map settings) {
|
||||
return interpretIsolation( settings.get( AvailableSettings.ISOLATION ) );
|
||||
}
|
||||
|
||||
public static Integer interpretIsolation(Object setting) {
|
||||
if ( setting == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( Number.class.isInstance( setting ) ) {
|
||||
return ( (Number) setting ).intValue();
|
||||
}
|
||||
|
||||
final String settingAsString = setting.toString();
|
||||
if ( StringHelper.isEmpty( settingAsString ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( ISOLATION_VALUE_MAP.containsKey( settingAsString ) ) {
|
||||
return ISOLATION_VALUE_MAP.get( settingAsString );
|
||||
}
|
||||
|
||||
// it could be a String representation of the isolation numeric value...
|
||||
try {
|
||||
return Integer.valueOf( settingAsString );
|
||||
}
|
||||
catch (NumberFormatException ignore) {
|
||||
}
|
||||
|
||||
throw new HibernateException( "Could not interpret transaction isolation setting [" + setting + "]" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Connection} constant name corresponding to the given isolation.
|
||||
*
|
||||
* @param isolation The transaction isolation numeric value.
|
||||
*
|
||||
* @return The corresponding Connection constant name.
|
||||
*
|
||||
* @throws HibernateException If the given isolation does not map to JDBC standard isolation
|
||||
*
|
||||
* @see #toIsolationNiceName
|
||||
*/
|
||||
public static String toIsolationConnectionConstantName(Integer isolation) {
|
||||
final String name = ISOLATION_VALUE_CONSTANT_NAME_MAP.get( isolation );
|
||||
if ( name == null ) {
|
||||
throw new HibernateException(
|
||||
"Could not convert isolation value [" + isolation + "] to java.sql.Connection constant name"
|
||||
);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of a JDBC transaction isolation level
|
||||
*
|
||||
* @param isolation The transaction isolation numeric value.
|
||||
*
|
||||
* @return a nice human-readable name
|
||||
*
|
||||
* @see #toIsolationConnectionConstantName
|
||||
*/
|
||||
public static String toIsolationNiceName(Integer isolation) {
|
||||
String name = null;
|
||||
|
||||
if ( isolation != null ) {
|
||||
name = ISOLATION_VALUE_NICE_NAME_MAP.get( isolation );
|
||||
}
|
||||
|
||||
if ( name == null ) {
|
||||
name = "<unknown>";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,9 +163,9 @@ public class DriverManagerConnectionProviderImpl
|
|||
log.autoCommitMode( autoCommit );
|
||||
connectionCreatorBuilder.setAutoCommit( autoCommit );
|
||||
|
||||
final Integer isolation = ConfigurationHelper.getInteger( AvailableSettings.ISOLATION, configurationValues );
|
||||
final Integer isolation = ConnectionProviderInitiator.extractIsolation( configurationValues );
|
||||
if ( isolation != null ) {
|
||||
log.jdbcIsolationLevel( Environment.isolationLevelToString( isolation ) );
|
||||
log.jdbcIsolationLevel( ConnectionProviderInitiator.toIsolationNiceName( isolation ) );
|
||||
}
|
||||
connectionCreatorBuilder.setIsolation( isolation );
|
||||
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* 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.connection;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.service.spi.Configurable;
|
||||
import org.hibernate.service.spi.Startable;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class BaseTransactionIsolationConfigTest extends BaseUnitTestCase {
|
||||
protected abstract ConnectionProvider getConnectionProviderUnderTest();
|
||||
|
||||
protected void augmentConfigurationSettings(Properties properties) {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettingIsolationAsNumeric() throws Exception {
|
||||
Properties properties = Environment.getProperties();
|
||||
augmentConfigurationSettings( properties );
|
||||
properties.put( AvailableSettings.ISOLATION, Connection.TRANSACTION_SERIALIZABLE );
|
||||
|
||||
ConnectionProvider provider = getConnectionProviderUnderTest();
|
||||
|
||||
try {
|
||||
( (Configurable) provider ).configure( properties );
|
||||
|
||||
if ( Startable.class.isInstance( provider ) ) {
|
||||
( (Startable) provider ).start();
|
||||
}
|
||||
|
||||
Connection connection = provider.getConnection();
|
||||
assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() );
|
||||
provider.closeConnection( connection );
|
||||
}
|
||||
finally {
|
||||
( (Stoppable) provider ).stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettingIsolationAsNumericString() throws Exception {
|
||||
Properties properties = Environment.getProperties();
|
||||
augmentConfigurationSettings( properties );
|
||||
properties.put( AvailableSettings.ISOLATION, Integer.toString( Connection.TRANSACTION_SERIALIZABLE ) );
|
||||
|
||||
ConnectionProvider provider = getConnectionProviderUnderTest();
|
||||
|
||||
try {
|
||||
( (Configurable) provider ).configure( properties );
|
||||
|
||||
if ( Startable.class.isInstance( provider ) ) {
|
||||
( (Startable) provider ).start();
|
||||
}
|
||||
|
||||
Connection connection = provider.getConnection();
|
||||
assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() );
|
||||
provider.closeConnection( connection );
|
||||
}
|
||||
finally {
|
||||
( (Stoppable) provider ).stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettingIsolationAsName() throws Exception {
|
||||
Properties properties = Environment.getProperties();
|
||||
augmentConfigurationSettings( properties );
|
||||
properties.put( AvailableSettings.ISOLATION, "TRANSACTION_SERIALIZABLE" );
|
||||
|
||||
ConnectionProvider provider = getConnectionProviderUnderTest();
|
||||
|
||||
try {
|
||||
( (Configurable) provider ).configure( properties );
|
||||
|
||||
if ( Startable.class.isInstance( provider ) ) {
|
||||
( (Startable) provider ).start();
|
||||
}
|
||||
|
||||
Connection connection = provider.getConnection();
|
||||
assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() );
|
||||
provider.closeConnection( connection );
|
||||
}
|
||||
finally {
|
||||
( (Stoppable) provider ).stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettingIsolationAsNameAlt() throws Exception {
|
||||
Properties properties = Environment.getProperties();
|
||||
augmentConfigurationSettings( properties );
|
||||
properties.put( AvailableSettings.ISOLATION, "SERIALIZABLE" );
|
||||
|
||||
ConnectionProvider provider = getConnectionProviderUnderTest();
|
||||
|
||||
try {
|
||||
( (Configurable) provider ).configure( properties );
|
||||
|
||||
if ( Startable.class.isInstance( provider ) ) {
|
||||
( (Startable) provider ).start();
|
||||
}
|
||||
|
||||
Connection connection = provider.getConnection();
|
||||
assertEquals( Connection.TRANSACTION_SERIALIZABLE, connection.getTransactionIsolation() );
|
||||
provider.closeConnection( connection );
|
||||
}
|
||||
finally {
|
||||
( (Stoppable) provider ).stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* 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.connection;
|
||||
|
||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class DriverManagerConnectionProviderTransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest {
|
||||
@Override
|
||||
protected ConnectionProvider getConnectionProviderUnderTest() {
|
||||
return new DriverManagerConnectionProviderImpl();
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ dependencies {
|
|||
compile project( ':hibernate-core' )
|
||||
compile( libraries.hikaricp )
|
||||
testCompile project( ':hibernate-testing' )
|
||||
testRuntime libraries.slf4j_log4j
|
||||
}
|
||||
|
||||
mavenPom {
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
|
||||
|
@ -22,7 +23,6 @@ import com.zaxxer.hikari.HikariConfig;
|
|||
* @author Brett Meyer
|
||||
*/
|
||||
public class HikariConfigurationUtil {
|
||||
|
||||
public static final String CONFIG_PREFIX = "hibernate.hikari.";
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,6 @@ public class HikariConfigurationUtil {
|
|||
@SuppressWarnings("rawtypes")
|
||||
public static HikariConfig loadConfiguration(Map props) {
|
||||
Properties hikariProps = new Properties();
|
||||
copyProperty( AvailableSettings.ISOLATION, props, "transactionIsolation", hikariProps );
|
||||
copyProperty( AvailableSettings.AUTOCOMMIT, props, "autoCommit", hikariProps );
|
||||
|
||||
copyProperty( AvailableSettings.DRIVER, props, "driverClassName", hikariProps );
|
||||
|
@ -42,6 +41,8 @@ public class HikariConfigurationUtil {
|
|||
copyProperty( AvailableSettings.USER, props, "username", hikariProps );
|
||||
copyProperty( AvailableSettings.PASS, props, "password", hikariProps );
|
||||
|
||||
copyIsolationSetting( props, hikariProps );
|
||||
|
||||
for ( Object keyo : props.keySet() ) {
|
||||
if ( !(keyo instanceof String) ) {
|
||||
continue;
|
||||
|
@ -61,4 +62,15 @@ public class HikariConfigurationUtil {
|
|||
dst.setProperty( dstKey, (String) src.get( srcKey ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyIsolationSetting(Map props, Properties hikariProps) {
|
||||
final Integer isolation = ConnectionProviderInitiator.extractIsolation( props );
|
||||
if ( isolation != null ) {
|
||||
hikariProps.put(
|
||||
"transactionIsolation",
|
||||
ConnectionProviderInitiator.toIsolationConnectionConstantName( isolation )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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.test.hikaricp;
|
||||
|
||||
import org.hibernate.connection.BaseTransactionIsolationConfigTest;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.hikaricp.internal.HikariCPConnectionProvider;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class HikariTransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest {
|
||||
@Override
|
||||
protected ConnectionProvider getConnectionProviderUnderTest() {
|
||||
return new HikariCPConnectionProvider();
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ import java.util.Properties;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
|
@ -188,10 +189,8 @@ public class ProxoolConnectionProvider
|
|||
}
|
||||
|
||||
// Remember Isolation level
|
||||
isolation = ConfigurationHelper.getInteger( Environment.ISOLATION, props );
|
||||
if ( isolation != null ) {
|
||||
LOG.jdbcIsolationLevel( Environment.isolationLevelToString( isolation.intValue() ) );
|
||||
}
|
||||
isolation = ConnectionProviderInitiator.extractIsolation( props );
|
||||
LOG.jdbcIsolationLevel( ConnectionProviderInitiator.toIsolationNiceName( isolation ) );
|
||||
|
||||
autocommit = ConfigurationHelper.getBoolean( Environment.AUTOCOMMIT, props );
|
||||
LOG.autoCommmitMode( autocommit );
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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.test.proxool;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.connection.BaseTransactionIsolationConfigTest;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.proxool.internal.ProxoolConnectionProvider;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ProxoolTransactionIsolationConfigTest extends BaseTransactionIsolationConfigTest {
|
||||
private Properties properties;
|
||||
private StandardServiceRegistry ssr;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String poolName = "pool-one";
|
||||
|
||||
properties = new Properties();
|
||||
properties.put( AvailableSettings.PROXOOL_POOL_ALIAS, poolName );
|
||||
properties.put( AvailableSettings.PROXOOL_PROPERTIES, poolName + ".properties" );
|
||||
|
||||
ssr = new StandardServiceRegistryBuilder()
|
||||
.applySettings( properties )
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionProvider getConnectionProviderUnderTest() {
|
||||
ProxoolConnectionProvider provider = new ProxoolConnectionProvider();
|
||||
provider.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
return provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void augmentConfigurationSettings(Properties properties) {
|
||||
super.augmentConfigurationSettings( properties );
|
||||
|
||||
properties.putAll( this.properties );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue