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

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

Introduction

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

Prototype

public MetadataImpl buildMetadataInstance(MetadataBuildingContext buildingContext) 

Source Link

Document

Builds the complete and immutable Metadata instance from the collected info.

Usage

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();/*  www .ja  va  2 s.com*/

    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);// w ww  .  j  ava  2 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();
}