Search in sources :

Example 6 with AbstractEntityMetamodelFacade

use of org.jboss.tools.hibernate.runtime.common.AbstractEntityMetamodelFacade 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");
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.build();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(serviceRegistry);
    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);
    MetadataImplementor m = (MetadataImplementor) MetadataHelper.getMetadata(configuration);
    SimpleValue sv = new SimpleValue(m);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.addColumn(c);
    rc.setEntityName("foobar");
    rc.setIdentifier(sv);
    entityMetamodel = new EntityMetamodel(rc, null, sfi) {

        @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;
        }
    };
    entityMetamodelFacade = new AbstractEntityMetamodelFacade(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) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) AbstractEntityMetamodelFacade(org.jboss.tools.hibernate.runtime.common.AbstractEntityMetamodelFacade) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) 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) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)6 Configuration (org.hibernate.cfg.Configuration)6 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)6 Column (org.hibernate.mapping.Column)6 RootClass (org.hibernate.mapping.RootClass)6 SimpleValue (org.hibernate.mapping.SimpleValue)6 Table (org.hibernate.mapping.Table)6 ServiceRegistry (org.hibernate.service.ServiceRegistry)6 EntityMetamodel (org.hibernate.tuple.entity.EntityMetamodel)6 EntityTuplizer (org.hibernate.tuple.entity.EntityTuplizer)6 AbstractEntityMetamodelFacade (org.jboss.tools.hibernate.runtime.common.AbstractEntityMetamodelFacade)6 IEntityMetamodel (org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel)6 Before (org.junit.Before)6 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)4 ServiceRegistryBuilder (org.hibernate.service.ServiceRegistryBuilder)1