Search in sources :

Example 11 with Command

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

the class HibernateExtension method executeCriteriaQuery.

public QueryPage executeCriteriaQuery(final String criteriaCode, final QueryInputModel model) {
    return (QueryPage) execute(new Command() {

        public Object execute() {
            ISession session = sessionFactory.openSession();
            QueryPage qp = new JavaPage(HibernateExtension.this, criteriaCode, model);
            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 12 with Command

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

the class SchemaExportAction method doRun.

public void doRun() {
    for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext(); ) {
        Object node = i.next();
        if (!(node instanceof ConsoleConfiguration)) {
            continue;
        }
        final ConsoleConfiguration config = (ConsoleConfiguration) node;
        try {
            config.execute(new Command() {

                public Object execute() {
                    final IConfiguration cfg = config.getConfiguration();
                    if (cfg == null) {
                        return null;
                    }
                    String out = NLS.bind(HibernateConsoleMessages.SchemaExportAction_sure_run_schemaexport, config.getName());
                    boolean res = openWarningYesNoDlg(viewer.getControl().getShell(), HibernateConsoleMessages.SchemaExportAction_run_schemaexport, out);
                    if (!res) {
                        return null;
                    }
                    IService service = config.getHibernateExtension().getHibernateService();
                    ISchemaExport export = service.newSchemaExport(cfg);
                    export.create();
                    if (!export.getExceptions().isEmpty()) {
                        Iterator<Throwable> iterator = export.getExceptions().iterator();
                        int cnt = 1;
                        while (iterator.hasNext()) {
                            Throwable element = iterator.next();
                            String outStr = NLS.bind(HibernateConsoleMessages.SchemaExportAction_errornum_while_performing_schemaexport, cnt++);
                            HibernateConsolePlugin.getDefault().logErrorMessage(outStr, element);
                        }
                        HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), NLS.bind(HibernateConsoleMessages.SchemaExportAction_error_while_performing_schemaexport, cnt - 1), (Throwable) null);
                    }
                    return null;
                }
            });
            // todo: should we do it here or should
            viewer.refresh(node);
        // the view just react to config being
        // build ?
        } catch (Exception he) {
            HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(), HibernateConsoleMessages.SchemaExportAction_exception_running_schemaexport, he);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Command(org.hibernate.console.execution.ExecutionContext.Command) ISchemaExport(org.jboss.tools.hibernate.runtime.spi.ISchemaExport) Iterator(java.util.Iterator) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IService(org.jboss.tools.hibernate.runtime.spi.IService)

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