Search in sources :

Example 6 with RevengStrategy

use of org.hibernate.tool.api.reveng.RevengStrategy in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method collectDatabaseTables.

@Override
public Map<String, List<ITable>> collectDatabaseTables(Properties properties, IReverseEngineeringStrategy strategy, final IProgressListener progressListener) {
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(properties).build();
    MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuildingOptionsImpl(serviceRegistry);
    BootstrapContextImpl bootstrapContext = new BootstrapContextImpl(serviceRegistry, metadataBuildingOptions);
    metadataBuildingOptions.setBootstrapContext(bootstrapContext);
    InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl(bootstrapContext, metadataBuildingOptions);
    RevengDialect mdd = RevengDialectFactory.createMetaDataDialect(serviceRegistry.getService(JdbcServices.class).getDialect(), properties);
    RevengStrategy revengStrategy = (RevengStrategy) ((IFacade) strategy).getTarget();
    DatabaseReader reader = DatabaseReader.create(properties, revengStrategy, mdd, serviceRegistry);
    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl("JBoss Tools", bootstrapContext, metadataBuildingOptions, metadataCollector);
    RevengMetadataCollector revengMetadataCollector = new RevengMetadataCollector(metadataBuildingContext);
    reader.readDatabaseSchema(revengMetadataCollector);
    Map<String, List<ITable>> result = new HashMap<String, List<ITable>>();
    for (Table table : revengMetadataCollector.getTables()) {
        String qualifier = "";
        if (table.getCatalog() != null) {
            qualifier += table.getCatalog();
        }
        if (table.getSchema() != null) {
            if (!"".equals(qualifier)) {
                qualifier += ".";
            }
            qualifier += table.getSchema();
        }
        List<ITable> list = result.get(qualifier);
        if (list == null) {
            list = new ArrayList<ITable>();
            result.put(qualifier, list);
        }
        list.add(facadeFactory.createTable(table));
    }
    return result;
}
Also used : ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) MetadataBuildingOptionsImpl(org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl) RevengMetadataCollector(org.hibernate.tool.internal.reveng.RevengMetadataCollector) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) DummyMetadataBuildingContext(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.DummyMetadataBuildingContext) BootstrapContextImpl(org.hibernate.boot.internal.BootstrapContextImpl) RevengStrategy(org.hibernate.tool.api.reveng.RevengStrategy) InFlightMetadataCollectorImpl(org.hibernate.boot.internal.InFlightMetadataCollectorImpl) DatabaseReader(org.hibernate.tool.internal.reveng.reader.DatabaseReader) RevengDialect(org.hibernate.tool.api.reveng.RevengDialect) List(java.util.List) ArrayList(java.util.ArrayList) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) MetadataBuildingContextRootImpl(org.hibernate.boot.internal.MetadataBuildingContextRootImpl) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 7 with RevengStrategy

use of org.hibernate.tool.api.reveng.RevengStrategy in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateReverseEngineeringStrategy.

@Test
public void testCreateReverseEngineeringStrategy() {
    RevengStrategy res = (RevengStrategy) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { RevengStrategy.class }, new TestInvocationHandler());
    IReverseEngineeringStrategy facade = facadeFactory.createReverseEngineeringStrategy(res);
    assertTrue(facade instanceof ReverseEngineeringStrategyFacadeImpl);
    assertSame(res, ((IFacade) facade).getTarget());
}
Also used : RevengStrategy(org.hibernate.tool.api.reveng.RevengStrategy) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.internal.export.java.POJOClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) Test(org.junit.jupiter.api.Test)

Example 8 with RevengStrategy

use of org.hibernate.tool.api.reveng.RevengStrategy in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testSetReverseEngineeringStrategy.

@Test
public void testSetReverseEngineeringStrategy() {
    JdbcMetadataConfiguration configuration = new JdbcMetadataConfiguration();
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    RevengStrategy reverseEngineeringStrategy = new DefaultStrategy();
    IReverseEngineeringStrategy strategyFacade = FACADE_FACTORY.createReverseEngineeringStrategy(reverseEngineeringStrategy);
    assertNotSame(reverseEngineeringStrategy, configuration.getReverseEngineeringStrategy());
    configurationFacade.setReverseEngineeringStrategy(strategyFacade);
    assertSame(reverseEngineeringStrategy, configuration.getReverseEngineeringStrategy());
}
Also used : RevengStrategy(org.hibernate.tool.api.reveng.RevengStrategy) IReverseEngineeringStrategy(org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy) JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.JdbcMetadataConfiguration) DefaultStrategy(org.hibernate.tool.internal.reveng.strategy.DefaultStrategy) Test(org.junit.jupiter.api.Test) MetadataHelperTest(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MetadataHelperTest)

Example 9 with RevengStrategy

use of org.hibernate.tool.api.reveng.RevengStrategy in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeImpl method setReverseEngineeringStrategy.

@Override
public void setReverseEngineeringStrategy(IReverseEngineeringStrategy res) {
    if (getTarget() instanceof JdbcMetadataConfiguration) {
        RevengStrategy revengStrategy = (RevengStrategy) ((IFacade) res).getTarget();
        ((JdbcMetadataConfiguration) getTarget()).setReverseEngineeringStrategy(revengStrategy);
    }
}
Also used : RevengStrategy(org.hibernate.tool.api.reveng.RevengStrategy) JdbcMetadataConfiguration(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.JdbcMetadataConfiguration)

Aggregations

RevengStrategy (org.hibernate.tool.api.reveng.RevengStrategy)9 Test (org.junit.jupiter.api.Test)6 DefaultStrategy (org.hibernate.tool.internal.reveng.strategy.DefaultStrategy)5 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)4 Field (java.lang.reflect.Field)2 JdbcMetadataConfiguration (org.jboss.tools.hibernate.runtime.v_6_0.internal.util.JdbcMetadataConfiguration)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 BootstrapContextImpl (org.hibernate.boot.internal.BootstrapContextImpl)1 InFlightMetadataCollectorImpl (org.hibernate.boot.internal.InFlightMetadataCollectorImpl)1 MetadataBuildingOptionsImpl (org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl)1 MetadataBuildingContextRootImpl (org.hibernate.boot.internal.MetadataBuildingContextRootImpl)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 MetadataBuildingContext (org.hibernate.boot.spi.MetadataBuildingContext)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 RootClass (org.hibernate.mapping.RootClass)1 Table (org.hibernate.mapping.Table)1 RevengDialect (org.hibernate.tool.api.reveng.RevengDialect)1