use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.
the class Cfg2HbmToolFacadeTest method testGetPersistentClassTag.
@Test
public void testGetPersistentClassTag() {
PersistentClass target = new RootClass();
IPersistentClass persistentClass = new AbstractPersistentClassFacade(FACADE_FACTORY, target) {
};
Assert.assertEquals("class", cfg2HbmToolFacade.getTag(persistentClass));
}
use of org.hibernate.mapping.RootClass 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());
}
use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.
the class HibernateMappingExporterExtensionTest method createPojoClass.
private POJOClass createPojoClass() {
RootClass persistentClass = new RootClass();
Table rootTable = new Table();
rootTable.setName("table");
persistentClass.setTable(rootTable);
persistentClass.setEntityName("Bar");
persistentClass.setClassName("foo.Bar");
return new EntityPOJOClass(persistentClass, new Cfg2JavaTool());
}
use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testGetClassMappings.
@Test
public void testGetClassMappings() {
configurationFacade = FACADE_FACTORY.createConfiguration(configuration);
Iterator<IPersistentClass> iterator = configurationFacade.getClassMappings();
assertFalse(iterator.hasNext());
PersistentClass persistentClass = new RootClass();
persistentClass.setEntityName("Foo");
Mappings mappings = configuration.createMappings();
mappings.addClass(persistentClass);
configurationFacade = FACADE_FACTORY.createConfiguration(configuration);
iterator = configurationFacade.getClassMappings();
IPersistentClass persistentClassFacade = iterator.next();
assertSame(persistentClass, ((IFacade) persistentClassFacade).getTarget());
}
use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.
the class EntityMetamodelFacadeTest method createFoobarModel.
@SuppressWarnings("serial")
private EntityMetamodel createFoobarModel() {
Configuration configuration = new Configuration();
configuration.setProperty(AvailableSettings.DIALECT, TestDialect.class.getName());
ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
builder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = builder.buildServiceRegistry();
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 entityMetamodel = new EntityMetamodel(rc, 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;
}
};
}
Aggregations