From 2f712702354cc0d57eb1628190847b0aea32bb15 Mon Sep 17 00:00:00 2001 From: Brett Wooldridge Date: Tue, 8 Jul 2014 12:05:17 +0900 Subject: [PATCH] Fix JNDI lookup bug where properties were not being passed through. --- .../com/zaxxer/hikari/HikariJNDIFactory.java | 15 ++++++++++----- .../com/zaxxer/hikari/HikariJNDIFactory.java | 17 +++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/hikaricp-java6/src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java b/hikaricp-java6/src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java index 55ab3c96..99a955ff 100644 --- a/hikaricp-java6/src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java +++ b/hikaricp-java6/src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java @@ -16,8 +16,10 @@ package com.zaxxer.hikari; +import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; +import java.util.Set; import javax.naming.Context; import javax.naming.InitialContext; @@ -50,12 +52,15 @@ public class HikariJNDIFactory implements ObjectFactory throw new NamingException(ref.getClassName() + " is not a valid class name/type for this JNDI factory."); } + Set hikariPropSet = PropertyBeanSetter.getPropertyNames(HikariConfig.class); + Properties properties = new Properties(); - for (String propertyName : PropertyBeanSetter.getPropertyNames(HikariConfig.class)) { - RefAddr ra = ref.get(propertyName); - if (ra != null) { - String propertyValue = ra.getContent().toString(); - properties.setProperty(propertyName, propertyValue); + Enumeration enumeration = ref.getAll(); + while (enumeration.hasMoreElements()) { + RefAddr element = enumeration.nextElement(); + String type = element.getType(); + if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) { + properties.setProperty(type, element.getContent().toString()); } } diff --git a/hikaricp/src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java b/hikaricp/src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java index d2fed65d..99a955ff 100644 --- a/hikaricp/src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java +++ b/hikaricp/src/main/java/com/zaxxer/hikari/HikariJNDIFactory.java @@ -16,8 +16,10 @@ package com.zaxxer.hikari; +import java.util.Enumeration; import java.util.Hashtable; import java.util.Properties; +import java.util.Set; import javax.naming.Context; import javax.naming.InitialContext; @@ -50,12 +52,15 @@ public class HikariJNDIFactory implements ObjectFactory throw new NamingException(ref.getClassName() + " is not a valid class name/type for this JNDI factory."); } + Set hikariPropSet = PropertyBeanSetter.getPropertyNames(HikariConfig.class); + Properties properties = new Properties(); - for (String propertyName : PropertyBeanSetter.getPropertyNames(HikariConfig.class)) { - RefAddr ra = ref.get(propertyName); - if (ra != null) { - String propertyValue = ra.getContent().toString(); - properties.setProperty(propertyName, propertyValue); + Enumeration enumeration = ref.getAll(); + while (enumeration.hasMoreElements()) { + RefAddr element = enumeration.nextElement(); + String type = element.getType(); + if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) { + properties.setProperty(type, element.getContent().toString()); } } @@ -89,7 +94,7 @@ public class HikariJNDIFactory implements ObjectFactory if (jndiDS == null) { try { - context = new InitialContext(); + context = (Context) (new InitialContext()); jndiDS = (DataSource) context.lookup(jndiName); } catch (NamingException e) {