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

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

Introduction

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

Prototype

public MetadataBuildingContextRootImpl(BootstrapContext bootstrapContext, MetadataBuildingOptions options,
            InFlightMetadataCollector metadataCollector) 

Source Link

Usage

From source file:com.blazebit.persistence.integration.hibernate.Hibernate52MetadataContributor.java

License:Apache License

@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
    ServiceBinding.ServiceLifecycleOwner lifecycleOwner = (ServiceBinding.ServiceLifecycleOwner) metadataCollector
            .getMetadataBuildingOptions().getServiceRegistry();
    lifecycleOwner// ww  w  .  ja v  a  2  s.c  om
            .configureService(new ServiceBinding<>(lifecycleOwner, Hibernate52MetadataContributor.class, this));
    Object existingStrategy = configurationValues.get("hibernate.hql.bulk_id_strategy");
    if (existingStrategy == null) {
        JdbcServices jdbcService = metadataCollector.getMetadataBuildingOptions().getServiceRegistry()
                .getService(JdbcServices.class);
        MultiTableBulkIdStrategy defaultMultiTableBulkIdStrategy = jdbcService.getDialect()
                .getDefaultMultiTableBulkIdStrategy();
        configurationValues.put("hibernate.hql.bulk_id_strategy",
                new CustomMultiTableBulkIdStrategy(defaultMultiTableBulkIdStrategy));
    } else {
        LOG.warning("Can't replace hibernate.hql.bulk_id_strategy because it was overridden by the user with: "
                + existingStrategy);
    }
    // Skip if already registered
    if (metadataCollector
            .getEntityBinding("com.blazebit.persistence.impl.function.entity.ValuesEntity") != null) {
        return;
    }

    MetadataBuildingOptions options = metadataCollector.getMetadataBuildingOptions();
    final ClassLoaderService classLoaderService = options.getServiceRegistry()
            .getService(ClassLoaderService.class);

    final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(options.getTempClassLoader(),
            classLoaderService);

    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl(options,
            classLoaderAccess, metadataCollector);

    addEntity("com.blazebit.persistence.impl.function.entity.ValuesEntity", metadataBuildingContext);
}

From source file:com.blazebit.persistence.integration.hibernate.Hibernate53MetadataContributor.java

License:Apache License

@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
    ServiceBinding.ServiceLifecycleOwner lifecycleOwner = (ServiceBinding.ServiceLifecycleOwner) metadataCollector
            .getBootstrapContext().getServiceRegistry();
    lifecycleOwner/*from w  w  w  . j a v a  2 s. c  o m*/
            .configureService(new ServiceBinding<>(lifecycleOwner, Hibernate53MetadataContributor.class, this));
    Object existingStrategy = configurationValues.get("hibernate.hql.bulk_id_strategy");
    if (existingStrategy == null) {
        JdbcServices jdbcService = metadataCollector.getBootstrapContext().getServiceRegistry()
                .getService(JdbcServices.class);
        MultiTableBulkIdStrategy defaultMultiTableBulkIdStrategy = jdbcService.getDialect()
                .getDefaultMultiTableBulkIdStrategy();
        configurationValues.put("hibernate.hql.bulk_id_strategy",
                new CustomMultiTableBulkIdStrategy(defaultMultiTableBulkIdStrategy));
    } else {
        LOG.warning("Can't replace hibernate.hql.bulk_id_strategy because it was overridden by the user with: "
                + existingStrategy);
    }
    // Skip if already registered
    if (metadataCollector
            .getEntityBinding("com.blazebit.persistence.impl.function.entity.ValuesEntity") != null) {
        return;
    }

    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl(
            metadataCollector.getBootstrapContext(), metadataCollector.getMetadataBuildingOptions(),
            metadataCollector);

    addEntity("com.blazebit.persistence.impl.function.entity.ValuesEntity", metadataBuildingContext);
}

From source file:com.blazebit.persistence.integration.hibernate.Hibernate5MetadataContributor.java

License:Apache License

