Search in sources :

Example 6 with RootClass

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);
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 7 with RootClass

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();
}
Also used : RootClass(org.hibernate.mapping.RootClass) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) HashMap(java.util.HashMap) CachingRegionFactory(org.hibernate.testing.cache.CachingRegionFactory) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) HibernateSchemaManagementTool(org.hibernate.tool.schema.internal.HibernateSchemaManagementTool) DdlTransactionIsolatorTestingImpl(org.hibernate.test.util.DdlTransactionIsolatorTestingImpl) SchemaDropperImpl(org.hibernate.tool.schema.internal.SchemaDropperImpl) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) AbstractMultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider) MultiTenantConnectionProvider(org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider) GenerationTargetToDatabase(org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 8 with RootClass

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());
}
Also used : RootClass(org.hibernate.mapping.RootClass) Test(org.junit.Test)

Example 9 with RootClass

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
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) Property(org.hibernate.mapping.Property) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

Example 10 with RootClass

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());
}
Also used : RootClass(org.hibernate.mapping.RootClass) EntityPOJOClass(org.hibernate.tool.hbm2x.pojo.EntityPOJOClass) Table(org.hibernate.mapping.Table) TemplateHelper(org.hibernate.tool.hbm2x.TemplateHelper) Method(java.lang.reflect.Method) Cfg2JavaTool(org.hibernate.tool.hbm2x.Cfg2JavaTool) Before(org.junit.Before)

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