Search in sources :

Example 86 with RootClass

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

the class FacadeFactoryTest method testCreateSpecialRootClass.

@Test
public void testCreateSpecialRootClass() {
    Property target = new Property();
    PersistentClass pc = new RootClass();
    target.setPersistentClass(pc);
    IProperty property = facadeFactory.createProperty(target);
    IPersistentClass specialRootClass = facadeFactory.createSpecialRootClass(property);
    assertNotNull(specialRootClass);
    Object object = ((IFacade) specialRootClass).getTarget();
    assertTrue(specialRootClass instanceof SpecialRootClassFacadeImpl);
    assertTrue(object instanceof RootClass);
    assertSame(property, specialRootClass.getProperty());
}
Also used : RootClass(org.hibernate.mapping.RootClass) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Property(org.hibernate.mapping.Property) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.jupiter.api.Test)

Example 87 with RootClass

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

the class HibernateMappingExporterFacadeTest method testExportPOJO.

@Test
public void testExportPOJO() throws Exception {
    RootClass persistentClass = new RootClass();
    Table rootTable = new Table();
    rootTable.setName("FOO");
    persistentClass.setTable(rootTable);
    persistentClass.setEntityName("Foo");
    persistentClass.setClassName("Foo");
    IPOJOClass pojoClass = FACADE_FACTORY.createPOJOClass(new EntityPOJOClass(persistentClass, new Cfg2JavaTool()));
    Map<Object, Object> additionalContext = new HashMap<Object, Object>();
    Cfg2HbmTool c2h = new Cfg2HbmTool();
    additionalContext.put("date", new Date().toString());
    additionalContext.put("version", Version.getDefault().toString());
    additionalContext.put("c2h", c2h);
    hibernateMappingExporter.setOutputDirectory(outputDir);
    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(hibernateMappingExporter, new Object[] { templateHelper });
    final File fooHbmXml = new File(outputDir, "Foo.hbm.xml");
    assertFalse(fooHbmXml.exists());
    hibernateMappingExporterFacade.exportPOJO(additionalContext, pojoClass);
    assertTrue(fooHbmXml.exists());
    fooHbmXml.delete();
    outputDir.delete();
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) HashMap(java.util.HashMap) TemplateHelper(org.hibernate.tool.hbm2x.TemplateHelper) Method(java.lang.reflect.Method) Date(java.util.Date) EntityPOJOClass(org.hibernate.tool.hbm2x.pojo.EntityPOJOClass) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) Cfg2JavaTool(org.hibernate.tool.hbm2x.Cfg2JavaTool) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 88 with RootClass

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

the class HibernateMappingExporterFacadeTest method testStart.

@Test
public void testStart() throws Exception {
    RootClass persistentClass = new RootClass();
    Table table = new Table("FOO");
    Column keyColumn = new Column("BAR");
    SimpleValue key = new SimpleValue(configurationTarget.createMappings());
    key.setTypeName("String");
    key.addColumn(keyColumn);
    key.setTable(table);
    persistentClass.setClassName("Foo");
    persistentClass.setEntityName("Foo");
    persistentClass.setJpaEntityName("Foo");
    persistentClass.setTable(table);
    persistentClass.setIdentifier(key);
    configurationFacade.addClass(FACADE_FACTORY.createPersistentClass(persistentClass));
    hibernateMappingExporter.setOutputDirectory(outputDir);
    final File fooHbmXml = new File(outputDir, "Foo.hbm.xml");
    // First without a 'delegate' exporter
    assertFalse(fooHbmXml.exists());
    hibernateMappingExporterFacade.start();
    assertTrue(fooHbmXml.exists());
    assertTrue(fooHbmXml.delete());
    // Now set a 'delegate' and invoke 'start' again
    final File dummyDir = new File(outputDir, "dummy");
    dummyDir.mkdir();
    assertTrue(dummyDir.exists());
    IExportPOJODelegate delegate = new IExportPOJODelegate() {

        @Override
        public void exportPOJO(Map<Object, Object> map, IPOJOClass pojoClass) {
            assertTrue(dummyDir.delete());
            Map<Object, 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();
    assertFalse(dummyDir.exists());
    assertTrue(fooHbmXml.exists());
    assertTrue(fooHbmXml.delete());
    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) 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.jupiter.api.Test)

Example 89 with RootClass

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

the class PersistentClassFacadeTest method testGetIdentifierProperty.

@Test
public void testGetIdentifierProperty() throws Exception {
    Field field = AbstractPersistentClassFacade.class.getDeclaredField("identifierProperty");
    field.setAccessible(true);
    assertNull(field.get(persistentClassFacade));
    Property propertyTarget = new Property();
    assertNull(persistentClassFacade.getIdentifierProperty());
    ((RootClass) persistentClassTarget).setIdentifierProperty(propertyTarget);
    IProperty propertyFacade = persistentClassFacade.getIdentifierProperty();
    assertNotNull(propertyFacade);
    assertSame(propertyTarget, ((IFacade) propertyFacade).getTarget());
    assertSame(propertyFacade, field.get(persistentClassFacade));
}
Also used : RootClass(org.hibernate.mapping.RootClass) Field(java.lang.reflect.Field) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) Property(org.hibernate.mapping.Property) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) Test(org.junit.jupiter.api.Test)

Example 90 with RootClass

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

the class PersistentClassFacadeTest method testGetVersion.

@Test
public void testGetVersion() throws Exception {
    assertNull(persistentClassFacade.getVersion());
    Property versionTarget = new Property();
    Field field = AbstractPersistentClassFacade.class.getDeclaredField("version");
    field.setAccessible(true);
    assertNull(field.get(persistentClassFacade));
    ((RootClass) persistentClassTarget).setVersion(versionTarget);
    IProperty versionFacade = persistentClassFacade.getVersion();
    assertNotNull(versionFacade);
    assertSame(versionFacade, field.get(persistentClassFacade));
    assertSame(versionTarget, ((IFacade) versionFacade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) Field(java.lang.reflect.Field) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) Property(org.hibernate.mapping.Property) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) Test(org.junit.jupiter.api.Test)

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