public Object getValueFromRecord(DatabaseRecord record, ResultSetMappingQuery query){
//from the row data build result entity.
// To do this let's collect the column based data for this entity from
// the results and call build object with this new row.
ClassDescriptor descriptor = query.getSession().getDescriptor(this.entityClass);
DatabaseRecord entityRecord = new DatabaseRecord(descriptor.getFields().size());
if (descriptor.hasInheritance()){
if (this.discriminatorColumn != null){
Object value = record.get(this.discriminatorColumn);
if (value == null){
throw QueryException.discriminatorColumnNotSelected(this.discriminatorColumn, query.getSQLResultSetMapping().getName());
}
entityRecord.put(descriptor.getInheritancePolicy().getClassIndicatorField(), record.get(this.discriminatorColumn));
}else{
entityRecord.put(descriptor.getInheritancePolicy().getClassIndicatorField(), record.get(descriptor.getInheritancePolicy().getClassIndicatorField()));
}
// if the descriptor uses inheritance and multiple types may have been read
//get the correct descriptor.
if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().shouldReadSubclasses()) {
Class classValue = descriptor.getInheritancePolicy().classFromRow(entityRecord, query.getSession());
descriptor = query.getSession().getDescriptor(classValue);
}
}
for (Iterator mappings = descriptor.getMappings().iterator(); mappings.hasNext();){
DatabaseMapping mapping = (DatabaseMapping)mappings.next();
FieldResult fieldResult = (FieldResult)this.getFieldResults().get(mapping.getAttributeName());
if (fieldResult != null){
if (mapping.getFields().size() == 1 ){
entityRecord.put(mapping.getFields().firstElement(), record.get(fieldResult.getColumnName()));
}else if (mapping.getFields().size() >1){
getValueFromRecordForMapping(entityRecord,mapping,fieldResult,record);
}
}else{
for (Iterator fields = mapping.getFields().iterator(); fields.hasNext();){
DatabaseField field = (DatabaseField)fields.next();
entityRecord.put(field, record.get(field));
}
}
}
query.setReferenceClass(this.entityClass);
query.setDescriptor(descriptor);