in rdb/src/main/java/org/apache/tuscany/das/rdb/graphbuilder/impl/DataObjectMaker.java [61:118]
public DataObject createAndAddDataObject(TableData tableData, ResultMetadata resultMetadata) {
// Get a Type from the package and create a standalone DataObject
if (this.logger.isDebugEnabled()) {
this.logger.debug("Looking for Type for " + tableData.getTableName());
}
String tableName = tableData.getTableName();
Type tableClass = (Type) typeMap.get(tableName);
if (tableClass == null) {
throw new RuntimeException("An SDO Type with name " + tableData.getTableName() + " was not found");
}
DataObject obj = DataFactory.INSTANCE.create(tableClass);
// Now, check to see if the root data object has a containment reference
// to this EClass. If so, add it to the graph. If not, it will be taken
// care of when we process relationships
Property containmentProp = (Property) containmentPropertyMap.get(tableName);
if (containmentProp != null) {
if (containmentProp.isMany()) {
rootObject.getList(containmentProp).add(obj);
} else {
this.rootObject.set(containmentProp, obj);
}
}
// Set the column values
Iterator columnNames = resultMetadata.getPropertyNames(tableData.getTableName()).iterator();
Type objType = obj.getType();
while (columnNames.hasNext()) {
String propertyName = (String) columnNames.next();
Property p = objType.getProperty(propertyName);
if (p == null) {
// Try again, ignoring case
p = findProperty(objType, propertyName);
if (p == null) {
throw new RuntimeException("Type " + obj.getType().getName()
+ " does not contain a property named " + propertyName);
}
}
Object value = tableData.getColumnData(propertyName);
try {
obj.set(p, value);
} catch (ClassCastException e) {
// a mismatch between the value and property types may happen in some cases
// e.g. when the property is a boolean but the database doesn't have a boolean data type
if (value != null) {
Object convertedValue = DataObjectUtil.getSetValue(p, value.toString());
obj.set(p, convertedValue);
}
}
}
return obj;
}