Search in sources :

Example 1 with Command

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

the class ConsoleExtension method runExporters.

private IArtifactCollector runExporters(final ExporterAttributes attributes, final ExporterFactory[] exporterFactories, final Set<String> outputDirectories, final IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for + attributes.getConsoleConfigurationName(), exporterFactories.length + 1);
    if (monitor.isCanceled())
        return null;
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
    if (attributes.isReverseEngineer()) {
        monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
    }
    final IConfiguration cfg = buildConfiguration(attributes, cc, ResourcesPlugin.getWorkspace().getRoot());
    monitor.worked(1);
    if (monitor.isCanceled())
        return null;
    return (IArtifactCollector) cc.execute(new Command() {

        public Object execute() {
            IArtifactCollector artifactCollector = hibernateExtension.getHibernateService().newArtifactCollector();
            // Global properties
            Properties props = new Properties();
            props.put(CodeGenerationStrings.EJB3, // $NON-NLS-1$
            "" + attributes.isEJB3Enabled());
            props.put(CodeGenerationStrings.JDK5, // $NON-NLS-1$
            "" + attributes.isJDK5Enabled());
            for (int i = 0; i < exporterFactories.length; i++) {
                monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());
                Properties globalProperties = new Properties();
                globalProperties.putAll(props);
                IExporter exporter;
                try {
                    exporter = exporterFactories[i].createConfiguredExporter(cfg, attributes.getOutputPath(), attributes.getTemplatePath(), globalProperties, outputDirectories, artifactCollector, hibernateExtension.getHibernateService());
                } catch (CoreException e) {
                    throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up + exporterFactories[i].getExporterDefinition(), e);
                }
                try {
                    exporter.start();
                } catch (HibernateException he) {
                    throw new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running + exporterFactories[i].getExporterDefinition().getDescription(), he);
                }
                monitor.worked(1);
            }
            return artifactCollector;
        }
    });
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) Command(org.hibernate.console.execution.ExecutionContext.Command) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IExporter(org.jboss.tools.hibernate.runtime.spi.IExporter) HibernateConsoleRuntimeException(org.hibernate.console.HibernateConsoleRuntimeException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties)

Example 2 with Command

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

the class HibernateExtension method executeHQLQuery.

public QueryPage executeHQLQuery(final String hql, final QueryInputModel queryParameters) {
    return (QueryPage) execute(new Command() {

        public Object execute() {
            ISession session = sessionFactory.openSession();
            QueryPage qp = new HQLQueryPage(HibernateExtension.this, hql, queryParameters);
            qp.setSession(session);
            return qp;
        }
    });
}
Also used : ISession(org.jboss.tools.hibernate.runtime.spi.ISession) Command(org.hibernate.console.execution.ExecutionContext.Command) QueryPage(org.hibernate.console.QueryPage)

Example 3 with Command

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

the class HibernateExtension method cleanUpClassLoader.

protected boolean cleanUpClassLoader() {
    boolean resetted = false;
    if (executionContext != null) {
        executionContext.execute(new Command() {

            public Object execute() {
                Iterator<FakeDelegatingDriver> it = fakeDrivers.values().iterator();
                while (it.hasNext()) {
                    try {
                        DriverManager.deregisterDriver(it.next());
                    } catch (SQLException e) {
                    // ignore
                    }
                }
                return null;
            }
        });
    }
    if (fakeDrivers.size() > 0) {
        fakeDrivers.clear();
        resetted = true;
    }
    ClassLoader classLoaderTmp = classLoader;
    while (classLoaderTmp != null) {
        if (classLoaderTmp instanceof ConsoleConfigClassLoader) {
            ((ConsoleConfigClassLoader) classLoaderTmp).close();
            resetted = true;
        }
        classLoaderTmp = classLoaderTmp.getParent();
    }
    if (classLoader != null) {
        classLoader = null;
        resetted = true;
    }
    return resetted;
}
Also used : Command(org.hibernate.console.execution.ExecutionContext.Command) SQLException(java.sql.SQLException) ConsoleConfigClassLoader(org.hibernate.console.ConsoleConfigClassLoader) Iterator(java.util.Iterator) ConsoleConfigClassLoader(org.hibernate.console.ConsoleConfigClassLoader)

Example 4 with Command

use of org.hibernate.console.execution.ExecutionContext.Command 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 5 with Command

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

the class ConsoleConfiguration method cleanUpClassLoader.

protected boolean cleanUpClassLoader() {
    boolean resetted = false;
    if (executionContext != null) {
        executionContext.execute(new Command() {

            public Object execute() {
                Iterator<FakeDelegatingDriver> it = fakeDrivers.values().iterator();
                while (it.hasNext()) {
                    try {
                        DriverManager.deregisterDriver(it.next());
                    } catch (SQLException e) {
                    // ignore
                    }
                }
                return null;
            }
        });
    }
    if (fakeDrivers.size() > 0) {
        fakeDrivers.clear();
        resetted = true;
    }
    ClassLoader classLoaderTmp = classLoader;
    while (classLoaderTmp != null) {
        if (classLoaderTmp instanceof ConsoleConfigClassLoader) {
            ((ConsoleConfigClassLoader) classLoaderTmp).close();
            resetted = true;
        }
        classLoaderTmp = classLoaderTmp.getParent();
    }
    if (classLoader != null) {
        classLoader = null;
        resetted = true;
    }
    return resetted;
}
Also used : Command(org.hibernate.console.execution.ExecutionContext.Command) SQLException(java.sql.SQLException) Iterator(java.util.Iterator)

Aggregations

Command (org.hibernate.console.execution.ExecutionContext.Command)12 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)6 Iterator (java.util.Iterator)3 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)3 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 CoreException (org.eclipse.core.runtime.CoreException)2 HibernateConsoleRuntimeException (org.hibernate.console.HibernateConsoleRuntimeException)2 QueryPage (org.hibernate.console.QueryPage)2 DefaultExecutionContext (org.hibernate.console.execution.DefaultExecutionContext)2 HibernateException (org.jboss.tools.hibernate.runtime.spi.HibernateException)2 IArtifactCollector (org.jboss.tools.hibernate.runtime.spi.IArtifactCollector)2 IExporter (org.jboss.tools.hibernate.runtime.spi.IExporter)2 IService (org.jboss.tools.hibernate.runtime.spi.IService)2 ISession (org.jboss.tools.hibernate.runtime.spi.ISession)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 ConfigurationFactory (org.hibernate.console.ConfigurationFactory)1 ConsoleConfigClassLoader (org.hibernate.console.ConsoleConfigClassLoader)1 ISchemaExport (org.jboss.tools.hibernate.runtime.spi.ISchemaExport)1 IHSearchService (org.jboss.tools.hibernate.search.runtime.spi.IHSearchService)1