Search in sources :

Example 1 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class ReverseEngineeringEditor method getLazyDatabaseSchema.

public LazyDatabaseSchema getLazyDatabaseSchema() {
    try {
        ConsoleConfiguration configuration = KnownConfigurations.getInstance().find(getConsoleConfigurationName());
        if (configuration == null) {
            configuration = askForConsoleConfiguration();
            if (configuration == null) {
                return null;
            } else {
                setConsoleConfigurationName(configuration.getName());
            }
        }
        org.hibernate.eclipse.console.model.ITableFilter[] tableFilters = getReverseEngineeringDefinition().getTableFilters();
        IService service = configuration.getHibernateExtension().getHibernateService();
        IOverrideRepository repository = service.newOverrideRepository();
        boolean hasIncludes = false;
        for (int i = 0; i < tableFilters.length; i++) {
            org.hibernate.eclipse.console.model.ITableFilter filter = tableFilters[i];
            ITableFilter tf = service.newTableFilter();
            tf.setExclude(filter.getExclude());
            if (filter.getExclude() != null && !filter.getExclude().booleanValue()) {
                hasIncludes = true;
            }
            tf.setMatchCatalog(filter.getMatchCatalog());
            tf.setMatchName(filter.getMatchName());
            tf.setMatchSchema(filter.getMatchSchema());
            repository.addTableFilter(tf);
        }
        ITableFilter tf = service.newTableFilter();
        tf.setExclude(Boolean.FALSE);
        // $NON-NLS-1$
        tf.setMatchCatalog(".*");
        // $NON-NLS-1$
        tf.setMatchSchema(".*");
        // $NON-NLS-1$
        tf.setMatchName(".*");
        repository.addTableFilter(tf);
        String dialogId = ReverseEngineeringEditor.class.getName();
        if (tableFilters.length == 0 && OptionalMessageDialog.isDialogEnabled(dialogId)) {
            int returnCode = OptionalMessageDialog.open(dialogId, getContainer().getShell(), MapperMessages.ReverseEngineeringEditor_no_filters_defined, null, MapperMessages.ReverseEngineeringEditor_no_filters_has_been_defined, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
            if (returnCode == Window.CANCEL)
                return null;
        }
        LazyDatabaseSchema lazyDatabaseSchema = new LazyDatabaseSchema(configuration, repository.getReverseEngineeringStrategy(service.newDefaultReverseEngineeringStrategy()));
        return lazyDatabaseSchema;
    } catch (Exception he) {
        HibernateConsolePlugin.getDefault().showError(getContainer().getShell(), MapperMessages.ReverseEngineeringEditor_error_while_refreshing_databasetree, he);
        return null;
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LazyDatabaseSchema(org.hibernate.eclipse.console.workbench.LazyDatabaseSchema) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 3 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class HibernateJpaProject method synchronizeJpaFiles.

@Override
protected boolean synchronizeJpaFiles(IFile file, int deltaKind) {
    boolean result = super.synchronizeJpaFiles(file, deltaKind);
    ConsoleConfiguration cc = getDefaultConsoleConfiguration();
    if (cc != null) {
        ConsoleConfigurationPreferences preferences = cc.getPreferences();
        if (file.getLocation().toFile().equals(preferences.getPropertyFile())) {
            switch(deltaKind) {
                case IResourceDelta.ADDED:
                case IResourceDelta.REMOVED:
                case IResourceDelta.CHANGED:
                    stateChanged();
                    revalidate();
            }
        }
    }
    return result;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences)

Example 4 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class HibernateJptPlugin method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    KnownConfigurations.getInstance().addConsoleConfigurationListener(new KnownConfigurationsAdapter() {

        private void revalidateProjects(ConsoleConfiguration ccfg) {
            // INFO: should revalidate project to calculate correct naming strategy's values
            JpaProjectManager manager = (JpaProjectManager) ResourcesPlugin.getWorkspace().getAdapter(JpaProjectManager.class);
            Iterator<JpaProject> jpaProjects = manager.getJpaProjects().iterator();
            while (jpaProjects.hasNext()) {
                JpaProject jpaProject = jpaProjects.next();
                if (jpaProject instanceof HibernateJpaProject) {
                    String ccName = ((HibernateJpaProject) jpaProject).getDefaultConsoleConfigurationName();
                    if (ccfg.getName().equals(ccName)) {
                        rebuildJpaProject(jpaProject.getJavaProject().getProject());
                    // jpaProject.getJavaProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
                    }
                }
            }
        }

        @Override
        public void configurationBuilt(ConsoleConfiguration ccfg) {
            if (ccfg.getConfiguration() == null) {
                return;
            }
            revalidateProjects(ccfg);
        }

        @Override
        public void configurationRemoved(ConsoleConfiguration root, boolean forUpdate) {
            if (forUpdate) {
                return;
            }
            revalidateProjects(root);
        }
    });
}
Also used : KnownConfigurationsAdapter(org.hibernate.console.KnownConfigurationsAdapter) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) JpaProjectManager(org.eclipse.jpt.jpa.core.JpaProjectManager) Iterator(java.util.Iterator) JpaProject(org.eclipse.jpt.jpa.core.JpaProject)

Example 5 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class JPAPostInstallFasetListener method getConnectionProperties.

public Properties getConnectionProperties(IProject project) {
    IJavaProject javaProject = JavaCore.create(project);
    IService service = null;
    if (javaProject != null) {
        HibernateNature hibNat = HibernateNature.getHibernateNature(javaProject);
        if (hibNat != null) {
            ConsoleConfiguration cc = hibNat.getDefaultConsoleConfiguration();
            if (cc != null) {
                service = cc.getHibernateExtension().getHibernateService();
            }
        }
    }
    String cpName = HibernateEclipseUtils.getConnectionProfileName(project);
    if (cpName != null && service != null) {
        return ConnectionProfileUtil.getHibernateConnectionProperties(service, ProfileManager.getInstance().getProfileByName(cpName));
    }
    return new Properties();
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) HibernateNature(org.hibernate.eclipse.nature.HibernateNature) Properties(java.util.Properties) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)107 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)19 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)17 CoreException (org.eclipse.core.runtime.CoreException)16 PartInitException (org.eclipse.ui.PartInitException)13 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 KnownConfigurations (org.hibernate.console.KnownConfigurations)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 TreePath (org.eclipse.jface.viewers.TreePath)10 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 FileNotFoundException (java.io.FileNotFoundException)8 IPath (org.eclipse.core.runtime.IPath)8 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 IService (org.jboss.tools.hibernate.runtime.spi.IService)8 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)7 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)7 GridLayout (org.eclipse.swt.layout.GridLayout)6