Search in sources :

Example 11 with SessionFactoryImpl

use of org.hibernate.impl.SessionFactoryImpl 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");
    SessionFactoryImplementor sfi = new SessionFactoryImpl(configuration, null, configuration.buildSettings(), null, null);
    RootClass rc = new RootClass();
    SimpleValue sv = new SimpleValue();
    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) SessionFactoryImplementor(org.hibernate.engine.SessionFactoryImplementor) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) 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 12 with SessionFactoryImpl

use of org.hibernate.impl.SessionFactoryImpl in project jbosstools-hibernate by jbosstools.

the class EntityMetamodelFacadeTest method setUp.

@SuppressWarnings("serial")
@Before
public void setUp() throws Exception {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    SessionFactoryImplementor sfi = new SessionFactoryImpl(configuration, null, configuration.buildSettings(), null, null);
    RootClass rc = new RootClass();
    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(configuration.createMappings());
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.addColumn(c);
    rc.setEntityName("foobar");
    rc.setIdentifier(sv);
    entityMetamodel = new EntityMetamodel(rc, sfi) {

        @Override
        public EntityTuplizer getTuplizer(EntityMode entityMode) {
            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;
        }
    };
    entityMetamodelFacade = new EntityMetamodelFacadeImpl(FACADE_FACTORY, entityMetamodel);
}
Also used : RootClass(org.hibernate.mapping.RootClass) EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.SessionFactoryImplementor) ArrayList(java.util.ArrayList) SimpleValue(org.hibernate.mapping.SimpleValue) EntityMode(org.hibernate.EntityMode) Column(org.hibernate.mapping.Column) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) Before(org.junit.Before)

Example 13 with SessionFactoryImpl

use of org.hibernate.impl.SessionFactoryImpl 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");
    SessionFactoryImplementor sfi = new SessionFactoryImpl(configuration, null, configuration.buildSettings(), null, null);
    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.SessionFactoryImplementor) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) 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)

Aggregations

SessionFactoryImpl (org.hibernate.impl.SessionFactoryImpl)13 Configuration (org.hibernate.cfg.Configuration)9 SessionFactoryImplementor (org.hibernate.engine.SessionFactoryImplementor)8 RootClass (org.hibernate.mapping.RootClass)8 SimpleValue (org.hibernate.mapping.SimpleValue)8 Column (org.hibernate.mapping.Column)6 Table (org.hibernate.mapping.Table)6 ArrayList (java.util.ArrayList)4 HQLQueryPlan (org.hibernate.engine.query.HQLQueryPlan)4 EntityMetamodel (org.hibernate.tuple.entity.EntityMetamodel)4 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)4 IEntityMetamodel (org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel)4 IHQLQueryPlan (org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan)4 Test (org.junit.Test)4 Mappings (org.hibernate.cfg.Mappings)3 XWikiException (com.xpn.xwiki.XWikiException)2 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)2 Field (java.lang.reflect.Field)2 SQLException (java.sql.SQLException)2 EntityMode (org.hibernate.EntityMode)2