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);
}
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);
}
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());
}
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;
}
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;
}
Aggregations