use of org.hibernate.mapping.RootClass in project hibernate-orm by hibernate.
the class DiscriminatorOptionsTest method testPropertyBasedDiscriminatorForcing.
@Test
public void testPropertyBasedDiscriminatorForcing() throws Exception {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(BaseClass2.class).addAnnotatedClass(SubClass2.class).getMetadataBuilder().enableImplicitForcingOfDiscriminatorsInSelect(true).build();
PersistentClass persistentClass = metadata.getEntityBinding(BaseClass2.class.getName());
assertNotNull(persistentClass);
assertTrue(persistentClass instanceof RootClass);
RootClass root = (RootClass) persistentClass;
assertTrue("Discriminator should be forced by property", root.isForceDiscriminator());
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.mapping.RootClass in project hibernate-orm by hibernate.
the class SchemaBasedMultiTenancyTest method setUp.
@Before
public void setUp() {
AbstractMultiTenantConnectionProvider multiTenantConnectionProvider = buildMultiTenantConnectionProvider();
Map settings = new HashMap();
settings.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(Environment.GENERATE_STATISTICS, "true");
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).addService(MultiTenantConnectionProvider.class, multiTenantConnectionProvider).build();
MetadataSources ms = new MetadataSources(serviceRegistry);
ms.addAnnotatedClass(Customer.class);
ms.addAnnotatedClass(Invoice.class);
Metadata metadata = ms.buildMetadata();
((RootClass) metadata.getEntityBinding(Customer.class.getName())).setCacheConcurrencyStrategy("read-write");
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
tool.injectServices(serviceRegistry);
final GenerationTargetToDatabase acmeTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, acmeProvider));
final GenerationTargetToDatabase jbossTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, jbossProvider));
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
configure(sfb);
sessionFactory = (SessionFactoryImplementor) sfb.build();
}
use of org.hibernate.mapping.RootClass in project hibernate-orm by hibernate.
the class PersistentClassTest method testGetProxyInterface.
@Test
public void testGetProxyInterface() {
RootClass pc = new RootClass(metadataBuildingContext);
pc.setProxyInterfaceName(String.class.getName());
Assert.assertEquals(String.class.getName(), pc.getProxyInterfaceName());
Assert.assertEquals(String.class, pc.getProxyInterface());
pc.setProxyInterfaceName(Integer.class.getName());
Assert.assertEquals(Integer.class, pc.getProxyInterface());
}
use of org.hibernate.mapping.RootClass in project hibernate-orm by hibernate.
the class PersistentClassTest method testGetProperty.
@Test
public void testGetProperty() {
RootClass pc = new RootClass(metadataBuildingContext);
Property p = new Property();
p.setName("name");
pc.addProperty(p);
Assert.assertEquals(p, pc.getProperty("name"));
Assert.assertEquals(p, pc.getProperty("name.test"));
try {
Assert.assertNull(pc.getProperty("test"));
Assert.fail("MappingException expected");
} catch (MappingException e) {
// expected
}
}
use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.
the class HibernateMappingExporterExtensionTest method setUp.
@Before
public void setUp() throws Exception {
hibernateMappingExporterExtension = new HibernateMappingExporterExtension(FACADE_FACTORY, null, null);
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(hibernateMappingExporterExtension, new Object[] { templateHelper });
RootClass persistentClass = new RootClass();
Table rootTable = new Table();
rootTable.setName("table");
persistentClass.setTable(rootTable);
persistentClass.setEntityName("Bar");
persistentClass.setClassName("foo.Bar");
pojoClass = new EntityPOJOClass(persistentClass, new Cfg2JavaTool());
exportPojoDelegate = (IExportPOJODelegate) Proxy.newProxyInstance(HibernateMappingExporterExtension.class.getClassLoader(), new Class[] { IExportPOJODelegate.class }, new TestInvocationHandler());
}
Aggregations