Resolve #145 support ``hikaricp.configurationFile`` system property to define location to load configuration properties file.

pull/147/head
Brett Wooldridge 11 years ago
parent a39782a2db
commit bef71f78af

@ -111,6 +111,11 @@ public class HikariConfig implements HikariConfigMBean
{
}
};
String systemProp = System.getProperty("hikaricp.configurationFile");
if ( systemProp != null) {
loadProperties(systemProp);
}
}
/**
@ -135,26 +140,7 @@ public class HikariConfig implements HikariConfigMBean
{
this();
final File propFile = new File(propertyFileName);
try {
final InputStream is = propFile.isFile() ? new FileInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName);
if (is != null) {
try {
Properties props = new Properties();
props.load(is);
PropertyBeanSetter.setTargetFromProperties(this, props);
}
finally {
is.close();
}
}
else {
throw new IllegalArgumentException("Property file " + propertyFileName + " was not found.");
}
}
catch (IOException io) {
throw new RuntimeException("Error loading properties file", io);
}
loadProperties(propertyFileName);
}
/**
@ -770,6 +756,30 @@ public class HikariConfig implements HikariConfigMBean
}
}
private void loadProperties(String propertyFileName)
{
final File propFile = new File(propertyFileName);
try {
final InputStream is = propFile.isFile() ? new FileInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName);
if (is != null) {
try {
Properties props = new Properties();
props.load(is);
PropertyBeanSetter.setTargetFromProperties(this, props);
}
finally {
is.close();
}
}
else {
throw new IllegalArgumentException("Property file " + propertyFileName + " was not found.");
}
}
catch (IOException io) {
throw new RuntimeException("Error loading properties file", io);
}
}
void copyState(HikariConfig other)
{
for (Field field : HikariConfig.class.getDeclaredFields()) {

@ -111,6 +111,11 @@ public class HikariConfig implements HikariConfigMBean
{
}
};
String systemProp = System.getProperty("hikaricp.configurationFile");
if ( systemProp != null) {
loadProperties(systemProp);
}
}
/**
@ -135,20 +140,7 @@ public class HikariConfig implements HikariConfigMBean
{
this();
final File propFile = new File(propertyFileName);
try (final InputStream is = propFile.isFile() ? new FileInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName)) {
if (is != null) {
Properties props = new Properties();
props.load(is);
PropertyBeanSetter.setTargetFromProperties(this, props);
}
else {
throw new IllegalArgumentException("Property file " + propertyFileName + " was not found.");
}
}
catch (IOException io) {
throw new RuntimeException("Error loading properties file", io);
}
loadProperties(propertyFileName);
}
/**
@ -764,6 +756,24 @@ public class HikariConfig implements HikariConfigMBean
}
}
private void loadProperties(String propertyFileName)
{
final File propFile = new File(propertyFileName);
try (final InputStream is = propFile.isFile() ? new FileInputStream(propFile) : this.getClass().getResourceAsStream(propertyFileName)) {
if (is != null) {
Properties props = new Properties();
props.load(is);
PropertyBeanSetter.setTargetFromProperties(this, props);
}
else {
throw new IllegalArgumentException("Property file " + propertyFileName + " was not found.");
}
}
catch (IOException io) {
throw new RuntimeException("Error loading properties file", io);
}
}
void copyState(HikariConfig other)
{
for (Field field : HikariConfig.class.getDeclaredFields()) {

Loading…
Cancel
Save