com.jwebmp.guicedpersistence.readers.systemproperties.SystemEnvironmentVariablesPropertiesReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiced-persistence-systemproperties-reader Show documentation
Show all versions of guiced-persistence-systemproperties-reader Show documentation
Reads ${} properties from the System Environment Variables and replaces the values in the persistence properties.
package com.jwebmp.guicedpersistence.readers.systemproperties;
import com.google.common.base.Strings;
import com.jwebmp.guicedpersistence.services.IPropertiesEntityManagerReader;
import com.oracle.jaxb21.PersistenceUnit;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* A default connection string builder for H2 Databases
*/
public class SystemEnvironmentVariablesPropertiesReader
implements IPropertiesEntityManagerReader
{
@Override
public Map processProperties(PersistenceUnit persistenceUnit, Properties incomingProperties)
{
for (String prop : incomingProperties.stringPropertyNames())
{
String value = incomingProperties.getProperty(prop);
if (value.startsWith("${"))
{
String searchProperty = value.substring(2, value.length() - 1);
String systemProperty = System.getProperty(searchProperty);
if (!Strings.isNullOrEmpty(systemProperty))
{
incomingProperties.put(prop, systemProperty);
}
}
}
return new HashMap<>();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy