Search in sources :

Example 1 with Mappings

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

the class HibernateMappingExporterFacadeTest method testStart.

@Test
public void testStart() throws Exception {
    Configuration configuration = new Configuration();
    RootClass persistentClass = new RootClass();
    Table table = new Table("FOO");
    persistentClass.setClassName("Foo");
    persistentClass.setEntityName("Foo");
    persistentClass.setTable(table);
    Mappings mappings = configuration.createMappings();
    mappings.addClass(persistentClass);
    hibernateMappingExporter.setConfiguration(configuration);
    hibernateMappingExporter.setOutputDirectory(outputDir);
    final File fooHbmXml = new File(outputDir, "Foo.hbm.xml");
    // First without a 'delegate' exporter
    Assert.assertFalse(fooHbmXml.exists());
    hibernateMappingExporterFacade.start();
    Assert.assertTrue(fooHbmXml.exists());
    Assert.assertTrue(fooHbmXml.delete());
    // Now set a 'delegate' and invoke 'start' again
    final File dummyDir = new File(outputDir, "dummy");
    dummyDir.mkdir();
    Assert.assertTrue(dummyDir.exists());
    IExportPOJODelegate delegate = new IExportPOJODelegate() {

        @Override
        public void exportPOJO(Map<Object, Object> map, IPOJOClass pojoClass) {
            Assert.assertTrue(dummyDir.delete());
            hibernateMappingExporter.superExportPOJO(map, (POJOClass) ((IFacade) pojoClass).getTarget());
        }
    };
    Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
    delegateField.setAccessible(true);
    delegateField.set(hibernateMappingExporter, delegate);
    hibernateMappingExporterFacade.start();
    Assert.assertFalse(dummyDir.exists());
    Assert.assertTrue(fooHbmXml.exists());
    Assert.assertTrue(fooHbmXml.delete());
    Assert.assertTrue(outputDir.exists());
}
Also used : RootClass(org.hibernate.mapping.RootClass) Field(java.lang.reflect.Field) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) Mappings(org.hibernate.cfg.Mappings) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) IExportPOJODelegate(org.jboss.tools.hibernate.runtime.spi.IExportPOJODelegate) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 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.setIdentifier(sv);
    rc.setTable(t);
    mappings.addClass(rc);
    SessionFactoryImplementor sfi = new SessionFactoryImpl(configuration, null, configuration.buildSettings(), null, null);
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, Collections.emptyMap(), sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    Assert.assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) HQLQueryPlan(org.hibernate.engine.query.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) 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) Mappings(org.hibernate.cfg.Mappings) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) SessionFactoryImplementor(org.hibernate.engine.SessionFactoryImplementor) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 3 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.setIdentifier(sv);
    rc.setTable(t);
    mappings.addClass(rc);
    ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(serviceRegistry);
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, Collections.emptyMap(), 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) 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) ServiceRegistryBuilder(org.hibernate.service.ServiceRegistryBuilder) 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) ServiceRegistry(org.hibernate.service.ServiceRegistry) Test(org.junit.Test)

Example 4 with Mappings

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

the class HibernateMappingExporterFacadeTest method testStart.

@Test
public void testStart() throws Exception {
    Configuration configuration = new Configuration();
    RootClass persistentClass = new RootClass();
    Table table = new Table("FOO");
    persistentClass.setClassName("Foo");
    persistentClass.setEntityName("Foo");
    persistentClass.setTable(table);
    Mappings mappings = configuration.createMappings();
    mappings.addClass(persistentClass);
    hibernateMappingExporter.setConfiguration(configuration);
    hibernateMappingExporter.setOutputDirectory(outputDir);
    final File fooHbmXml = new File(outputDir, "Foo.hbm.xml");
    // First without a 'delegate' exporter
    Assert.assertFalse(fooHbmXml.exists());
    hibernateMappingExporterFacade.start();
    Assert.assertTrue(fooHbmXml.exists());
    Assert.assertTrue(fooHbmXml.delete());
    // Now set a 'delegate' and invoke 'start' again
    final File dummyDir = new File(outputDir, "dummy");
    dummyDir.mkdir();
    Assert.assertTrue(dummyDir.exists());
    IExportPOJODelegate delegate = new IExportPOJODelegate() {

        @Override
        public void exportPOJO(Map<Object, Object> map, IPOJOClass pojoClass) {
            Assert.assertTrue(dummyDir.delete());
            hibernateMappingExporter.superExportPOJO(map, (POJOClass) ((IFacade) pojoClass).getTarget());
        }
    };
    Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
    delegateField.setAccessible(true);
    delegateField.set(hibernateMappingExporter, delegate);
    hibernateMappingExporterFacade.start();
    Assert.assertFalse(dummyDir.exists());
    Assert.assertTrue(fooHbmXml.exists());
    Assert.assertTrue(fooHbmXml.delete());
    Assert.assertTrue(outputDir.exists());
}
Also used : RootClass(org.hibernate.mapping.RootClass) Field(java.lang.reflect.Field) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) Mappings(org.hibernate.cfg.Mappings) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) IExportPOJODelegate(org.jboss.tools.hibernate.runtime.spi.IExportPOJODelegate) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with Mappings

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

the class FacadeFactoryTest method testCreateSpecialRootClass.

@Test
public void testCreateSpecialRootClass() {
    Property property = new Property();
    Mappings m = (Mappings) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { Mappings.class }, new TestInvocationHandler());
    property.setValue(new SimpleValue(m));
    IProperty propertyFacade = new AbstractPropertyFacade(facadeFactory, property) {
    };
    IPersistentClass specialRootClass = facadeFactory.createSpecialRootClass(propertyFacade);
    Assert.assertSame(property, ((IFacade) specialRootClass.getProperty()).getTarget());
}
Also used : Mappings(org.hibernate.cfg.Mappings) AbstractPropertyFacade(org.jboss.tools.hibernate.runtime.common.AbstractPropertyFacade) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) Property(org.hibernate.mapping.Property) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) 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