Merge commit 'ace24b3b9cdff86c40ec2c90ab48a28f2e29a69e' into dev

* commit 'ace24b3b9cdff86c40ec2c90ab48a28f2e29a69e':
  Prevent race in close()
  Make sure temporary pool is shut down
  Fix some issues found by Idea inspections
  Reuse pool name
  Fix JavaDoc
  Use path API
pull/316/merge
Brett Wooldridge 10 years ago
commit d8954d92b6

@ -16,12 +16,13 @@
package com.zaxxer.hikari;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
@ -800,8 +801,8 @@ public class HikariConfig implements HikariConfigMBean
protected void loadProperties(String propertyFileName)
{
final File propFile = new File(propertyFileName);
try (final InputStream is = propFile.isFile() ? new FileInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName)) {
final Path propFile = Paths.get(propertyFileName);
try (final InputStream is = Files.isRegularFile(propFile) ? Files.newInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName)) {
if (is != null) {
Properties props = new Properties();
props.load(is);

@ -22,6 +22,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Wrapper;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.sql.DataSource;
@ -43,7 +44,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
{
private static final Logger LOGGER = LoggerFactory.getLogger(HikariDataSource.class);
private volatile boolean isShutdown;
private final AtomicBoolean isShutdown = new AtomicBoolean();
private final HikariPool fastPathPool;
private volatile HikariPool pool;
@ -78,7 +79,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
@Override
public Connection getConnection() throws SQLException
{
if (isShutdown) {
if (isShutdown.get()) {
throw new SQLException("Pool " + pool.getConfiguration().getPoolName() + " has been shutdown");
}
@ -142,6 +143,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
}
/** {@inheritDoc} */
@Override
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException
{
throw new SQLFeatureNotSupportedException();
@ -231,7 +233,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
*/
public void evictConnection(Connection connection)
{
if (!isShutdown && pool != null && connection instanceof IHikariConnectionProxy) {
if (!isClosed() && pool != null && connection instanceof IHikariConnectionProxy) {
pool.evictConnection((IHikariConnectionProxy) connection);
}
}
@ -242,7 +244,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
*/
public void suspendPool()
{
if (!isShutdown && pool != null) {
if (!isClosed() && pool != null) {
pool.suspendPool();
}
}
@ -252,7 +254,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
*/
public void resumePool()
{
if (!isShutdown && pool != null) {
if (!isClosed() && pool != null) {
pool.resumePool();
}
}
@ -263,12 +265,10 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
@Override
public void close()
{
if (isShutdown) {
if (isShutdown.getAndSet(true)) {
return;
}
isShutdown = true;
if (pool != null) {
try {
pool.shutdown();
@ -290,7 +290,7 @@ public class HikariDataSource extends HikariConfig implements DataSource, Closea
*/
public boolean isClosed()
{
return isShutdown;
return isShutdown.get();
}
/**

@ -85,7 +85,7 @@ public class HikariJNDIFactory implements ObjectFactory
String jndiName = properties.getProperty("dataSourceJNDI");
DataSource jndiDS = (DataSource) context.lookup(jndiName);
if (jndiDS == null) {
context = (Context) (new InitialContext());
context = new InitialContext();
jndiDS = (DataSource) context.lookup(jndiName);
}

@ -44,7 +44,7 @@ public class LeakTask implements Runnable
{
NO_LEAK = new LeakTask() {
@Override
public void cancel() {};
public void cancel() {}
@Override
public LeakTask start(final PoolBagEntry bagEntry)

@ -27,7 +27,7 @@ public final class PoolUtilities
private Executor netTimeoutExecutor;
private String poolName;
private final String poolName;
private volatile boolean isValidChecked;
private volatile boolean isValidSupported;
private boolean isNetworkTimeoutSupported;
@ -63,7 +63,7 @@ public final class PoolUtilities
}
}
catch (Throwable e) {
LOGGER.debug("Exception closing connection {} in pool {}{}", connection.toString(), poolName, addendum, e);
LOGGER.debug("Exception closing connection {} in pool {}{}", connection, poolName, addendum, e);
}
}
@ -78,16 +78,12 @@ public final class PoolUtilities
public void executeSql(final Connection connection, final String sql, final boolean isAutoCommit) throws SQLException
{
if (sql != null) {
Statement statement = connection.createStatement();
try {
try (Statement statement = connection.createStatement()) {
statement.execute(sql);
if (!isAutoCommit) {
connection.commit();
}
}
finally {
statement.close();
}
}
}
@ -268,7 +264,7 @@ public final class PoolUtilities
command.run();
}
catch (Throwable t) {
LOGGER.debug("Exception executing {}", command.toString(), t);
LOGGER.debug("Exception executing {}", command, t);
}
}
}

@ -47,7 +47,7 @@ import com.zaxxer.hikari.util.ClassLoaderUtils;
*/
public final class JavassistProxyFactory
{
private ClassPool classPool;
private final ClassPool classPool;
static {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
@ -224,7 +224,7 @@ public final class JavassistProxyFactory
paramTypes.add(toJavaClass(pt));
}
return intf.getDeclaredMethod(intfMethod.getName(), paramTypes.toArray(new Class[0])).toString().contains("default ");
return intf.getDeclaredMethod(intfMethod.getName(), paramTypes.toArray(new Class[paramTypes.size()])).toString().contains("default ");
}
private Class<?> toJavaClass(CtClass cls) throws Exception

@ -19,8 +19,8 @@ import java.util.concurrent.ThreadFactory;
public class DefaultThreadFactory implements ThreadFactory {
private String threadName;
private boolean daemon;
private final String threadName;
private final boolean daemon;
public DefaultThreadFactory(String threadName, boolean daemon) {
this.threadName = threadName;

@ -122,6 +122,7 @@ public final class DriverDataSource implements DataSource
return DriverManager.getLoginTimeout();
}
@Override
public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException
{
return driver.getParentLogger();

Loading…
Cancel
Save