com.jwebmp.guicedpersistence.readers.hibernateproperties.HibernateDefaultConnectionBaseBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiced-persistence-hibernateproperties-reader Show documentation
Show all versions of guiced-persistence-hibernateproperties-reader Show documentation
Reads and Configures Hibernate Properties programmatically and replaces the values in the persistence properties.
The newest version!
package com.jwebmp.guicedpersistence.readers.hibernateproperties;
import com.jwebmp.guicedpersistence.db.ConnectionBaseInfo;
import com.jwebmp.guicedpersistence.services.IPropertiesConnectionInfoReader;
import com.oracle.jaxb21.PersistenceUnit;
import java.util.Properties;
/**
* Reads the default connection properties for hibernate and configures the connection accordingly
*/
public class HibernateDefaultConnectionBaseBuilder
implements IPropertiesConnectionInfoReader
{
@Override
public ConnectionBaseInfo populateConnectionBaseInfo(PersistenceUnit unit, Properties filteredProperties, ConnectionBaseInfo cbi)
{
for (String prop : filteredProperties.stringPropertyNames())
{
switch (prop)
{
case "hibernate.connection.url":
{
if (cbi.getUrl() == null)
{
cbi.setUrl(filteredProperties.getProperty(prop));
}
break;
}
case "hibernate.connection.user":
{
if (cbi.getUsername() == null)
{
cbi.setUsername(filteredProperties.getProperty(prop));
}
break;
}
case "hibernate.connection.driver_class":
{
if (cbi.getDriverClass() == null)
{
cbi.setDriverClass(filteredProperties.getProperty(prop));
}
break;
}
default:
{
break;
}
}
}
return cbi;
}
}