Search in sources :

Example 81 with RootClass

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

the class ValueFacadeTest method testGetAssociatedClass.

@Test
public void testGetAssociatedClass() {
    RootClass rootClass = new RootClass(null);
    OneToMany oneToManyTarget = new OneToMany(DummyMetadataBuildingContext.INSTANCE, null);
    valueFacade = FACADE_FACTORY.createValue(oneToManyTarget);
    assertNull(valueFacade.getAssociatedClass());
    oneToManyTarget.setAssociatedClass(rootClass);
    assertSame(rootClass, ((IFacade) valueFacade.getAssociatedClass()).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) OneToMany(org.hibernate.mapping.OneToMany) Test(org.junit.jupiter.api.Test)

Example 82 with RootClass

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

the class SpecialRootClassFacadeTest method testConstruction.

@Test
public void testConstruction() throws Exception {
    PersistentClass persistentClassTarget = new RootClass(DummyMetadataBuildingContext.INSTANCE);
    Property propertyTarget = new Property();
    Component componentTarget = new Component(DummyMetadataBuildingContext.INSTANCE, persistentClassTarget);
    componentTarget.setOwner(persistentClassTarget);
    componentTarget.setParentProperty("fooBar");
    propertyTarget.setValue(componentTarget);
    propertyTarget.setPersistentClass(persistentClassTarget);
    IProperty propertyFacade = FACADE_FACTORY.createProperty(propertyTarget);
    specialRootClassFacade = new SpecialRootClassFacadeImpl(FACADE_FACTORY, propertyFacade);
    Object specialRootClassTarget = ((IFacade) specialRootClassFacade).getTarget();
    assertNotSame(propertyFacade, specialRootClassTarget);
    assertTrue(specialRootClassTarget instanceof RootClass);
    assertNotSame(specialRootClassTarget, persistentClassTarget);
    Field propertyField = AbstractSpecialRootClassFacade.class.getDeclaredField("property");
    propertyField.setAccessible(true);
    assertSame(propertyField.get(specialRootClassFacade), propertyFacade);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Field(java.lang.reflect.Field) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) Component(org.hibernate.mapping.Component) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) Property(org.hibernate.mapping.Property) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.jupiter.api.Test)

Example 83 with RootClass

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

the class FacadeFactoryTest method testCreateHQLQueryPlan.

@Test
public void testCreateHQLQueryPlan() {
    Configuration configuration = new Configuration();
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    Mappings mappings = configuration.createMappings();
    Table t = new Table("FOO");
    Column c = new Column("foo");
    t.addColumn(c);
    PrimaryKey key = new PrimaryKey();
    key.addColumn(c);
    t.setPrimaryKey(key);
    Mappings m = configuration.createMappings();
    SimpleValue sv = new SimpleValue(m);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.setTable(t);
    sv.addColumn(c);
    RootClass rc = new RootClass();
    rc.setEntityName("foo");
    rc.setJpaEntityName("foo");
    rc.setIdentifier(sv);
    rc.setTable(t);
    mappings.addClass(rc);
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
    builder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = builder.build();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(serviceRegistry);
    Map<String, Filter> filters = Collections.emptyMap();
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) Configuration(org.hibernate.cfg.Configuration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) SimpleValue(org.hibernate.mapping.SimpleValue) HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Mappings(org.hibernate.cfg.Mappings) Column(org.hibernate.mapping.Column) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Filter(org.hibernate.Filter) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) Test(org.junit.jupiter.api.Test)

Example 84 with RootClass

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

the class FacadeFactoryTest method testCreatePersistentClass.

@Test
public void testCreatePersistentClass() {
    PersistentClass persistentClass = new RootClass();
    IPersistentClass facade = facadeFactory.createPersistentClass(persistentClass);
    assertTrue(facade instanceof PersistentClassFacadeImpl);
    assertSame(persistentClass, ((IFacade) facade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) 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 85 with RootClass

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

the class FacadeFactoryTest method testCreateEntityMetamodel.

@Test
public void testCreateEntityMetamodel() {
    Configuration configuration = new Configuration();
    final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
    standardServiceRegistryBuilder.applySetting(AvailableSettings.DIALECT, TestDialect.class.getName());
    final StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
    SessionFactoryImplementor sfi = (SessionFactoryImplementor) configuration.buildSessionFactory(serviceRegistry);
    RootClass rc = new RootClass();
    SimpleValue sv = new SimpleValue(configuration.createMappings());
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    rc.setIdentifier(sv);
    rc.setOptimisticLockStyle(OptimisticLockStyle.NONE);
    EntityMetamodel entityMetamodel = new EntityMetamodel(rc, null, sfi);
    IEntityMetamodel facade = facadeFactory.createEntityMetamodel(entityMetamodel);
    assertSame(entityMetamodel, ((IFacade) facade).getTarget());
}
Also used : RootClass(org.hibernate.mapping.RootClass) Configuration(org.hibernate.cfg.Configuration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) IEntityMetamodel(org.jboss.tools.hibernate.runtime.spi.IEntityMetamodel) EntityMetamodel(org.hibernate.tuple.entity.EntityMetamodel) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SimpleValue(org.hibernate.mapping.SimpleValue) 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