Search in sources :

Example 11 with BootstrapContextImpl

use of org.hibernate.boot.internal.BootstrapContextImpl in project jbosstools-hibernate by jbosstools.

the class EntityMetamodelFacadeTest method createFooBarModel.

private EntityMetamodel createFooBarModel() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySetting(AvailableSettings.DIALECT, MockDialect.class.getName());
    builder.applySetting(AvailableSettings.CONNECTION_PROVIDER, MockConnectionProvider.class.getName());
    StandardServiceRegistry serviceRegistry = builder.build();
    MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuildingOptionsImpl(serviceRegistry);
    BootstrapContextImpl bootstrapContext = new BootstrapContextImpl(serviceRegistry, metadataBuildingOptions);
    metadataBuildingOptions.setBootstrapContext(bootstrapContext);
    InFlightMetadataCollector inFlightMetadataCollector = new InFlightMetadataCollectorImpl(bootstrapContext, metadataBuildingOptions);
    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl(bootstrapContext, metadataBuildingOptions, inFlightMetadataCollector);
    PersistentClass persistentClass = createPersistentClass(metadataBuildingContext);
    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    SessionFactoryImplementor sessionFactoryImplementor = (SessionFactoryImplementor) metadataSources.buildMetadata().buildSessionFactory();
    return new EntityMetamodel(persistentClass, null, sessionFactoryImplementor) {

        private static final long serialVersionUID = 1L;

        @Override
        public EntityTuplizer getTuplizer() {
            return (EntityTuplizer) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { EntityTuplizer.class }, new TestInvocationHandler());
        }

        @Override
        public Integer getPropertyIndexOrNull(String id) {
            methodName = "getPropertyIndexOrNull";
            arguments = new Object[] { id };
            return INDEX;
        }
    };
}
Also used : MockConnectionProvider(org.jboss.tools.hibernate.runtime.v_5_4.internal.util.MockConnectionProvider) EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataBuildingOptionsImpl(org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl) MockDialect(org.jboss.tools.hibernate.runtime.v_5_4.internal.util.MockDialect) MetadataSources(org.hibernate.boot.MetadataSources) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) BootstrapContextImpl(org.hibernate.boot.internal.BootstrapContextImpl) InFlightMetadataCollector(org.hibernate.boot.spi.InFlightMetadataCollector) InFlightMetadataCollectorImpl(org.hibernate.boot.internal.InFlightMetadataCollectorImpl) RootClass(org.hibernate.mapping.RootClass) PersistentClass(org.hibernate.mapping.PersistentClass) MetadataBuildingContextRootImpl(org.hibernate.boot.internal.MetadataBuildingContextRootImpl) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 12 with BootstrapContextImpl

use of org.hibernate.boot.internal.BootstrapContextImpl in project jbosstools-hibernate by jbosstools.

the class ColumnFacadeTest method createMetadataBuildingContext.

private MetadataBuildingContext createMetadataBuildingContext() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySetting(AvailableSettings.DIALECT, MockDialect.class.getName());
    builder.applySetting(AvailableSettings.CONNECTION_PROVIDER, MockConnectionProvider.class.getName());
    StandardServiceRegistry serviceRegistry = builder.build();
    MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuildingOptionsImpl(serviceRegistry);
    BootstrapContextImpl bootstrapContext = new BootstrapContextImpl(serviceRegistry, metadataBuildingOptions);
    metadataBuildingOptions.setBootstrapContext(bootstrapContext);
    InFlightMetadataCollector inFlightMetadataCollector = new InFlightMetadataCollectorImpl(bootstrapContext, metadataBuildingOptions);
    return new MetadataBuildingContextRootImpl(bootstrapContext, metadataBuildingOptions, inFlightMetadataCollector);
}
Also used : MockConnectionProvider(org.jboss.tools.hibernate.runtime.v_5_4.internal.util.MockConnectionProvider) InFlightMetadataCollector(org.hibernate.boot.spi.InFlightMetadataCollector) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuildingOptionsImpl(org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl) MockDialect(org.jboss.tools.hibernate.runtime.v_5_4.internal.util.MockDialect) InFlightMetadataCollectorImpl(org.hibernate.boot.internal.InFlightMetadataCollectorImpl) BootstrapContextImpl(org.hibernate.boot.internal.BootstrapContextImpl) MetadataBuildingContextRootImpl(org.hibernate.boot.internal.MetadataBuildingContextRootImpl) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Example 13 with BootstrapContextImpl

use of org.hibernate.boot.internal.BootstrapContextImpl in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateHQLQueryPlan.

