From fd02583e477ed24780f4e26699badf48ae0aab6a Mon Sep 17 00:00:00 2001 From: Nitin Date: Sun, 27 Dec 2015 18:55:22 +0530 Subject: [PATCH] minor tweaks --- .../java/com/zaxxer/hikari/pool/PoolBase.java | 17 +++++------------ .../com/zaxxer/hikari/util/PropertyElf.java | 14 +++++++++----- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java index 2acf2914..3fd576d7 100644 --- a/src/main/java/com/zaxxer/hikari/pool/PoolBase.java +++ b/src/main/java/com/zaxxer/hikari/pool/PoolBase.java @@ -99,22 +99,15 @@ abstract class PoolBase void quietlyCloseConnection(final Connection connection, final String closureReason) { - if (connection == null) { - return; - } - - try { - LOGGER.debug("{} - Closing connection {}: {}", poolName, connection, closureReason); + if (connection != null) { try { + LOGGER.debug("{} - Closing connection {}: {}", poolName, connection, closureReason); setNetworkTimeout(connection, TimeUnit.SECONDS.toMillis(15)); - } - finally { - // continue with the close even if setNetworkTimeout() throws (due to driver poorly behaving drivers) connection.close(); } - } - catch (Throwable e) { - LOGGER.debug("{} - Closing connection {} failed", poolName, connection, e); + catch (Throwable e) { + LOGGER.debug("{} - Closing connection {} failed", poolName, connection, e); + } } } diff --git a/src/main/java/com/zaxxer/hikari/util/PropertyElf.java b/src/main/java/com/zaxxer/hikari/util/PropertyElf.java index e8871bda..a89d2399 100644 --- a/src/main/java/com/zaxxer/hikari/util/PropertyElf.java +++ b/src/main/java/com/zaxxer/hikari/util/PropertyElf.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,6 +47,7 @@ public final class PropertyElf return; } + List methods = Arrays.asList(target.getClass().getMethods()); Enumeration propertyNames = properties.propertyNames(); while (propertyNames.hasMoreElements()) { Object key = propertyNames.nextElement(); @@ -59,7 +62,7 @@ public final class PropertyElf config.addDataSourceProperty(propName.substring("dataSource.".length()), propValue); } else { - setProperty(target, propName, propValue); + setProperty(target, propName, propValue, methods); } } } @@ -73,9 +76,11 @@ public final class PropertyElf public static Set getPropertyNames(Class targetClass) { HashSet set = new HashSet<>(); + Pattern pattern = Pattern.compile("(get|is)[A-Z].+"); + Matcher matcher = pattern.matcher(""); for (Method method : targetClass.getMethods()) { String name = method.getName(); - if (name.matches("(get|is)[A-Z].+") && method.getParameterTypes().length == 0) { + if (method.getParameterTypes().length == 0 && matcher.reset(name).matches()) { name = name.replaceFirst("(get|is)", ""); try { if (targetClass.getMethod("set" + name, method.getReturnType()) != null) { @@ -120,12 +125,11 @@ public final class PropertyElf return copy; } - private static void setProperty(Object target, String propName, Object propValue) + private static void setProperty(Object target, String propName, Object propValue, List methods) { Method writeMethod = null; String methodName = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1); - List methods = Arrays.asList(target.getClass().getMethods()); for (Method method : methods) { if (method.getName().equals(methodName) && method.getParameterTypes().length == 1) { writeMethod = method; @@ -140,7 +144,7 @@ public final class PropertyElf writeMethod = method; break; } - } + } } if (writeMethod == null) {