Search in sources :

Example 1 with IOverrideRepository

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

the class ConsoleExtension method buildConfiguration.

private IConfiguration buildConfiguration(final ExporterAttributes attributes, ConsoleConfiguration cc, IWorkspaceRoot root) {
    final boolean reveng = attributes.isReverseEngineer();
    final String reverseEngineeringStrategy = attributes.getRevengStrategy();
    final boolean preferBasicCompositeids = attributes.isPreferBasicCompositeIds();
    final IResource revengres = PathHelper.findMember(root, attributes.getRevengSettings());
    if (reveng) {
        IConfiguration configuration = null;
        if (cc.hasConfiguration()) {
            configuration = cc.getConfiguration();
        } else {
            configuration = cc.buildWith(null, false);
        }
        final IConfiguration cfg = hibernateExtension.getHibernateService().newJDBCMetaDataConfiguration();
        // final JDBCMetaDataConfiguration cfg = new
        // JDBCMetaDataConfiguration();
        Properties properties = configuration.getProperties();
        cfg.setProperties(properties);
        cc.buildWith(cfg, false);
        cfg.setPreferBasicCompositeIds(preferBasicCompositeids);
        cc.execute(new // need to execute in the
        Command() {

            // consoleconfiguration to let it handle
            // classpath stuff!
            public Object execute() {
                // todo: factor this setup of revengstrategy to core
                IService service = hibernateExtension.getHibernateService();
                IReverseEngineeringStrategy res = service.newDefaultReverseEngineeringStrategy();
                IOverrideRepository repository = null;
                if (revengres != null) {
                    File file = PathHelper.getLocation(revengres).toFile();
                    repository = service.newOverrideRepository();
                    repository.addFile(file);
                }
                if (repository != null) {
                    res = repository.getReverseEngineeringStrategy(res);
                }
                if (reverseEngineeringStrategy != null && reverseEngineeringStrategy.trim().length() > 0) {
                    res = service.newReverseEngineeringStrategy(reverseEngineeringStrategy, res);
                }
                IReverseEngineeringSettings qqsettings = service.newReverseEngineeringSettings(res).setDefaultPackageName(attributes.getPackageName()).setDetectManyToMany(attributes.detectManyToMany()).setDetectOneToOne(attributes.detectOneToOne()).setDetectOptimisticLock(attributes.detectOptimisticLock());
                res.setSettings(qqsettings);
                cfg.setReverseEngineeringStrategy(res);
                cfg.readFromJDBC();
                cfg.buildMappings();
                return null;
            }
        });
        return cfg;
    } else {
        cc.build();
        cc.buildMappings();
        return cc.getConfiguration();
    }
}
Also used : IReverseEngineeringSettings(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringSettings) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Properties(java.util.Properties) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 2 with IOverrideRepository

use of org.jboss.tools.hibernate.runtime.spi.IOverrideRepository 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 IOverrideRepository

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

the class FacadeFactoryTest method testCreateOverrideRepository.

@Test
public void testCreateOverrideRepository() {
    OverrideRepository overrideRepository = new OverrideRepository();
    IOverrideRepository facade = facadeFactory.createOverrideRepository(overrideRepository);
    Assert.assertSame(overrideRepository, ((IFacade) facade).getTarget());
}
Also used : OverrideRepository(org.hibernate.cfg.reveng.OverrideRepository) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) Test(org.junit.Test)

Example 4 with IOverrideRepository

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

the class FacadeFactoryTest method testCreateOverrideRepository.

@Test
public void testCreateOverrideRepository() {
    OverrideRepository overrideRepository = new OverrideRepository();
    IOverrideRepository facade = facadeFactory.createOverrideRepository(overrideRepository);
    Assert.assertSame(overrideRepository, ((IFacade) facade).getTarget());
}
Also used : OverrideRepository(org.hibernate.cfg.reveng.OverrideRepository) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) Test(org.junit.Test)

Example 5 with IOverrideRepository

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

the class FacadeFactoryTest method testCreateOverrideRepository.

@Test
public void testCreateOverrideRepository() {
    OverrideRepository overrideRepository = new OverrideRepository();
    IOverrideRepository facade = facadeFactory.createOverrideRepository(overrideRepository);
    Assert.assertSame(overrideRepository, ((IFacade) facade).getTarget());
}
Also used : OverrideRepository(org.hibernate.cfg.reveng.OverrideRepository) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) IOverrideRepository(org.jboss.tools.hibernate.runtime.spi.IOverrideRepository) Test(org.junit.Test)

Aggregations

IOverrideRepository (org.jboss.tools.hibernate.runtime.spi.IOverrideRepository)15 OverrideRepository (org.hibernate.cfg.reveng.OverrideRepository)12 Test (org.junit.Test)12 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)4 IService (org.jboss.tools.hibernate.runtime.spi.IService)3 File (java.io.File)2 Properties (java.util.Properties)2 IResource (org.eclipse.core.resources.IResource)2 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)2 IReverseEngineeringSettings (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringSettings)2 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)2 CoreException (org.eclipse.core.runtime.CoreException)1 PartInitException (org.eclipse.ui.PartInitException)1 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)1 LazyDatabaseSchema (org.hibernate.eclipse.console.workbench.LazyDatabaseSchema)1 ITableFilter (org.jboss.tools.hibernate.runtime.spi.ITableFilter)1