Search in sources :

Example 16 with IFacade

use of org.jboss.tools.hibernate.runtime.common.IFacade in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method newSingleTableSubclass.

@Override
public IPersistentClass newSingleTableSubclass(IPersistentClass persistentClass) {
    assert persistentClass instanceof IFacade;
    IPersistentClass result = facadeFactory.createPersistentClass(new SingleTableSubclass((PersistentClass) ((IFacade) persistentClass).getTarget(), null));
    ((AbstractPersistentClassFacade) result).setSuperClass(persistentClass);
    return result;
}
Also used : AbstractPersistentClassFacade(org.jboss.tools.hibernate.runtime.common.AbstractPersistentClassFacade) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) SingleTableSubclass(org.hibernate.mapping.SingleTableSubclass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 17 with IFacade

use of org.jboss.tools.hibernate.runtime.common.IFacade 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 18 with IFacade

use of org.jboss.tools.hibernate.runtime.common.IFacade in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewAnnotationConfiguration.

@Test
public void testNewAnnotationConfiguration() {
    IConfiguration configuration = service.newAnnotationConfiguration();
    Assert.assertNotNull(configuration);
    Object target = ((IFacade) configuration).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof AnnotationConfiguration);
}
Also used : AnnotationConfiguration(org.hibernate.cfg.AnnotationConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Test(org.junit.Test)

Example 19 with IFacade

use of org.jboss.tools.hibernate.runtime.common.IFacade in project jbosstools-hibernate by jbosstools.

the class ConfigurationFacadeTest method testBuildSessionFactory.

@Test
public void testBuildSessionFactory() throws Throwable {
    ISessionFactory sessionFactoryFacade = configurationFacade.buildSessionFactory();
    Assert.assertNotNull(sessionFactoryFacade);
    Object sessionFactory = ((IFacade) sessionFactoryFacade).getTarget();
    Assert.assertNotNull(sessionFactory);
    Assert.assertTrue(sessionFactory instanceof SessionFactory);
}
Also used : ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) SessionFactory(org.hibernate.SessionFactory) ISessionFactory(org.jboss.tools.hibernate.runtime.spi.ISessionFactory) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Test(org.junit.Test)

Example 20 with IFacade

use of org.jboss.tools.hibernate.runtime.common.IFacade in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterFacadeTest method testStart.

@Test
public void testStart() throws Exception {
    PojoMetaDataConfiguration configuration = new PojoMetaDataConfiguration();
    RootClass persistentClass = new RootClass(null);
    Table table = new Table("FOO");
    Column keyColumn = new Column("BAR");
    SimpleValue key = new SimpleValue(configuration.getMetadataImplementor());
    key.setTypeName("String");
    key.addColumn(keyColumn);
    key.setTable(table);
    persistentClass.setClassName("Foo");
    persistentClass.setEntityName("Foo");
    persistentClass.setJpaEntityName("Foo");
    persistentClass.setTable(table);
    persistentClass.setIdentifier(key);
    configuration.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());
            Map<String, Object> m = new HashMap<>();
            for (Object key : map.keySet()) {
                m.put((String) key, map.get(key));
            }
            hibernateMappingExporter.superExportPOJO(m, (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) Table(org.hibernate.mapping.Table) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) HashMap(java.util.HashMap) PojoMetaDataConfiguration(org.hibernate.cfg.PojoMetaDataConfiguration) SimpleValue(org.hibernate.mapping.SimpleValue) Field(java.lang.reflect.Field) Column(org.hibernate.mapping.Column) 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)

Aggregations

IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)188 Test (org.junit.Test)156 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)60 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)40 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)29 Configuration (org.hibernate.cfg.Configuration)20 IReverseEngineeringStrategy (org.jboss.tools.hibernate.runtime.spi.IReverseEngineeringStrategy)20 RootClass (org.hibernate.mapping.RootClass)19 Table (org.hibernate.mapping.Table)15 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)13 File (java.io.File)12 PersistentClass (org.hibernate.mapping.PersistentClass)12 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 ISessionFactory (org.jboss.tools.hibernate.runtime.spi.ISessionFactory)12 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)11 Field (java.lang.reflect.Field)9 JDBCReader (org.hibernate.cfg.reveng.JDBCReader)9 IJDBCReader (org.jboss.tools.hibernate.runtime.spi.IJDBCReader)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8