Search in sources :

Example 1 with EntityPOJOClass

use of org.hibernate.tool.internal.export.java.EntityPOJOClass in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterFacadeTest method testExportPOJO.

@Test
public void testExportPOJO() throws Exception {
    RootClass persistentClass = new RootClass(DummyMetadataBuildingContext.INSTANCE);
    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.CURRENT_VERSION);
    additionalContext.put("c2h", c2h);
    hibernateMappingExporter.getProperties().put(ExporterConstants.DESTINATION_FOLDER, 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.internal.export.common.TemplateHelper) Method(java.lang.reflect.Method) Date(java.util.Date) EntityPOJOClass(org.hibernate.tool.internal.export.java.EntityPOJOClass) Cfg2HbmTool(org.hibernate.tool.internal.export.hbm.Cfg2HbmTool) Cfg2JavaTool(org.hibernate.tool.internal.export.java.Cfg2JavaTool) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 2 with EntityPOJOClass

use of org.hibernate.tool.internal.export.java.EntityPOJOClass in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterExtensionTest method createPojoClass.

private POJOClass createPojoClass() {
    RootClass persistentClass = new RootClass(DummyMetadataBuildingContext.INSTANCE);
    Table rootTable = new Table();
    rootTable.setName("table");
    persistentClass.setTable(rootTable);
    persistentClass.setEntityName("Bar");
    persistentClass.setClassName("foo.Bar");
    return new EntityPOJOClass(persistentClass, new Cfg2JavaTool());
}
Also used : RootClass(org.hibernate.mapping.RootClass) EntityPOJOClass(org.hibernate.tool.internal.export.java.EntityPOJOClass) Table(org.hibernate.mapping.Table) Cfg2JavaTool(org.hibernate.tool.internal.export.java.Cfg2JavaTool)

Aggregations

RootClass (org.hibernate.mapping.RootClass)2 Table (org.hibernate.mapping.Table)2 Cfg2JavaTool (org.hibernate.tool.internal.export.java.Cfg2JavaTool)2 EntityPOJOClass (org.hibernate.tool.internal.export.java.EntityPOJOClass)2 File (java.io.File)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 TemplateHelper (org.hibernate.tool.internal.export.common.TemplateHelper)1 Cfg2HbmTool (org.hibernate.tool.internal.export.hbm.Cfg2HbmTool)1 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)1 Test (org.junit.jupiter.api.Test)1