Search in sources :

Example 86 with MetadataSources

use of org.hibernate.boot.MetadataSources in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsComponentType.

@Test
public void testIsComponentType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertFalse(typeFacade.isComponentType());
    MetadataBuildingOptions mdbo = new MetadataBuilderImpl.MetadataBuildingOptionsImpl(new StandardServiceRegistryBuilder().build());
    MetadataImplementor mdi = (MetadataImplementor) new MetadataBuilderImpl(new MetadataSources()).build();
    ComponentType componentType = new ComponentType(null, new ComponentMetamodel(new Component(mdi, new RootClass(null)), mdbo));
    typeFacade = FACADE_FACTORY.createType(componentType);
    Assert.assertTrue(typeFacade.isComponentType());
}
Also used : RootClass(org.hibernate.mapping.RootClass) ComponentType(org.hibernate.type.ComponentType) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ComponentMetamodel(org.hibernate.tuple.component.ComponentMetamodel) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ClassType(org.hibernate.type.ClassType) Component(org.hibernate.mapping.Component) MetadataBuilderImpl(org.hibernate.boot.internal.MetadataBuilderImpl) IType(org.jboss.tools.hibernate.runtime.spi.IType) MetadataBuildingOptions(org.hibernate.boot.spi.MetadataBuildingOptions) Test(org.junit.Test)

Example 87 with MetadataSources

use of org.hibernate.boot.MetadataSources in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsComponentType.

@Test
public void testIsComponentType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertFalse(typeFacade.isComponentType());
    MetadataBuildingOptions mdbo = new MetadataBuilderImpl.MetadataBuildingOptionsImpl(new StandardServiceRegistryBuilder().build());
    MetadataImplementor mdi = (MetadataImplementor) new MetadataBuilderImpl(new MetadataSources()).build();
    ComponentType componentType = new ComponentType(null, new ComponentMetamodel(new Component(mdi, new RootClass(null)), mdbo));
    typeFacade = FACADE_FACTORY.createType(componentType);
    Assert.assertTrue(typeFacade.isComponentType());
}
Also used : RootClass(org.hibernate.mapping.RootClass) ComponentType(org.hibernate.type.ComponentType) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ComponentMetamodel(org.hibernate.tuple.component.ComponentMetamodel) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ClassType(org.hibernate.type.ClassType) Component(org.hibernate.mapping.Component) MetadataBuilderImpl(org.hibernate.boot.internal.MetadataBuilderImpl) IType(org.jboss.tools.hibernate.runtime.spi.IType) MetadataBuildingOptions(org.hibernate.boot.spi.MetadataBuildingOptions) Test(org.junit.Test)

Example 88 with MetadataSources

use of org.hibernate.boot.MetadataSources in project jbosstools-hibernate by jbosstools.

the class ClassMetadataFacadeTest method createSampleEntityPersister.

private TestEntityPersister createSampleEntityPersister() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    ServiceRegistry serviceRegistry = builder.build();
    MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) metadata.buildSessionFactory();
    RootClass rc = new RootClass(null);
    Table t = new Table("foobar");
    rc.setTable(t);
    Column c = new Column("foo");
    t.addColumn(c);
    ArrayList<Column> keyList = new ArrayList<>();
    keyList.add(c);
    t.createUniqueKey(keyList);
    SimpleValue sv = new SimpleValue(metadata);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.addColumn(c);
    rc.setEntityName("foobar");
    rc.setIdentifier(sv);
    return new TestEntityPersister(rc, sfi, metadata);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) ArrayList(java.util.ArrayList) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) SimpleValue(org.hibernate.mapping.SimpleValue) Column(org.hibernate.mapping.Column) ServiceRegistry(org.hibernate.service.ServiceRegistry)

Example 89 with MetadataSources

use of org.hibernate.boot.MetadataSources 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("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    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);
    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);
    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);
        }
    });
    SessionFactoryImpl sfi = new SessionFactoryImpl(wrapper, new SessionFactoryOptionsBuilder(serviceRegistry));
    Map<String, Filter> filters = Collections.emptyMap();
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    Assert.assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryOptionsBuilder(org.hibernate.boot.internal.SessionFactoryOptionsBuilder) ArrayList(java.util.ArrayList) MetadataSources(org.hibernate.boot.MetadataSources) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Method(java.lang.reflect.Method) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) 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) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) 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) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 90 with MetadataSources

use of org.hibernate.boot.MetadataSources in project jbosstools-hibernate by jbosstools.

the class ColumnFacadeTest method testGetValue.

public void testGetValue() throws Exception {
    Value targetValue = null;
    column.setValue(targetValue);
    Assert.assertNull(columnFacade.getValue());
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
    ssrb.applySetting(Environment.DIALECT, "org.hibernate.dialect.H2Dialect");
    StandardServiceRegistry ssr = ssrb.build();
    MetadataSources metadataSources = new MetadataSources(ssr);
    MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    targetValue = new SimpleValue(metadata);
    column.setValue(targetValue);
    IValue value = columnFacade.getValue();
    Assert.assertNotNull(value);
    Assert.assertEquals(targetValue, ((IFacade) value).getTarget());
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SimpleValue(org.hibernate.mapping.SimpleValue) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) Value(org.hibernate.mapping.Value) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SimpleValue(org.hibernate.mapping.SimpleValue)

Aggregations

MetadataSources (org.hibernate.boot.MetadataSources)293 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)193 Test (org.junit.Test)192 Metadata (org.hibernate.boot.Metadata)123 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)120 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)76 TestForIssue (org.hibernate.testing.TestForIssue)57 PersistentClass (org.hibernate.mapping.PersistentClass)53 SchemaExport (org.hibernate.tool.hbm2ddl.SchemaExport)41 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)37 Before (org.junit.Before)33 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)30 ServiceRegistry (org.hibernate.service.ServiceRegistry)26 RootClass (org.hibernate.mapping.RootClass)25 HashMap (java.util.HashMap)20 SimpleValue (org.hibernate.mapping.SimpleValue)20 SchemaUpdate (org.hibernate.tool.hbm2ddl.SchemaUpdate)20 File (java.io.File)19 Property (org.hibernate.mapping.Property)18 Map (java.util.Map)17