Search in sources :

Example 26 with IReverseEngineeringStrategy

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

the class ServiceImplTest method testNewReverseEngineeringSettings.

@Test
public void testNewReverseEngineeringSettings() {
    IReverseEngineeringStrategy strategy = service.newDefaultReverseEngineeringStrategy();
    IReverseEngineeringSettings reverseEngineeringSettings = service.newReverseEngineeringSettings(strategy);
    Assert.assertNotNull(reverseEngineeringSettings);
    Object target = ((IFacade) reverseEngineeringSettings).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof ReverseEngineeringSettings);
}
Also used : IReverseEngineeringSettings(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringSettings) ReverseEngineeringSettings(org.hibernate.cfg.reveng.ReverseEngineeringSettings) IReverseEngineeringSettings(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringSettings) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Test(org.junit.Test)

Example 27 with IReverseEngineeringStrategy

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

the class ServiceImplTest method testNewJDBCReader.

@Test
public void testNewJDBCReader() {
    IConfiguration configuration = service.newDefaultConfiguration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    IReverseEngineeringStrategy strategy = service.newDefaultReverseEngineeringStrategy();
    IJDBCReader jdbcReader = service.newJDBCReader(configuration, strategy);
    Assert.assertNotNull(jdbcReader);
    Object target = ((IFacade) jdbcReader).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof JDBCReader);
}
Also used : IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) IJDBCReader(org.jboss.tools.hibernate.runtime.spi.IJDBCReader) IJDBCReader(org.jboss.tools.hibernate.runtime.spi.IJDBCReader) JDBCReader(org.hibernate.cfg.reveng.JDBCReader) Test(org.junit.Test)

Example 28 with IReverseEngineeringStrategy

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

the class CodeGenerationLaunchDelegate 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 JDBCMetaDataConfiguration cfg = new JDBCMetaDataConfiguration();
        final IService service = cc.getHibernateExtension().getHibernateService();
        final IConfiguration cfg = service.newJDBCMetaDataConfiguration();
        Properties properties = configuration.getProperties();
        cfg.setProperties(properties);
        cc.buildWith(cfg, false);
        cfg.setPreferBasicCompositeIds(preferBasicCompositeids);
        cc.execute(new // need to execute in the consoleconfiguration to let it handle classpath stuff!
        Command() {

            public Object execute() {
                // todo: factor this setup of revengstrategy to core
                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 29 with IReverseEngineeringStrategy

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

the class ServiceImpl method newReverseEngineeringStrategy.

@Override
public IReverseEngineeringStrategy newReverseEngineeringStrategy(String strategyName, IReverseEngineeringStrategy delegate) {
    assert delegate instanceof IFacade;
    ReverseEngineeringStrategy delegateTarget = (ReverseEngineeringStrategy) ((IFacade) delegate).getTarget();
    Object target = newReverseEngineeringStrategy(strategyName, delegateTarget);
    return facadeFactory.createReverseEngineeringStrategy(target);
}
Also used : IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) DefaultReverseEngineeringStrategy(org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy) ReverseEngineeringStrategy(org.hibernate.cfg.reveng.ReverseEngineeringStrategy) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade)

Example 30 with IReverseEngineeringStrategy

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

the class ConfigurationFacadeTest method testSetReverseEngineeringStrategy.

@Test
public void testSetReverseEngineeringStrategy() {
    JDBCMetaDataConfiguration configuration = new JDBCMetaDataConfiguration();
    configurationFacade = FACADE_FACTORY.createConfiguration(configuration);
    ReverseEngineeringStrategy reverseEngineeringStrategy = new DefaultReverseEngineeringStrategy();
    IReverseEngineeringStrategy strategyFacade = FACADE_FACTORY.createReverseEngineeringStrategy(reverseEngineeringStrategy);
    Assert.assertNotSame(reverseEngineeringStrategy, configuration.getReverseEngineeringStrategy());
    configurationFacade.setReverseEngineeringStrategy(strategyFacade);
    Assert.assertSame(reverseEngineeringStrategy, configuration.getReverseEngineeringStrategy());
}
Also used : JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) DefaultReverseEngineeringStrategy(org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy) ReverseEngineeringStrategy(org.hibernate.cfg.reveng.ReverseEngineeringStrategy) DefaultReverseEngineeringStrategy(org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy) Test(org.junit.Test)

Aggregations

IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)50 Test (org.junit.Test)44 DefaultReverseEngineeringStrategy (org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy)36 ReverseEngineeringStrategy (org.hibernate.cfg.reveng.ReverseEngineeringStrategy)32 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)20 DelegatingReverseEngineeringStrategy (org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy)16 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)10 Field (java.lang.reflect.Field)8 JDBCReader (org.hibernate.cfg.reveng.JDBCReader)8 PersistentClass (org.hibernate.mapping.PersistentClass)8 RootClass (org.hibernate.mapping.RootClass)8 POJOClass (org.hibernate.tool.hbm2x.pojo.POJOClass)8 IJDBCReader (org.jboss.tools.hibernate.runtime.spi.IJDBCReader)8 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)8 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)8 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)7 IReverseEngineeringSettings (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringSettings)6 Configuration (org.hibernate.cfg.Configuration)4 ReverseEngineeringSettings (org.hibernate.cfg.reveng.ReverseEngineeringSettings)4 File (java.io.File)2