Search in sources :

Example 71 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewAnnotationConfiguration.

@Test
public void testNewAnnotationConfiguration() {
    IConfiguration configuration = service.newAnnotationConfiguration();
    Assert.assertNotNull(configuration);
    Object target = ((IFacade) configuration).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof Configuration);
}
Also used : JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_5_3.internal.util.JdbcMetadataConfiguration) Configuration(org.hibernate.cfg.Configuration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Test(org.junit.Test)

Example 72 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.

the class IndexRebuildHandler method run.

private void run(final ConsoleConfiguration consoleConfig, final Set<Class> classes) {
    try {
        consoleConfig.execute(new Command() {

            public Object execute() {
                final IConfiguration cfg = consoleConfig.getConfiguration();
                if (cfg == null) {
                    return null;
                }
                IHSearchService service = HSearchServiceLookup.findService(HSearchConsoleConfigurationPreferences.getHSearchVersion(consoleConfig.getName()));
                service.newIndexRebuild(consoleConfig.getSessionFactory(), classes);
                return null;
            }
        });
        MessageDialog.openInformation(HibernateConsolePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), "Initial index rebuild", "Initial index rebuild succesfully finished");
    } catch (Exception e) {
        MessageDialog.openError(HibernateConsolePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), "Initial index rebuild failed", e.getMessage());
    }
}
Also used : IHSearchService(org.jboss.tools.hibernate.search.runtime.spi.IHSearchService) Command(org.hibernate.console.execution.ExecutionContext.Command) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 73 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.

the class CodeGenerationLaunchDelegate 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;
    final IService service = cc.getHibernateExtension().getHibernateService();
    return (IArtifactCollector) cc.execute(new Command() {

        public Object execute() {
            IArtifactCollector artifactCollector = service.newArtifactCollector();
            // Global properties
            Properties props = new Properties();
            // $NON-NLS-1$
            props.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled());
            // $NON-NLS-1$
            props.put(CodeGenerationStrings.JDK5, "" + 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, service);
                } 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) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 74 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.

the class CriteriaEditor method getImports.

private String[] getImports() {
    final ConsoleConfiguration consoleConfiguration = getConsoleConfiguration();
    if (!consoleConfiguration.hasConfiguration()) {
        try {
            consoleConfiguration.build();
            consoleConfiguration.buildMappings();
        } catch (Exception e) {
            String mess = NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc, consoleConfiguration.getName());
            HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
        }
    }
    Set<String> imports = new HashSet<String>();
    IConfiguration configuration = consoleConfiguration.getConfiguration();
    if (configuration != null) {
        Iterator<IPersistentClass> classMappings = configuration.getClassMappings();
        while (classMappings.hasNext()) {
            IPersistentClass clazz = classMappings.next();
            String className = clazz.getClassName();
            if (className != null) {
                imports.add(className);
            }
        }
    }
    // $NON-NLS-1$
    imports.add("org.hibernate.*");
    // $NON-NLS-1$
    imports.add("org.hibernate.criterion.*");
    return imports.toArray(new String[imports.size()]);
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) HashSet(java.util.HashSet)

Example 75 with IConfiguration

use of org.jboss.tools.hibernate.runtime.spi.IConfiguration in project jbosstools-hibernate by jbosstools.

the class LazyDatabaseSchemaWorkbenchAdapter method readDatabaseSchema.

protected IDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor, final ConsoleConfiguration consoleConfiguration, final IReverseEngineeringStrategy strategy) {
    final IConfiguration configuration = consoleConfiguration.buildWith(null, false);
    return (IDatabaseCollector) consoleConfiguration.execute(new ExecutionContext.Command() {

        public Object execute() {
            IDatabaseCollector db = null;
            try {
                IService service = consoleConfiguration.getHibernateExtension().getHibernateService();
                IJDBCReader reader = service.newJDBCReader(configuration, strategy);
                db = service.newDatabaseCollector(reader);
                reader.readDatabaseSchema(db, new ProgressListener(monitor));
            } catch (UnsupportedOperationException he) {
                throw new HibernateException(he);
            } catch (Exception he) {
                he.printStackTrace();
                throw new HibernateException(he.getMessage(), he.getCause());
            }
            return db;
        }
    });
}
Also used : IProgressListener(org.jboss.tools.hibernate.runtime.spi.IProgressListener) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IDatabaseCollector(org.jboss.tools.hibernate.runtime.spi.IDatabaseCollector) IService(org.jboss.tools.hibernate.runtime.spi.IService) HibernateException(org.jboss.tools.hibernate.runtime.spi.HibernateException) IJDBCReader(org.jboss.tools.hibernate.runtime.spi.IJDBCReader)

Aggregations

IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)137 Test (org.junit.Test)72 Configuration (org.hibernate.cfg.Configuration)65 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)29 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)25 File (java.io.File)19 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)17 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)16 Properties (java.util.Properties)13 CoreException (org.eclipse.core.runtime.CoreException)10 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)10 IJDBCReader (org.jboss.tools.hibernate.runtime.spi.IJDBCReader)9 FileWriter (java.io.FileWriter)8 IOException (java.io.IOException)8 JDBCReader (org.hibernate.cfg.reveng.JDBCReader)8 SimpleValue (org.hibernate.mapping.SimpleValue)8 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)8 JavaModelException (org.eclipse.jdt.core.JavaModelException)7 PartInitException (org.eclipse.ui.PartInitException)7 Ejb3Configuration (org.hibernate.ejb.Ejb3Configuration)7