@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
    ServiceBinding.ServiceLifecycleOwner lifecycleOwner = (ServiceBinding.ServiceLifecycleOwner) metadataCollector
            .getMetadataBuildingOptions().getServiceRegistry();
    lifecycleOwner// w  w  w  .j  av a 2  s . c om
            .configureService(new ServiceBinding<>(lifecycleOwner, Hibernate5MetadataContributor.class, this));
    Object existingStrategy = configurationValues.get("hibernate.hql.bulk_id_strategy");
    if (existingStrategy == null) {
        JdbcServices jdbcService = metadataCollector.getMetadataBuildingOptions().getServiceRegistry()
                .getService(JdbcServices.class);
        MultiTableBulkIdStrategy defaultMultiTableBulkIdStrategy = jdbcService.getDialect()
                .getDefaultMultiTableBulkIdStrategy();
        configurationValues.put("hibernate.hql.bulk_id_strategy",
                new CustomMultiTableBulkIdStrategy(defaultMultiTableBulkIdStrategy));
    } else {
        LOG.warning("Can't replace hibernate.hql.bulk_id_strategy because it was overridden by the user with: "
                + existingStrategy);
    }
    // Skip if already registered
    if (metadataCollector
            .getEntityBinding("com.blazebit.persistence.impl.function.entity.ValuesEntity") != null) {
        return;
    }

    MetadataBuildingOptions options = metadataCollector.getMetadataBuildingOptions();
    final ClassLoaderService classLoaderService = options.getServiceRegistry()
            .getService(ClassLoaderService.class);

    final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(options.getTempClassLoader(),
            classLoaderService);

    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl(options,
            classLoaderAccess, metadataCollector);

    addEntity("com.blazebit.persistence.impl.function.entity.ValuesEntity", metadataBuildingContext);
}

From source file:com.blazebit.persistence.integration.hibernate.Hibernate60MetadataContributor.java

License:Apache License

@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
    // Skip if already registered
    if (metadataCollector
            .getEntityBinding("com.blazebit.persistence.impl.function.entity.ValuesEntity") != null) {
        return;//from   w  w  w  .  jav a2s.co  m
    }

    MetadataBuildingOptions options = metadataCollector.getMetadataBuildingOptions();
    final ClassLoaderService classLoaderService = options.getServiceRegistry()
            .getService(ClassLoaderService.class);

    final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(options.getTempClassLoader(),
            classLoaderService);

    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl(options,
            classLoaderAccess, metadataCollector);

    addEntity("com.blazebit.persistence.impl.function.entity.ValuesEntity", metadataBuildingContext);
}

From source file:org.grails.orm.hibernate.cfg.GrailsDomainBinder.java

License:Apache License

@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
    MetadataBuildingOptions options = metadataCollector.getMetadataBuildingOptions();
    ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);

    final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(options.getTempClassLoader(),
            classLoaderService);//  w w  w . jav  a  2 s .c o m

    this.metadataBuildingContext = new MetadataBuildingContextRootImpl(options, classLoaderAccess,
            metadataCollector);

    java.util.Collection<PersistentEntity> persistentEntities = hibernateMappingContext.getPersistentEntities();
    for (PersistentEntity persistentEntity : persistentEntities) {
        if (!persistentEntity.getJavaClass().isAnnotationPresent(Entity.class)) {
            if (ConnectionSourcesSupport.usesConnectionSource(persistentEntity, dataSourceName)
                    && persistentEntity.isRoot()) {
                bindRoot((HibernatePersistentEntity) persistentEntity, metadataCollector, sessionFactoryName);
            }
        }
    }
}

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

License:Open Source License

