Closes#45 if the PropertyBeanSetter fails to find the setter method via "set" + first property character capitalized, try "set" + property fully capitalized. This handles cases where "url" is used as a property but the setter is setURL() rather than setUrl().

pull/60/head
Brett Wooldridge 11 years ago
parent b46e484bad
commit 27cd322fba

@ -61,9 +61,27 @@ public final class PropertyBeanSetter
private static void setProperty(Object target, String propName, Object propValue)
{
String capitalized = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1);
PropertyDescriptor propertyDescriptor;
try
{
propertyDescriptor = new PropertyDescriptor(propName, target.getClass(), null, capitalized);
}
catch (IntrospectionException e)
{
capitalized = "set" + propName.toUpperCase();
try
{
propertyDescriptor = new PropertyDescriptor(propName, target.getClass(), null, capitalized);
}
catch (IntrospectionException e1)
{
LOGGER.error("Property {} is does not exist on target class {}", propName, target.getClass());
throw new RuntimeException(e);
}
}
try
{
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propName, target.getClass(), null, capitalized);
Method writeMethod = propertyDescriptor.getWriteMethod();
Class<?> paramClass = writeMethod.getParameterTypes()[0];
if (paramClass == int.class)
@ -87,11 +105,6 @@ public final class PropertyBeanSetter
writeMethod.invoke(target, propValue);
}
}
catch (IntrospectionException e)
{
LOGGER.error("Property {} is does not exist on target class {}", propName, target.getClass());
throw new RuntimeException(e);
}
catch (Exception e)
{
LOGGER.error("Exception setting property {} on target class {}", propName, target.getClass(), e);

@ -50,4 +50,17 @@ public class TestPropertySetter
Assert.assertSame(PrintWriter.class, dataSource.getLogWriter().getClass());
}
@Test
public void testPropertyUpperCase() throws Exception
{
File file = new File("src/test/resources/propfile3.properties");
HikariConfig config = new HikariConfig(file.getPath());
config.validate();
Class<?> clazz = this.getClass().getClassLoader().loadClass(config.getDataSourceClassName());
DataSource dataSource = (DataSource) clazz.newInstance();
PropertyBeanSetter.setTargetFromProperties(dataSource, config.getDataSourceProperties());
}
}

@ -55,6 +55,11 @@ public class StubDataSource implements DataSource
this.password = password;
}
public void setURL(String url)
{
// we don't care
}
/** {@inheritDoc} */
@Override
public PrintWriter getLogWriter() throws SQLException

@ -0,0 +1,6 @@
connectionTestQuery=SELECT 1
autoCommit=false
dataSourceClassName=com.zaxxer.hikari.mocks.StubDataSource
dataSource.user=test
dataSource.password=test
dataSource.url=jdbc:stub:foo
Loading…
Cancel
Save