use of org.jboss.tools.hibernate.runtime.spi.IEnvironment in project jbosstools-hibernate by jbosstools.
the class ConnectionProfileUtil method autoDetectDialect.
public static String autoDetectDialect(IService service, Properties properties) {
IEnvironment environment = service.getEnvironment();
if (properties.getProperty(environment.getDialect()) == null) {
String url = properties.getProperty(environment.getURL());
String user = properties.getProperty(environment.getUser());
String pass = properties.getProperty(environment.getPass());
Connection connection = null;
try {
connection = DriverManager.getConnection(url, user, pass);
// probably when not Hiberante3.5 is used
return service.newDialect(properties, connection);
} catch (SQLException e) {
// can't determine dialect
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
// ignore
}
}
}
return null;
} else {
return properties.getProperty(environment.getDialect());
}
}
use of org.jboss.tools.hibernate.runtime.spi.IEnvironment in project jbosstools-hibernate by jbosstools.
the class ConnectionProfileUtil method getHibernateConnectionProperties.
/**
* This method extracts connection properties from connection profile and convert them to
* hiberante properties (uses other "keys" for them)
* @param profile
* @return
*/
public static Properties getHibernateConnectionProperties(IService service, IConnectionProfile profile) {
Properties props = new Properties();
IEnvironment environment = service.getEnvironment();
if (profile != null) {
final Properties cpProperties = profile.getProperties(profile.getProviderId());
String driverClass = ConnectionProfileUtil.getDriverClass(profile.getName());
props.setProperty(environment.getDriver(), driverClass);
String url = cpProperties.getProperty(IJDBCDriverDefinitionConstants.URL_PROP_ID);
props.setProperty(environment.getURL(), url);
String user = cpProperties.getProperty(IJDBCDriverDefinitionConstants.USERNAME_PROP_ID);
if (null != user && user.length() > 0) {
props.setProperty(environment.getUser(), user);
}
String pass = cpProperties.getProperty(IJDBCDriverDefinitionConstants.PASSWORD_PROP_ID);
if (null != pass && pass.length() > 0) {
props.setProperty(environment.getPass(), pass);
}
}
return props;
}
use of org.jboss.tools.hibernate.runtime.spi.IEnvironment in project jbosstools-hibernate by jbosstools.
the class TestConsoleConfigurationPreferences method getProperties.
public Properties getProperties() {
IEnvironment environment = getService().getEnvironment();
Properties p = new Properties();
// $NON-NLS-1$
p.setProperty(environment.getDialect(), "org.hibernate.dialect.HSQLDialect");
return p;
}
use of org.jboss.tools.hibernate.runtime.spi.IEnvironment in project jbosstools-hibernate by jbosstools.
the class ServiceImplTest method testGetEnvironment.
@Test
public void testGetEnvironment() {
IEnvironment environment = service.getEnvironment();
Assert.assertNotNull(environment);
Assert.assertEquals(environment.getTransactionManagerStrategy(), Environment.TRANSACTION_COORDINATOR_STRATEGY);
}
use of org.jboss.tools.hibernate.runtime.spi.IEnvironment in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateEnvironment.
@Test
public void testCreateEnvironment() {
IEnvironment environment = facadeFactory.createEnvironment();
Assert.assertNotNull(environment);
Assert.assertTrue(environment instanceof EnvironmentFacadeImpl);
}
Aggregations