Search in sources :

Example 16 with RootClass

use of org.hibernate.mapping.RootClass 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 17 with RootClass

use of org.hibernate.mapping.RootClass 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)

Example 18 with RootClass

use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterExtensionTest method setUp.

@Before
public void setUp() throws Exception {
    hibernateMappingExporterExtension = new HibernateMappingExporterExtension(FACADE_FACTORY, null, null);
    Method setTemplateHelperMethod = AbstractExporter.class.getDeclaredMethod("setTemplateHelper", new Class[] { TemplateHelper.class });
    setTemplateHelperMethod.setAccessible(true);
    TemplateHelper templateHelper = new TemplateHelper();
    templateHelper.init(null, new String[0]);
    setTemplateHelperMethod.invoke(hibernateMappingExporterExtension, new Object[] { templateHelper });
    RootClass persistentClass = new RootClass();
    Table rootTable = new Table();
    rootTable.setName("table");
    persistentClass.setTable(rootTable);
    persistentClass.setEntityName("Bar");
    persistentClass.setClassName("foo.Bar");
    pojoClass = new EntityPOJOClass(persistentClass, new Cfg2JavaTool());
    exportPojoDelegate = (IExportPOJODelegate) Proxy.newProxyInstance(HibernateMappingExporterExtension.class.getClassLoader(), new Class[] { IExportPOJODelegate.class }, new TestInvocationHandler());
}
Also used : RootClass(org.hibernate.mapping.RootClass) EntityPOJOClass(org.hibernate.tool.hbm2x.pojo.EntityPOJOClass) Table(org.hibernate.mapping.Table) TemplateHelper(org.hibernate.tool.hbm2x.TemplateHelper) Method(java.lang.reflect.Method) Cfg2JavaTool(org.hibernate.tool.hbm2x.Cfg2JavaTool) Before(org.junit.Before)

Example 19 with RootClass

use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.

the class ClassMetadataFacadeTest method createSampleEntityPersister.

private TestEntityPersister createSampleEntityPersister() {
    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();
    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);
    return new TestEntityPersister(rc, sfi);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Column(org.hibernate.mapping.Column) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ArrayList(java.util.ArrayList) ServiceRegistry(org.hibernate.service.ServiceRegistry) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 20 with RootClass

use of org.hibernate.mapping.RootClass 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

RootClass (org.hibernate.mapping.RootClass)609 Test (org.junit.jupiter.api.Test)471 PersistentClass (org.hibernate.mapping.PersistentClass)166 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)162 Field (java.lang.reflect.Field)149 SimpleValue (org.hibernate.mapping.SimpleValue)142 Table (org.hibernate.mapping.Table)136 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)130 Property (org.hibernate.mapping.Property)124 Component (org.hibernate.mapping.Component)109 Column (org.hibernate.mapping.Column)53 ArrayList (java.util.ArrayList)51 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)51 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)44 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)43 Configuration (org.hibernate.cfg.Configuration)37 OneToOne (org.hibernate.mapping.OneToOne)37 MetadataSources (org.hibernate.boot.MetadataSources)35 Test (org.junit.Test)35 SingleTableSubclass (org.hibernate.mapping.SingleTableSubclass)34