All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jwebmp.guicedpersistence.readers.systemproperties.SystemEnvironmentVariablesPropertiesReader Maven / Gradle / Ivy

Go to download

Reads ${} properties from the System Environment Variables and replaces the values in the persistence properties.

There is a newer version: 0.68.0.1
Show newest version
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