Search in sources :

Example 1 with IEnvironment

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());
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) IEnvironment(org.jboss.tools.hibernate.runtime.spi.IEnvironment)

Example 2 with IEnvironment

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;
}
Also used : IEnvironment(org.jboss.tools.hibernate.runtime.spi.IEnvironment) Properties(java.util.Properties)

Example 3 with IEnvironment

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;
}
Also used : IEnvironment(org.jboss.tools.hibernate.runtime.spi.IEnvironment) Properties(java.util.Properties)

Example 4 with IEnvironment

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);
}
Also used : IEnvironment(org.jboss.tools.hibernate.runtime.spi.IEnvironment) Test(org.junit.Test)

Example 5 with IEnvironment

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);
}
Also used : IEnvironment(org.jboss.tools.hibernate.runtime.spi.IEnvironment) Test(org.junit.Test)

Aggregations

IEnvironment (org.jboss.tools.hibernate.runtime.spi.IEnvironment)15 Test (org.junit.Test)8 Properties (java.util.Properties)4 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 File (java.io.File)1 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 Element (org.dom4j.Element)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1