Fix issue #135 make get/setTransactionIsolation() fit proper bean pattern.

pull/140/head
Brett Wooldridge 11 years ago
parent 01d8119244
commit aff5c8ef9c

@ -36,6 +36,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zaxxer.hikari.proxy.JavassistProxyFactory;
import com.zaxxer.hikari.util.PoolUtilities;
import com.zaxxer.hikari.util.PropertyBeanSetter;
public class HikariConfig implements HikariConfigMBean
@ -82,7 +83,6 @@ public class HikariConfig implements HikariConfigMBean
private DataSource dataSource;
private Properties dataSourceProperties;
private IConnectionCustomizer customizer;
private int transactionIsolation;
private ThreadFactory threadFactory;
static {
@ -104,7 +104,6 @@ public class HikariConfig implements HikariConfigMBean
maxPoolSize = 10;
maxLifetime = MAX_LIFETIME;
isRecordMetrics = false;
transactionIsolation = -1;
metricsTrackerClassName = "com.zaxxer.hikari.metrics.CodaHaleMetricsTracker";
customizer = new IConnectionCustomizer() {
@Override
@ -597,9 +596,9 @@ public class HikariConfig implements HikariConfigMBean
this.poolName = poolName;
}
public int getTransactionIsolation()
public String getTransactionIsolation()
{
return transactionIsolation;
return transactionIsolationName;
}
/**
@ -702,14 +701,7 @@ public class HikariConfig implements HikariConfigMBean
}
if (transactionIsolationName != null) {
try {
Field field = Connection.class.getField(transactionIsolationName);
int level = field.getInt(null);
this.transactionIsolation = level;
}
catch (Exception e) {
throw new IllegalArgumentException("Invalid transaction isolation value: " + transactionIsolationName);
}
PoolUtilities.getTransactionIsolation(transactionIsolationName);
}
if (poolName == null) {

@ -53,6 +53,7 @@ import com.zaxxer.hikari.util.ConcurrentBag;
import com.zaxxer.hikari.util.ConcurrentBag.IBagStateListener;
import com.zaxxer.hikari.util.DefaultThreadFactory;
import com.zaxxer.hikari.util.DriverDataSource;
import com.zaxxer.hikari.util.PoolUtilities;
import com.zaxxer.hikari.util.PropertyBeanSetter;
/**
@ -129,7 +130,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
this.isRegisteredMbeans = configuration.isRegisterMbeans();
this.isJdbc4ConnectionTest = configuration.isJdbc4ConnectionTest();
this.leakDetectionThreshold = configuration.getLeakDetectionThreshold();
this.transactionIsolation = configuration.getTransactionIsolation();
this.transactionIsolation = PoolUtilities.getTransactionIsolation(configuration.getTransactionIsolation());
this.isRecordMetrics = configuration.isRecordMetrics();
this.metricsTracker = MetricsFactory.createMetricsTracker((isRecordMetrics ? configuration.getMetricsTrackerClassName()
: "com.zaxxer.hikari.metrics.MetricsTracker"), configuration.getPoolName());

@ -1,6 +1,7 @@
package com.zaxxer.hikari.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
@ -106,6 +107,21 @@ public final class PoolUtilities
}
}
public static int getTransactionIsolation(String transactionIsolationName)
{
if (transactionIsolationName != null) {
try {
Field field = Connection.class.getField(transactionIsolationName);
return field.getInt(null);
}
catch (Exception e) {
throw new IllegalArgumentException("Invalid transaction isolation value: " + transactionIsolationName);
}
}
return -1;
}
public static ThreadPoolExecutor createThreadPoolExecutor(final int queueSize, final String threadName, ThreadFactory threadFactory)
{
if (threadFactory == null) {

@ -6,6 +6,8 @@ import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Test;
import com.zaxxer.hikari.util.PoolUtilities;
public class ConnectionStateTest
{
@Test
@ -74,7 +76,7 @@ public class ConnectionStateTest
config.setTransactionIsolation("TRANSACTION_REPEATABLE_READ");
config.validate();
int transactionIsolation = config.getTransactionIsolation();
int transactionIsolation = PoolUtilities.getTransactionIsolation(config.getTransactionIsolation());
Assert.assertSame(Connection.TRANSACTION_REPEATABLE_READ, transactionIsolation);
}

@ -36,6 +36,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zaxxer.hikari.proxy.JavassistProxyFactory;
import com.zaxxer.hikari.util.PoolUtilities;
import com.zaxxer.hikari.util.PropertyBeanSetter;
public class HikariConfig implements HikariConfigMBean
@ -82,7 +83,6 @@ public class HikariConfig implements HikariConfigMBean
private DataSource dataSource;
private Properties dataSourceProperties;
private IConnectionCustomizer customizer;
private int transactionIsolation;
private ThreadFactory threadFactory;
static {
@ -104,7 +104,6 @@ public class HikariConfig implements HikariConfigMBean
maxPoolSize = 10;
maxLifetime = MAX_LIFETIME;
isRecordMetrics = false;
transactionIsolation = -1;
metricsTrackerClassName = "com.zaxxer.hikari.metrics.CodaHaleMetricsTracker";
customizer = new IConnectionCustomizer() {
@Override
@ -595,9 +594,9 @@ public class HikariConfig implements HikariConfigMBean
this.poolName = poolName;
}
public int getTransactionIsolation()
public String getTransactionIsolation()
{
return transactionIsolation;
return transactionIsolationName;
}
/**
@ -700,14 +699,7 @@ public class HikariConfig implements HikariConfigMBean
}
if (transactionIsolationName != null) {
try {
Field field = Connection.class.getField(transactionIsolationName);
int level = field.getInt(null);
this.transactionIsolation = level;
}
catch (Exception e) {
throw new IllegalArgumentException("Invalid transaction isolation value: " + transactionIsolationName);
}
PoolUtilities.getTransactionIsolation(transactionIsolationName);
}
if (poolName == null) {

@ -52,6 +52,7 @@ import com.zaxxer.hikari.util.ConcurrentBag;
import com.zaxxer.hikari.util.ConcurrentBag.IBagStateListener;
import com.zaxxer.hikari.util.DefaultThreadFactory;
import com.zaxxer.hikari.util.DriverDataSource;
import com.zaxxer.hikari.util.PoolUtilities;
import com.zaxxer.hikari.util.PropertyBeanSetter;
/**
@ -128,7 +129,7 @@ public final class HikariPool implements HikariPoolMBean, IBagStateListener
this.isRegisteredMbeans = configuration.isRegisterMbeans();
this.isJdbc4ConnectionTest = configuration.isJdbc4ConnectionTest();
this.leakDetectionThreshold = configuration.getLeakDetectionThreshold();
this.transactionIsolation = configuration.getTransactionIsolation();
this.transactionIsolation = PoolUtilities.getTransactionIsolation(configuration.getTransactionIsolation());
this.isRecordMetrics = configuration.isRecordMetrics();
this.metricsTracker = MetricsFactory.createMetricsTracker((isRecordMetrics ? configuration.getMetricsTrackerClassName()
: "com.zaxxer.hikari.metrics.MetricsTracker"), configuration.getPoolName());

@ -1,6 +1,7 @@
package com.zaxxer.hikari.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
@ -88,6 +89,21 @@ public final class PoolUtilities
}
}
public static int getTransactionIsolation(String transactionIsolationName)
{
if (transactionIsolationName != null) {
try {
Field field = Connection.class.getField(transactionIsolationName);
return field.getInt(null);
}
catch (Exception e) {
throw new IllegalArgumentException("Invalid transaction isolation value: " + transactionIsolationName);
}
}
return -1;
}
public static ThreadPoolExecutor createThreadPoolExecutor(final int queueSize, final String threadName, ThreadFactory threadFactory)
{
if (threadFactory == null) {

@ -6,6 +6,8 @@ import java.sql.SQLException;
import org.junit.Assert;
import org.junit.Test;
import com.zaxxer.hikari.util.PoolUtilities;
public class ConnectionStateTest
{
@Test
@ -74,7 +76,7 @@ public class ConnectionStateTest
config.setTransactionIsolation("TRANSACTION_REPEATABLE_READ");
config.validate();
int transactionIsolation = config.getTransactionIsolation();
int transactionIsolation = PoolUtilities.getTransactionIsolation(config.getTransactionIsolation());
Assert.assertSame(Connection.TRANSACTION_REPEATABLE_READ, transactionIsolation);
}

Loading…
Cancel
Save