@Test
public void testCreateHQLQueryPlan() {
    final Collection<PersistentClass> entityBindings = new ArrayList<PersistentClass>();
    final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
    standardServiceRegistryBuilder.applySetting(AvailableSettings.DIALECT, MockDialect.class.getName());
    standardServiceRegistryBuilder.applySetting(AvailableSettings.CONNECTION_PROVIDER, MockConnectionProvider.class.getName());
    final StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    Table t = new Table("FOO");
    Column c = new Column("foo");
    t.addColumn(c);
    PrimaryKey key = new PrimaryKey(t);
    key.addColumn(c);
    t.setPrimaryKey(key);
    @SuppressWarnings("deprecation") SimpleValue sv = new SimpleValue(metadata);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.setTable(t);
    sv.addColumn(c);
    final RootClass rc = new RootClass(null);
    rc.setEntityName("foo");
    rc.setJpaEntityName("foo");
    rc.setIdentifier(sv);
    rc.setTable(t);
    rc.setOptimisticLockStyle(OptimisticLockStyle.NONE);
    entityBindings.add(rc);
    MetadataImplementor wrapper = (MetadataImplementor) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { MetadataImplementor.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if ("getEntityBinding".equals(method.getName()) && args != null && args.length == 1 && "foo".equals(args[0])) {
                return rc;
            } else if ("getEntityBindings".equals(method.getName())) {
                return entityBindings;
            }
            return method.invoke(metadata, args);
        }
    });
    MetadataBuildingOptions mbo = new MetadataBuilderImpl.MetadataBuildingOptionsImpl(serviceRegistry);
    BootstrapContext bc = new BootstrapContextImpl(serviceRegistry, mbo);
    SessionFactoryImpl sfi = new SessionFactoryImpl(wrapper, new SessionFactoryOptionsBuilder(serviceRegistry, bc), HQLQueryPlan::new);
    Map<String, Filter> filters = Collections.emptyMap();
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ArrayList(java.util.ArrayList) MockDialect(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.MockDialect) MetadataSources(org.hibernate.boot.MetadataSources) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) BootstrapContext(org.hibernate.boot.spi.BootstrapContext) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) MetadataBuildingOptions(org.hibernate.boot.spi.MetadataBuildingOptions) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) MockConnectionProvider(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.MockConnectionProvider) RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) SessionFactoryOptionsBuilder(org.hibernate.boot.internal.SessionFactoryOptionsBuilder) Method(java.lang.reflect.Method) BootstrapContextImpl(org.hibernate.boot.internal.BootstrapContextImpl) InvocationHandler(java.lang.reflect.InvocationHandler) SimpleValue(org.hibernate.mapping.SimpleValue) HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) Filter(org.hibernate.Filter) PersistentClass(org.hibernate.mapping.PersistentClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) Test(org.junit.jupiter.api.Test)

Example 14 with BootstrapContextImpl

use of org.hibernate.boot.internal.BootstrapContextImpl in project jbosstools-hibernate by jbosstools.

the class EntityMetamodelFacadeTest method createFooBarModel.

private EntityMetamodel createFooBarModel() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySetting(AvailableSettings.DIALECT, MockDialect.class.getName());
    builder.applySetting(AvailableSettings.CONNECTION_PROVIDER, MockConnectionProvider.class.getName());
    StandardServiceRegistry serviceRegistry = builder.build();
    MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuildingOptionsImpl(serviceRegistry);
    BootstrapContextImpl bootstrapContext = new BootstrapContextImpl(serviceRegistry, metadataBuildingOptions);
    metadataBuildingOptions.setBootstrapContext(bootstrapContext);
    InFlightMetadataCollector inFlightMetadataCollector = new InFlightMetadataCollectorImpl(bootstrapContext, metadataBuildingOptions);
    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl(bootstrapContext, metadataBuildingOptions, inFlightMetadataCollector);
    PersisterCreationContext persisterCreationContext = createPersisterCreationContext(serviceRegistry, bootstrapContext);
    PersistentClass persistentClass = createPersistentClass(metadataBuildingContext);
    return new EntityMetamodel(persistentClass, null, persisterCreationContext) {

        private static final long serialVersionUID = 1L;

        @Override
        public EntityTuplizer getTuplizer() {
            return (EntityTuplizer) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { EntityTuplizer.class }, new TestInvocationHandler());
        }

        @Override
        public Integer getPropertyIndexOrNull(String id) {
            methodName = "getPropertyIndexOrNull";
            arguments = new Object[] { id };
            return INDEX;
        }
    };
}
Also used : MockConnectionProvider(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.MockConnectionProvider) EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuildingOptionsImpl(org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl) MockDialect(org.jboss.tools.hibernate.runtime.v_5_6.internal.util.MockDialect) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) BootstrapContextImpl(org.hibernate.boot.internal.BootstrapContextImpl) PersisterCreationContext(org.hibernate.persister.spi.PersisterCreationContext) InFlightMetadataCollector(org.hibernate.boot.spi.InFlightMetadataCollector) InFlightMetadataCollectorImpl(org.hibernate.boot.internal.InFlightMetadataCollectorImpl) RootClass(org.hibernate.mapping.RootClass) PersistentClass(org.hibernate.mapping.PersistentClass) MetadataBuildingContextRootImpl(org.hibernate.boot.internal.MetadataBuildingContextRootImpl) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 15 with BootstrapContextImpl

