Search in sources :

Example 56 with RootClass

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

the class ConfigurationFacadeTest method testAddClass.

@Test
public void testAddClass() throws Exception {
    PersistentClass persistentClass = new RootClass(null);
    persistentClass.setEntityName("Foo");
    IPersistentClass persistentClassFacade = FACADE_FACTORY.createPersistentClass(persistentClass);
    Field addedClassesField = ConfigurationFacadeImpl.class.getDeclaredField("addedClasses");
    addedClassesField.setAccessible(true);
    Collection<?> addedClasses = (Collection<?>) addedClassesField.get(configurationFacade);
    assertFalse(addedClasses.contains(persistentClassFacade));
    configurationFacade.addClass(persistentClassFacade);
    assertTrue(addedClasses.contains(persistentClassFacade));
}
Also used : RootClass(org.hibernate.mapping.RootClass) Field(java.lang.reflect.Field) Collection(java.util.Collection) 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 57 with RootClass

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

the class ConfigurationFacadeTest method testGetClassMapping.

@Test
public void testGetClassMapping() throws Exception {
    PersistentClass persistentClass = new RootClass(null);
    persistentClass.setEntityName("Foo");
    IPersistentClass persistentClassFacade = FACADE_FACTORY.createPersistentClass(persistentClass);
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    assertNull(configurationFacade.getClassMapping("Foo"));
    configurationFacade = new ConfigurationFacadeImpl(FACADE_FACTORY, configuration);
    Field addedClassesField = ConfigurationFacadeImpl.class.getDeclaredField("addedClasses");
    addedClassesField.setAccessible(true);
    @SuppressWarnings("unchecked") List<IPersistentClass> addedClasses = (List<IPersistentClass>) addedClassesField.get(configurationFacade);
    addedClasses.add(persistentClassFacade);
    assertSame(configurationFacade.getClassMapping("Foo"), persistentClassFacade);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Field(java.lang.reflect.Field) List(java.util.List) ArrayList(java.util.ArrayList) 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 58 with RootClass

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

the class EntityMetamodelFacadeTest method createPersistentClass.

private PersistentClass createPersistentClass(MetadataBuildingContext metadataBuildingContext) {
    RootClass rc = new RootClass(metadataBuildingContext);
    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(metadataBuildingContext, t);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.addColumn(c);
    rc.setEntityName("foobar");
    rc.setIdentifier(sv);
    rc.setClassName(FooBar.class.getName());
    rc.setOptimisticLockStyle(OptimisticLockStyle.NONE);
    return rc;
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) Column(org.hibernate.mapping.Column) ArrayList(java.util.ArrayList) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 59 with RootClass

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

the class TypeFacadeTest method testIsComponentType.

@Test
public void testIsComponentType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    assertFalse(typeFacade.isComponentType());
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
    ssrb.applySetting(AvailableSettings.DIALECT, TestDialect.class.getName());
    StandardServiceRegistry ssr = ssrb.build();
    MetadataBuildingOptions mdbo = new MetadataBuilderImpl.MetadataBuildingOptionsImpl(ssr);
    MetadataImplementor mdi = (MetadataImplementor) new MetadataBuilderImpl(new MetadataSources(ssr)).build();
    ComponentType componentType = new ComponentType(null, new ComponentMetamodel(new Component(mdi, new RootClass(null)), mdbo));
    typeFacade = FACADE_FACTORY.createType(componentType);
    assertTrue(typeFacade.isComponentType());
}
Also used : RootClass(org.hibernate.mapping.RootClass) ComponentType(org.hibernate.type.ComponentType) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ComponentMetamodel(org.hibernate.tuple.component.ComponentMetamodel) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) ClassType(org.hibernate.type.ClassType) MetadataBuilderImpl(org.hibernate.boot.internal.MetadataBuilderImpl) IType(org.jboss.tools.hibernate.runtime.spi.IType) MetadataBuildingOptions(org.hibernate.boot.spi.MetadataBuildingOptions) Component(org.hibernate.mapping.Component) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.jupiter.api.Test)

Example 60 with RootClass

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

the class PersistentClassFacadeTest method testIsJoinedSubclass.

@Test
public void testIsJoinedSubclass() {
    persistentClassFacade = new PersistentClassFacadeImpl(FACADE_FACTORY, new RootClass(null));
    assertFalse(persistentClassFacade.isJoinedSubclass());
    Table rootTable = new Table();
    Table subTable = new Table();
    RootClass rootClass = new RootClass(null);
    rootClass.setTable(rootTable);
    JoinedSubclass subclass = new JoinedSubclass(rootClass, null);
    subclass.setTable(subTable);
    persistentClassFacade = new PersistentClassFacadeImpl(FACADE_FACTORY, subclass) {
    };
    assertTrue(persistentClassFacade.isJoinedSubclass());
    subclass.setTable(rootTable);
    assertFalse(persistentClassFacade.isJoinedSubclass());
}
Also used : RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) JoinedSubclass(org.hibernate.mapping.JoinedSubclass) 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