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

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

Go to download

A complete JPA 2.1 implementation for Standalone or EE Implementation. Enables Multiple Persistence units with full JTA Support using BTM. Perfect for Guice implementations, test suites, and Guice enabled Web Applications or EAR Projects. Requires JDK 8

There is a newer version: 62
Show newest version
package com.guicedee.guicedpersistence.readers.systemproperties;

import com.google.common.base.Strings;
import com.guicedee.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 - 2024 Weber Informatics LLC | Privacy Policy