@Test
@TestOrder(5)/*w w  w. ja  v  a2s.c  o m*/
public void testDeclareJDBCMapping() {

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

    // ************************
    // Creation de l'entit persiste "Dynamic_Class"

    RootClass pClass = new RootClass(metadataBuildingContext);
    pClass.setEntityName("Dynamic_Class");
    pClass.setJpaEntityName("Dynamic_Class");
    pClass.setTable(table);
    metadataCollector.addEntityBinding(pClass);

    // Creation d'une proprit (clef) et son mapping

    Property prop = new Property();
    prop.setName("Nom");
    SimpleValue value = new SimpleValue((MetadataImplementor) metadata, table);
    value.setTypeName("java.lang.String");
    value.setIdentifierGeneratorStrategy("assigned");
    value.addColumn(col);
    value.setTable(table);
    prop.setValue(value);
    pClass.setDeclaredIdentifierProperty(prop);
    pClass.setIdentifierProperty(prop);
    pClass.setIdentifier(value);

    // Creation d'une proprit et son mapping

    prop = new Property();
    prop.setName("Prenom");
    value = new SimpleValue((MetadataImplementor) metadata, table);
    value.setTypeName(String.class.getCanonicalName());
    value.addColumn(col2);
    value.setTable(table);
    prop.setValue(value);
    pClass.addProperty(prop);

    // ************************
    // Creation de l'entit persiste "Adresse"

    RootClass pClass2 = new RootClass(metadataBuildingContext);
    pClass2.setEntityName("Adresse");
    pClass2.setJpaEntityName("Adresse");
    pClass2.setTable(table2);
    metadataCollector.addEntityBinding(pClass2);

    // Creation d'une proprit (clef) et son mapping

    prop = new Property();
    prop.setName("Identifiant");
    value = new SimpleValue((MetadataImplementor) metadata, table2);
    value.setTypeName("java.lang.Integer");
    value.setIdentifierGeneratorStrategy("native");
    value.addColumn(col4);
    value.setTable(table2);
    prop.setValue(value);
    pClass2.setDeclaredIdentifierProperty(prop);
    pClass2.setIdentifierProperty(prop);
    pClass2.setIdentifier(value);

    // Creation d'une proprit et son mapping

    prop = new Property();
    prop.setName("Prenom");
    value = new SimpleValue((MetadataImplementor) metadata, table2);
    value.setTypeName(String.class.getCanonicalName());
    value.addColumn(col5);
    value.setTable(table2);
    prop.setValue(value);
    pClass2.addProperty(prop);

    try {
        ((MetadataImplementor) metadata).validate();
    } catch (MappingException e) {
        System.out.println("Validation Error: " + e.getMessage());
    }

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

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

}

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

License:Open Source License

@Test
@TestOrder(8)//from   w ww  . j a  v a  2 s.c o  m
public void testConnectToDB() {

    System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>  On essaie de faire un truc");

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

    try (SessionFactory hbnSessionFactory = metadata.buildSessionFactory();
            Session hbnSession = hbnSessionFactory.withOptions().openSession()) {

        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());

        /*Map<String, String> syl = new HashMap<>();
        syl.put("Nom", "Sylvain2");
        Map<String, String> chris = new HashMap<>();
        chris.put("Nom", "Guychard2");
        chris.put("Prenom", "Christophe2");
                
        // Srialisation de l'instance
        // Hibernate native
        Transaction trans = hbnSession.beginTransaction();
                
        hbnSession.save("Dynamic_Class", syl);
        hbnSession.save("Dynamic_Class", chris);
                
        trans.commit();*/

        // NativeQuery<?> sqlQ = hbnSession.createNativeQuery("select * from T_Dynamic_Table_2;");

        Query<?> sqlQ = hbnSession.createQuery("select o from Dynamic_Class o");

        List<?> result = sqlQ.getResultList();
        assertEquals(5, result.size());

        for (Object o : result) {
            System.out.println(" > " + o + " of " + o.getClass());
            /*if (o.getClass().isArray()) {
               Object[] array = (Object[]) o;
               for (Object o2 : array) {
                  System.out.println("  >> " + o2);
               }
            }*/
        }

        Transaction t = hbnSession.beginTransaction();

        Map<String, Object> o1 = (Map<String, Object>) result.get(0);
        // Unused Map<String, Object> o2 = (Map<String, Object>)
        result.get(1);
        // Unused Map<String, Object> o3 = (Map<String, Object>)
        result.get(2);
        // Unused Map<String, Object> o4 = (Map<String, Object>)
        result.get(3);
        // Unused Map<String, Object> o5 = (Map<String, Object>)
        result.get(4);

        o1.put("Prenom", "toto");

        t.commit();

        /*System.out.println("DEBUT");
        Set<EntityType<?>> entities = hbnSession.getMetamodel().getEntities();
        for (EntityType<?> ent : entities) {
           System.out.println("Entit dynamique: " + ent.getName());
        }
        System.out.println("FIN");
                
        System.err.println(hbnSession.load("Dynamic_Class", "Sylvain"));*/
    }
}

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

License:Open Source License

public DynamicModelBuilder(HbnConfig aConfig) {

    super();//w ww  .ja  v  a2s  . 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();//from  w  w w .j  a  va 2  s.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 ww  . j  av a2s  .c o  m*/

    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();
}