.iterator();
while (names.hasNext()) {
String tableName = (String) names.next();
Type tableType = SDOUtil.createType(types, getURI(), tableName, false);
Property property = SDOUtil.createProperty(rootType, tableName, tableType);
SDOUtil.setMany(property,true);
SDOUtil.setContainment(property, true);
}
// TODO tablePropertyMap is temporary until Tuscany-203 is fixed
HashMap tablePropertyMap = new HashMap();
for (int i = 1; i <= resultMetadata.getColumnNames().size(); i++) {
Property ref = rootType.getProperty(resultMetadata.getTablePropertyName(i));
// TODO Temporary code to check to see if a property has already been added.
// Replace when Tuscany-203 is fixed
ArrayList addedProperties = (ArrayList) tablePropertyMap.get(ref.getName());
if ( addedProperties == null ) {
addedProperties = new ArrayList();
tablePropertyMap.put(ref.getName(), addedProperties);
}
if (ref == null)
throw new RuntimeException("Could not find table "
+ resultMetadata.getTablePropertyName(i)
+ " in the SDO model");
String columnName = resultMetadata.getColumnPropertyName(i);
// TODO temporary check until Tuscany-203 is fixed
if ( !addedProperties.contains(columnName)) {
addedProperties.add(columnName);
Type atype = (Type) resultMetadata.getDataType(i);
SDOUtil.createProperty(ref.getType(), columnName, atype);
DebugUtil.debugln(getClass(), debug, "Adding column "
+ columnName + " to "
+ resultMetadata.getTablePropertyName(i));
}
}
}
if (metadata.hasMappingModel()) {
MappingWrapper wrapper = new MappingWrapper(metadata.getMapping());
Iterator i = metadata.getRelationships().iterator();
while (i.hasNext()) {
Relationship r = (Relationship) i.next();
Type parent = rootType.getProperty(
wrapper.getTablePropertyName(r.getPrimaryKeyTable())).getType();
Type child = rootType.getProperty(
wrapper.getTablePropertyName(r.getForeignKeyTable())).getType();
if (parent == null) {
throw new RuntimeException("The parent table ("
+ r.getPrimaryKeyTable() + ") in relationship "
+ r.getName()
+ " was not found in the mapping information.");
} else if (child == null) {
throw new RuntimeException("The child table ("
+ r.getForeignKeyTable() + ") in relationship "
+ r.getName()
+ " was not found in the mapping information.");
}
// ReferenceImpl ref = refMaker.createReference(r, parent, child);
Property parentProp = SDOUtil.createProperty(parent, r.getName(), child);
Property childProp = SDOUtil.createProperty(child, r.getName() + "_opposite", parent);
SDOUtil.setOpposite(parentProp, childProp);
SDOUtil.setOpposite(childProp, parentProp);
SDOUtil.setMany(parentProp, r.isMany());