/**
* Build a database row from the record returned from the interaction.
* Also handles MappedRecords for case of input being indexed but mapped ouput.
*/
public AbstractRecord buildRow(Record record, EISAccessor accessor) {
AbstractRecord row = null;
if (record instanceof IndexedRecord) {
IndexedRecord indexedRecord = (IndexedRecord)record;
row = new DatabaseRecord(indexedRecord.size());
for (int index = 0; index < indexedRecord.size(); index++) {
DatabaseField field = (DatabaseField)getOutputArguments().get(index);
row.put(field, indexedRecord.get(index));
}
} else if (record instanceof MappedRecord) {
MappedRecord mappedRecord = (MappedRecord)record;
// Handle the case of a single output argument of the entire row contained within the return record.
if (getOutputArgumentNames().size() == 1) {
mappedRecord = (MappedRecord)mappedRecord.get(getOutputArgumentNames().get(0));
// Handle the case were the output row is mapped into a database row of values.
} else if (getOutputArgumentNames().size() > 1) {
row = new DatabaseRecord(getOutputArgumentNames().size());
for (int index = 0; index < getOutputArgumentNames().size(); index++) {
DatabaseField field = (DatabaseField)getOutputArguments().get(index);
row.put(field, mappedRecord.get(getOutputArgumentNames().get(index)));
}
return row;
}
// Wrapped the record in a database to avoid loosing any information in conversion to database row,
// also gets around problem of some adatpers not supporting keySet or entrySet.
row = new EISMappedRecord(mappedRecord, accessor);
} else {
row = new DatabaseRecord(1);
row.put(getOutputResultPath(), record);
}
return row;
}