* INTERNAL:
* Insert the private owned object.
*/
public void postInsert(WriteObjectQuery query) throws DatabaseException {
Object objects;
AbstractRecord databaseRow = new DatabaseRecord();
if (isReadOnly()) {
return;
}
objects = getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
DirectMapContainerPolicy containerPolicy = (DirectMapContainerPolicy)getContainerPolicy();
if (containerPolicy.isEmpty(objects)) {
return;
}
prepareTranslationRow(query.getTranslationRow(), query.getObject(), query.getSession());
// Extract primary key and value from the source.
for (int index = 0; index < getReferenceKeyFields().size(); index++) {
DatabaseField referenceKey = getReferenceKeyFields().get(index);
DatabaseField sourceKey = getSourceKeyFields().get(index);
Object sourceKeyValue = query.getTranslationRow().get(sourceKey);
databaseRow.put(referenceKey, sourceKeyValue);
}
// Extract target field and its value. Construct insert statement and execute it
Object keyIter = containerPolicy.iteratorFor(objects);
while (containerPolicy.hasNext(keyIter)) {
Object key = containerPolicy.next(keyIter, query.getSession());
Object value = containerPolicy.valueFromKey(key, objects);
if (getKeyConverter() != null) {
key = getKeyConverter().convertObjectValueToDataValue(key, query.getSession());
}
if (getValueConverter() != null) {
value = getValueConverter().convertObjectValueToDataValue(value, query.getSession());
}
databaseRow.put(getDirectKeyField(), key);
databaseRow.put(getDirectField(), value);
// In the uow data queries are cached until the end of the commit.
if (query.shouldCascadeOnlyDependentParts()) {
// Hey I might actually want to use an inner class here... ok array for now.
Object[] event = new Object[3];
event[0] = Insert;
event[1] = getInsertQuery();
event[2] = databaseRow.clone();
query.getSession().getCommitManager().addDataModificationEvent(this, event);
} else {
query.getSession().executeQuery(getInsertQuery(), databaseRow);
}
}