Search in sources :

Example 6 with Mappings

use of org.hibernate.cfg.Mappings in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateHQLQueryPlan.

@Test
public void testCreateHQLQueryPlan() {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    Mappings mappings = configuration.createMappings();
    Table t = new Table("FOO");
    Column c = new Column("foo");
    t.addColumn(c);
    PrimaryKey key = new PrimaryKey();
    key.addColumn(c);
    t.setPrimaryKey(key);
    Mappings m = configuration.createMappings();
    SimpleValue sv = new SimpleValue(m);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.setTable(t);
    sv.addColumn(c);
    RootClass rc = new RootClass();
    rc.setEntityName("foo");
    rc.setJpaEntityName("foo");
    rc.setIdentifier(sv);
    rc.setTable(t);
    mappings.addClass(rc);
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.build();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(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) Configuration(org.hibernate.cfg.Configuration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) SimpleValue(org.hibernate.mapping.SimpleValue) HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Mappings(org.hibernate.cfg.Mappings) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Filter(org.hibernate.Filter) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) ServiceRegistry(org.hibernate.service.ServiceRegistry) Test(org.junit.Test)

Example 7 with Mappings

use of org.hibernate.cfg.Mappings in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateEntityMetamodel.

@Test
public void testCreateEntityMetamodel() {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.build();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(serviceRegistry);
    RootClass rc = new RootClass();
    Mappings m = configuration.createMappings();
    SimpleValue sv = new SimpleValue(m);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    rc.setIdentifier(sv);
    EntityMetamodel entityMetamodel = new EntityMetamodel(rc, null, sfi);
    IEntityMetamodel facade = facadeFactory.createEntityMetamodel(entityMetamodel);
    Assert.assertSame(entityMetamodel, ((IFacade) facade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) Configuration(org.hibernate.cfg.Configuration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Mappings(org.hibernate.cfg.Mappings) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ServiceRegistry(org.hibernate.service.ServiceRegistry) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 8 with Mappings

use of org.hibernate.cfg.Mappings in project jbosstools-hibernate by jbosstools.

the class Cfg2HbmToolFacadeTest method testGetPropertyTag.

public void testGetPropertyTag() throws Exception {
    RootClass rc = new RootClass();
    Property p = new Property();
    Mappings m = (Mappings) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { Mappings.class }, new TestInvocationHandler());
    SimpleValue sv = new SimpleValue(m);
    sv.setTypeName("foobar");
    p.setValue(sv);
    p.setPersistentClass(rc);
    rc.setVersion(p);
    IProperty property = new AbstractPropertyFacade(FACADE_FACTORY, p) {
    };
    Assert.assertEquals("version", cfg2HbmToolFacade.getTag(property));
}
Also used : RootClass(org.hibernate.mapping.RootClass) Mappings(org.hibernate.cfg.Mappings) AbstractPropertyFacade(org.jboss.tools.hibernate.runtime.common.AbstractPropertyFacade) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass) Property(org.hibernate.mapping.Property) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 9 with Mappings

use of org.hibernate.cfg.Mappings in project jbosstools-hibernate by jbosstools.

the class Cfg2HbmToolFacadeTest method testGetPropertyTag.

public void testGetPropertyTag() throws Exception {
    RootClass rc = new RootClass();
    Property p = new Property();
    Mappings m = (Mappings) Proxy.newProxyInstance(FACADE_FACTORY.getClassLoader(), new Class[] { Mappings.class }, new TestInvocationHandler());
    SimpleValue sv = new SimpleValue(m);
    sv.setTypeName("foobar");
    p.setValue(sv);
    p.setPersistentClass(rc);
    rc.setVersion(p);
    IProperty property = new AbstractPropertyFacade(FACADE_FACTORY, p) {
    };
    Assert.assertEquals("version", cfg2HbmToolFacade.getTag(property));
}
Also used : RootClass(org.hibernate.mapping.RootClass) Mappings(org.hibernate.cfg.Mappings) AbstractPropertyFacade(org.jboss.tools.hibernate.runtime.common.AbstractPropertyFacade) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass) Property(org.hibernate.mapping.Property) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 10 with Mappings

use of org.hibernate.cfg.Mappings in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateEntityMetamodel.

@Test
public void testCreateEntityMetamodel() {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(serviceRegistry);
    RootClass rc = new RootClass();
    Mappings m = configuration.createMappings();
    SimpleValue sv = new SimpleValue(m);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    rc.setIdentifier(sv);
    EntityMetamodel entityMetamodel = new EntityMetamodel(rc, sfi);
    IEntityMetamodel facade = facadeFactory.createEntityMetamodel(entityMetamodel);
    Assert.assertSame(entityMetamodel, ((IFacade) facade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) Configuration(org.hibernate.cfg.Configuration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) Mappings(org.hibernate.cfg.Mappings) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ServiceRegistry(org.hibernate.service.ServiceRegistry) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Aggregations

Mappings (org.hibernate.cfg.Mappings)17 RootClass (org.hibernate.mapping.RootClass)17 Test (org.junit.Test)14 SimpleValue (org.hibernate.mapping.SimpleValue)13 Configuration (org.hibernate.cfg.Configuration)11 Table (org.hibernate.mapping.Table)8 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)7 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)7 PersistentClass (org.hibernate.mapping.PersistentClass)6 Property (org.hibernate.mapping.Property)6 AbstractPropertyFacade (org.jboss.tools.hibernate.runtime.common.AbstractPropertyFacade)6 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)6 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)6 File (java.io.File)4 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 Column (org.hibernate.mapping.Column)4 PrimaryKey (org.hibernate.mapping.PrimaryKey)4