/**
* Extract primary key attribute values from the domainObject.
*/
public AbstractRecord extractPrimaryKeyRowFromObject(Object domainObject, AbstractSession session) {
AbstractRecord databaseRow = createRecord(getPrimaryKeyMappings().size());
// PERF: use index not enumeration.
for (int index = 0; index < getPrimaryKeyMappings().size(); index++) {
((DatabaseMapping)getPrimaryKeyMappings().get(index)).writeFromObjectIntoRow(domainObject, databaseRow, session);
}
// PERF: optimize simple primary key case, no need to remap.
if (getDescriptor().hasSimplePrimaryKey()) {
return databaseRow;
}
AbstractRecord primaryKeyRow = createRecord(getPrimaryKeyMappings().size());
List primaryKeyFields = getDescriptor().getPrimaryKeyFields();
for (int index = 0; index < primaryKeyFields.size(); index++) {
// Ensure that the type extracted from the object is the same type as in the descriptor,
// the main reason for this is that 1-1 can optimize on vh by getting from the row as the row-type.
Class classification = (Class)getPrimaryKeyClassifications().get(index);
DatabaseField field = (DatabaseField)primaryKeyFields.get(index);
Object value = databaseRow.get(field);
primaryKeyRow.put(field, session.getPlatform(domainObject.getClass()).convertObject(value, classification));
}
return primaryKeyRow;
}