Search in sources :

Example 61 with IValue

use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewManyToOne.

@Test
public void testNewManyToOne() {
    ITable table = service.newTable("foo");
    IValue manyToOne = service.newManyToOne(table);
    Assert.assertNotNull(manyToOne);
    Object target = ((IFacade) manyToOne).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof ManyToOne);
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) ManyToOne(org.hibernate.mapping.ManyToOne) Test(org.junit.Test)

Example 62 with IValue

use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewArray.

@Test
public void testNewArray() {
    IPersistentClass persistentClass = service.newRootClass();
    IValue array = service.newArray(persistentClass);
    Assert.assertNotNull(array);
    Object target = ((IFacade) array).getTarget();
    Assert.assertNotNull(target);
    Assert.assertTrue(target instanceof Array);
}
Also used : Array(org.hibernate.mapping.Array) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) Test(org.junit.Test)

Example 63 with IValue

use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.

the class TableFacadeTest method testGetIdentifierValue.

@Test
public void testGetIdentifierValue() {
    Table table = new Table();
    ITable tableFacade = FACADE_FACTORY.createTable(table);
    IValue valueFacade = tableFacade.getIdentifierValue();
    Assert.assertNull(valueFacade);
    KeyValue value = new SimpleValue(null);
    table.setIdentifierValue(value);
    valueFacade = tableFacade.getIdentifierValue();
    Assert.assertSame(value, ((IFacade) valueFacade).getTarget());
}
Also used : Table(org.hibernate.mapping.Table) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) IValue(org.jboss.tools.hibernate.runtime.spi.IValue) KeyValue(org.hibernate.mapping.KeyValue) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 64 with IValue

use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.

the class TypeVisitor method buildCollectionValue.

private IValue buildCollectionValue(ITypeBinding[] interfaces) {
    IValue cValue = null;
    if (Utils.isImplementInterface(interfaces, Set.class.getName())) {
        cValue = service.newSet(rootClass);
    } else if (Utils.isImplementInterface(interfaces, List.class.getName())) {
        cValue = service.newList(rootClass);
    } else if (Utils.isImplementInterface(interfaces, Map.class.getName())) {
        cValue = service.newMap(rootClass);
    } else if (Utils.isImplementInterface(interfaces, Collection.class.getName())) {
        cValue = service.newBag(rootClass);
    }
    if (cValue == null)
        return null;
    // By default set the same table, but for one-to-many should change it to associated class's table
    cValue.setCollectionTable(rootClass.getTable());
    IValue key = service.newSimpleValue();
    // $NON-NLS-1$
    key.setTypeName("string");
    if (StringHelper.isNotEmpty(entityInfo.getPrimaryIdName())) {
        key.addColumn(service.newColumn(entityInfo.getPrimaryIdName().toUpperCase()));
    }
    cValue.setKey(key);
    cValue.setLazy(true);
    cValue.setRole(StringHelper.qualify(rootClass.getEntityName(), varName));
    return cValue;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map)

Example 65 with IValue

use of org.jboss.tools.hibernate.runtime.spi.IValue in project jbosstools-hibernate by jbosstools.

the class TypeVisitor method visit.

@Override
public boolean visit(ParameterizedType type) {
    // $NON-NLS-1$
    Assert.isNotNull(type, "Type object cannot be null");
    // $NON-NLS-1$
    Assert.isNotNull(entityInfo, "EntityInfo object cannot be null");
    ITypeBinding tb = type.resolveBinding();
    // Unresolved binding. Omit the property.
    if (tb == null)
        return false;
    rootClass = rootClasses.get(entityInfo.getFullyQualifiedName());
    // $NON-NLS-1$
    Assert.isNotNull(rootClass, "RootClass not found.");
    ITypeBinding[] interfaces = Utils.getAllInterfaces(tb);
    IValue value = buildCollectionValue(interfaces);
    if (value != null) {
        if (ref != null && rootClasses.get(ref.fullyQualifiedName) != null) {
            IValue oValue = service.newOneToMany(rootClass);
            IPersistentClass associatedClass = rootClasses.get(ref.fullyQualifiedName);
            oValue.setAssociatedClass(associatedClass);
            oValue.setReferencedEntityName(associatedClass.getEntityName());
            // Set another table
            value.setCollectionTable(associatedClass.getTable());
            value.setElement(oValue);
        } else {
            IValue elementValue = buildSimpleValue(tb.getTypeArguments()[0].getQualifiedName());
            elementValue.setTable(rootClass.getTable());
            value.setElement(elementValue);
            // TODO what to set?
            value.setCollectionTable(rootClass.getTable());
        }
        if (value.isList()) {
            value.setIndex(service.newSimpleValue());
        } else if (value.isMap()) {
            IValue map_key = service.newSimpleValue();
            // FIXME: is it possible to map Map<SourceType, String>?
            // Or only Map<String, SourceType>
            map_key.setTypeName(tb.getTypeArguments()[0].getBinaryName());
            value.setIndex(map_key);
        }
    }
    if (value == null) {
        value = buildSimpleValue(tb.getBinaryName());
    }
    buildProperty(value);
    if (!(value.isSimpleValue())) {
        // $NON-NLS-1$
        prop.setCascade("none");
    }
    // do not visit children
    return false;
}
Also used : IValue(org.jboss.tools.hibernate.runtime.spi.IValue) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Aggregations

IValue (org.jboss.tools.hibernate.runtime.spi.IValue)144 Test (org.junit.Test)105 SimpleValue (org.hibernate.mapping.SimpleValue)68 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)59 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)40 Bag (org.hibernate.mapping.Bag)20 Set (org.hibernate.mapping.Set)20 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)20 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)17 IdentifierBag (org.hibernate.mapping.IdentifierBag)16 KeyValue (org.hibernate.mapping.KeyValue)16 RootClass (org.hibernate.mapping.RootClass)16 Value (org.hibernate.mapping.Value)16 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)13 Collection (org.hibernate.mapping.Collection)8 Component (org.hibernate.mapping.Component)8 List (org.hibernate.mapping.List)8 PersistentClass (org.hibernate.mapping.PersistentClass)8 PrimitiveArray (org.hibernate.mapping.PrimitiveArray)8 Table (org.hibernate.mapping.Table)8