* Insert the private owned object.
*/
@Override
public void postInsert(WriteObjectQuery query) throws DatabaseException {
Object objects;
AbstractRecord databaseRow = new DatabaseRecord();
if (isReadOnly()) {
return;
}
objects = getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
ContainerPolicy containerPolicy = 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);
}
int orderIndex = 0;
// Extract target field and its value. Construct insert statement and execute it
for (Object iter = containerPolicy.iteratorFor(objects); containerPolicy.hasNext(iter);) {
Object wrappedObject = containerPolicy.nextEntry(iter, query.getSession());
Object object = containerPolicy.unwrapIteratorResult(wrappedObject);
if (getValueConverter() != null) {
object = getValueConverter().convertObjectValueToDataValue(object, query.getSession());
}
databaseRow.put(getDirectField(), object);
// 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();
if(listOrderField != null) {
((AbstractRecord)event[2]).put(listOrderField, orderIndex++);
}
query.getSession().getCommitManager().addDataModificationEvent(this, event);
} else {