Search in sources :

Example 1 with DefaultExecutionContext

use of org.hibernate.console.execution.DefaultExecutionContext in project jbosstools-hibernate by jbosstools.

the class HibernateExtension method buildWith.

public IConfiguration buildWith(final IConfiguration cfg, final boolean includeMappings) {
    reinitClassLoader();
    // TODO handle user libraries here
    executionContext = new DefaultExecutionContext(prefs.getName(), classLoader);
    IConfiguration result = (IConfiguration) execute(new Command() {

        public Object execute() {
            ConfigurationFactory cf = new ConfigurationFactory(prefs, fakeDrivers);
            return cf.createConfiguration(cfg, includeMappings);
        }
    });
    return result;
}
Also used : DefaultExecutionContext(org.hibernate.console.execution.DefaultExecutionContext) Command(org.hibernate.console.execution.ExecutionContext.Command) ConfigurationFactory(org.hibernate.console.ConfigurationFactory) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 2 with DefaultExecutionContext

use of org.hibernate.console.execution.DefaultExecutionContext in project jbosstools-hibernate by jbosstools.

the class ConsoleConfiguration method buildWith.

/**
 * @return
 */
public IConfiguration buildWith(final IConfiguration cfg, final boolean includeMappings) {
    reinitClassLoader();
    executionContext = new DefaultExecutionContext(getName(), classLoader);
    IConfiguration result = (IConfiguration) execute(new Command() {

        public Object execute() {
            ConfigurationFactory csf = new ConfigurationFactory(prefs, fakeDrivers);
            return csf.createConfiguration(cfg, includeMappings);
        }
    });
    return result;
}
Also used : DefaultExecutionContext(org.hibernate.console.execution.DefaultExecutionContext) Command(org.hibernate.console.execution.ExecutionContext.Command) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 3 with DefaultExecutionContext

use of org.hibernate.console.execution.DefaultExecutionContext in project jbosstools-hibernate by jbosstools.

the class DriverDeleteTest method initExecutionContext.

private void initExecutionContext() {
    final ConsoleConfigClassLoader urlClassLoader = createJarClassLoader();
    DefaultExecutionContext dec = new DefaultExecutionContext(testName.getMethodName(), urlClassLoader);
    ExecutionContext.Command command = new ExecutionContext.Command() {

        public Object execute() {
            try {
                Class<?> driverClass = null;
                driverClass = (Class<?>) ReflectHelper.classForName(DRIVER_TEST_CLASS);
                Driver driver2 = (Driver) driverClass.newInstance();
                ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
                if (contextClassLoader != null) {
                    driverClass = (Class<?>) contextClassLoader.loadClass(DRIVER_TEST_CLASS);
                }
                java.util.Properties info = new java.util.Properties();
                info.put("user", CONNECTION_USERNAME);
                info.put("password", CONNECTION_PASSWORD);
                try {
                    Connection connection = driver2.connect(CONNECTION_URL, info);
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            return null;
        }
    };
    dec.execute(command);
    command = null;
    dec = null;
    urlClassLoader.close();
}
Also used : DefaultExecutionContext(org.hibernate.console.execution.DefaultExecutionContext) SQLException(java.sql.SQLException) ConsoleConfigClassLoader(org.hibernate.console.ConsoleConfigClassLoader) Connection(java.sql.Connection) Driver(java.sql.Driver) DefaultExecutionContext(org.hibernate.console.execution.DefaultExecutionContext) ExecutionContext(org.hibernate.console.execution.ExecutionContext) ConsoleConfigClassLoader(org.hibernate.console.ConsoleConfigClassLoader)

Aggregations

DefaultExecutionContext (org.hibernate.console.execution.DefaultExecutionContext)3 Command (org.hibernate.console.execution.ExecutionContext.Command)2 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)2 Connection (java.sql.Connection)1 Driver (java.sql.Driver)1 SQLException (java.sql.SQLException)1 ConfigurationFactory (org.hibernate.console.ConfigurationFactory)1 ConsoleConfigClassLoader (org.hibernate.console.ConsoleConfigClassLoader)1 ExecutionContext (org.hibernate.console.execution.ExecutionContext)1