Example usage for org.hibernate.boot.internal InFlightMetadataCollectorImpl InFlightMetadataCollectorImpl

List of usage examples for org.hibernate.boot.internal InFlightMetadataCollectorImpl InFlightMetadataCollectorImpl

Introduction

In this page you can find the example usage for org.hibernate.boot.internal InFlightMetadataCollectorImpl InFlightMetadataCollectorImpl.

Prototype

public InFlightMetadataCollectorImpl(BootstrapContext bootstrapContext, MetadataBuildingOptions options) 

Source Link

Usage

From source file:org.openflexo.jdbc.hbn.MyDBTest.java

License:Open Source License

@Test
@TestOrder(3)//www.ja v a2 s  .  c om
public void createHbnConfig() {

    config = new HbnConfig(new BootstrapServiceRegistryBuilder().build());

    config.setProperty("hibernate.connection.driver_class", jdbcDriverClassname);
    config.setProperty("hibernate.connection.url", jdbcURL);
    config.setProperty("hibernate.connection.username", jdbcUser);
    config.setProperty("hibernate.connection.password", jdbcPwd);
    config.setProperty("hibernate.connection.pool_size", "1");
    config.setProperty("hibernate.dialect", hbnDialect);
    config.setProperty("hibernate.show_sql", "true");
    // creates object, wipe out if already exists
    // config.setProperty("hibernate.hbm2ddl.auto", "create-drop");

    buildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl(config.getServiceRegistry());
    metadataCollector = new InFlightMetadataCollectorImpl(buildingOptions, new TypeResolver());

    /*final Namespace namespace = metadataCollector.getDatabase().locateNamespace(
    getDatabase().toIdentifier( catalogName ),
    getDatabase().toIdentifier( schemaName )
    );*/

    Iterable<Namespace> namespaces = metadataCollector.getDatabase().getNamespaces();

    System.out.println("Prout debut");
    for (Namespace ns : namespaces) {
        System.out.println("> hop: " + ns);
    }
    System.out.println("Prout fin");

    Namespace namespace = metadataCollector.getDatabase().getDefaultNamespace();

    for (JDBCTable table : connection.getSchema().getTables()) {
        System.out.println("Found table:  " + table + " hop: " + table.getName());
        Identifier logicalName = metadataCollector.getDatabase().toIdentifier(table.getName());
        System.out.println("logicalName=" + logicalName);
        Table laTable = namespace.locateTable(logicalName);
        System.out.println("latable=" + laTable);
    }

    System.out.println(namespace.getTables());

}

From source file:org.openflexo.technologyadapter.jdbc.model.DynamicModelBuilder.java

License:Open Source License

public DynamicModelBuilder(HbnConfig aConfig) {

    super();/*from   w  w w  .  ja v a 2s  .  c  om*/
    config = aConfig;
    buildingOptions = new MetadataBuilderImpl.MetadataBuildingOptionsImpl(config.getServiceRegistry());

    metadataCollector = new InFlightMetadataCollectorImpl(buildingOptions, new TypeResolver());

    metadataBuildingContext = new MetadataBuildingContextRootImpl(buildingOptions,
            new ClassLoaderAccessImpl(null, config.getServiceRegistry()), metadataCollector);

}

From source file:org.teiid.spring.autoconfigure.SchemaBuilderUtility.java

License:Apache License

public static Metadata generateHbmModel(ConnectionProvider provider, Dialect dialect) throws SQLException {
    MetadataSources metadataSources = new MetadataSources();
    ServiceRegistry registry = metadataSources.getServiceRegistry();
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(
            (BootstrapServiceRegistry) registry).applySetting(AvailableSettings.DIALECT, TeiidDialect.class)
                    .addService(ConnectionProvider.class, provider).addService(JdbcEnvironment.class,
                            new JdbcEnvironmentImpl(provider.getConnection().getMetaData(), dialect))
                    .build();//  w w  w. j  a va 2s.c o  m

    ReverseEngineeringStrategy strategy = new DefaultReverseEngineeringStrategy();
    MetadataBuildingOptions options = new MetadataBuildingOptionsImpl(serviceRegistry);
    BasicTypeRegistry basicTypeRegistry = new BasicTypeRegistry();
    TypeResolver typeResolver = new TypeResolver(basicTypeRegistry, new TypeFactory());
    InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl(options, typeResolver);
    MetadataBuildingContext buildingContext = new MetadataBuildingContextRootImpl(options, null,
            metadataCollector);

    JDBCBinder binder = new JDBCBinder(serviceRegistry, new Properties(), buildingContext, strategy, false);
    Metadata metadata = metadataCollector.buildMetadataInstance(buildingContext);
    binder.readFromDatabase(null, null, buildMapping(metadata));
    HibernateMappingExporter exporter = new HibernateMappingExporter() {
        @Override
        protected Metadata getMetadata() {
            return metadata;
        }
    };
    exporter.start();
    return metadata;
}

From source file:org.teiid.spring.autoconfigure.SchemaBuilderUtility.java

License:Apache License

public static ArtifactCollector generateHibernateModel(MetadataFactory source,
        StandardServiceRegistry serviceRegistry) {
    ReverseEngineeringStrategy strategy = new DefaultReverseEngineeringStrategy();
    MetadataBuildingOptions options = new MetadataBuildingOptionsImpl(serviceRegistry);
    BasicTypeRegistry basicTypeRegistry = new BasicTypeRegistry();
    TypeResolver typeResolver = new TypeResolver(basicTypeRegistry, new TypeFactory());
    InFlightMetadataCollectorImpl metadataCollector = new InFlightMetadataCollectorImpl(options, typeResolver);
    MetadataBuildingContext buildingContext = new MetadataBuildingContextRootImpl(options, null,
            metadataCollector);//from  w  w  w  . ja  va2  s .  com

    TeiidJDBCBinder binder = new TeiidJDBCBinder(serviceRegistry, new Properties(), buildingContext, strategy,
            false, metadataCollector, source);
    Metadata metadata = metadataCollector.buildMetadataInstance(buildingContext);
    binder.readFromDatabase(null, null, buildMapping(metadata));

    HibernateMappingExporter exporter = new HibernateMappingExporter() {
        @Override
        protected Metadata getMetadata() {
            return metadata;
        }
    };
    exporter.setOutputDirectory(TMP_DIR);
    exporter.start();
    return exporter.getArtifactCollector();
}