use of org.hibernate.boot.internal.BootstrapContextImpl in project jbosstools-hibernate by jbosstools.

the class ClassMetadataFacadeTest method setupFooBarPersister.

private ClassMetadata setupFooBarPersister() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySetting(AvailableSettings.DIALECT, MockDialect.class.getName());
    builder.applySetting(AvailableSettings.CONNECTION_PROVIDER, MockConnectionProvider.class.getName());
    StandardServiceRegistry serviceRegistry = builder.build();
    MetadataBuildingOptionsImpl metadataBuildingOptions = new MetadataBuildingOptionsImpl(serviceRegistry);
    BootstrapContextImpl bootstrapContext = new BootstrapContextImpl(serviceRegistry, metadataBuildingOptions);
    metadataBuildingOptions.setBootstrapContext(bootstrapContext);
    InFlightMetadataCollector inFlightMetadataCollector = new InFlightMetadataCollectorImpl(bootstrapContext, metadataBuildingOptions);
    MetadataBuildingContext metadataBuildingContext = new MetadataBuildingContextRootImpl("JBoss Tools", bootstrapContext, metadataBuildingOptions, inFlightMetadataCollector);
    AbstractEntityPersister result = new TestEntityPersister(createPersistentClass(metadataBuildingContext), createPersisterCreationContext(serviceRegistry, bootstrapContext));
    return result;
}
Also used : MockConnectionProvider(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MockConnectionProvider) InFlightMetadataCollector(org.hibernate.boot.spi.InFlightMetadataCollector) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataBuildingOptionsImpl(org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl) MockDialect(org.jboss.tools.hibernate.runtime.v_6_0.internal.util.MockDialect) InFlightMetadataCollectorImpl(org.hibernate.boot.internal.InFlightMetadataCollectorImpl) MetadataBuildingContext(org.hibernate.boot.spi.MetadataBuildingContext) BootstrapContextImpl(org.hibernate.boot.internal.BootstrapContextImpl) MetadataBuildingContextRootImpl(org.hibernate.boot.internal.MetadataBuildingContextRootImpl) AbstractEntityPersister(org.hibernate.persister.entity.AbstractEntityPersister) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry)

Aggregations

BootstrapContextImpl (org.hibernate.boot.internal.BootstrapContextImpl)29 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)29 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)29 InFlightMetadataCollectorImpl (org.hibernate.boot.internal.InFlightMetadataCollectorImpl)24 MetadataBuildingContextRootImpl (org.hibernate.boot.internal.MetadataBuildingContextRootImpl)24 InFlightMetadataCollector (org.hibernate.boot.spi.InFlightMetadataCollector)23 MetadataBuildingOptionsImpl (org.hibernate.boot.internal.MetadataBuilderImpl.MetadataBuildingOptionsImpl)15 BootstrapContext (org.hibernate.boot.spi.BootstrapContext)14 MetadataBuildingContext (org.hibernate.boot.spi.MetadataBuildingContext)14 MetadataBuildingOptions (org.hibernate.boot.spi.MetadataBuildingOptions)13 RootClass (org.hibernate.mapping.RootClass)13 Test (org.junit.jupiter.api.Test)9 PersistentClass (org.hibernate.mapping.PersistentClass)8 MetadataSources (org.hibernate.boot.MetadataSources)7 ArrayList (java.util.ArrayList)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)5 InvocationHandler (java.lang.reflect.InvocationHandler)4 Method (java.lang.reflect.Method)4 Filter (org.hibernate.Filter)4 SessionFactoryOptionsBuilder (org.hibernate.boot.internal.SessionFactoryOptionsBuilder)4