if (cp.isEmpty(objects)) {
return;
}
prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getSession());
AbstractRecord databaseRow = new DatabaseRecord();
// Extract primary key and value from the source.
int size = sourceKeyFields.size();
for (int index = 0; index < size; index++) {
DatabaseField sourceKey = sourceKeyFields.get(index);
DatabaseField targetForeignKey = targetForeignKeyFields.get(index);
Object sourceKeyValue = query.getTranslationRow().get(sourceKey);
databaseRow.put(targetForeignKey, sourceKeyValue);
}
// Extract target field and its value. Construct insert statement and execute it
List<DatabaseField> targetPrimaryKeyFields = getReferenceDescriptor().getPrimaryKeyFields();
size = targetPrimaryKeyFields.size();
for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter);) {
Object object = cp.next(iter, query.getSession());
for(int index = 0; index < size; index++) {
DatabaseField targetPrimaryKey = targetPrimaryKeyFields.get(index);
Object targetKeyValue = getReferenceDescriptor().getObjectBuilder().extractValueFromObjectForField(object, targetPrimaryKey, query.getSession());
databaseRow.put(targetPrimaryKey, targetKeyValue);
}
query.getSession().executeQuery(addTargetQuery, databaseRow);
}
}