*/
public Object set(StateManager ownerSm, int index, Object element, boolean allowDependentField,
ElementContainerStore ecs, Object obj) {
DatastorePersistenceHandler handler = storeMgr.getPersistenceHandler();
JavaTypeMapping orderMapping = ecs.getOrderMapping();
ObjectManager om = ownerSm.getObjectManager();
if (orderMapping != null) {
StateManager childSm = om.findStateManager(element);
// See DatastoreFieldManager.handleIndexFields for info on why this
// absurdity is necessary.
Entity childEntity =
(Entity) childSm.getAssociatedValue(DatastorePersistenceHandler.ENTITY_WRITE_DELAYED);
if (childEntity != null) {
childSm.setAssociatedValue(DatastorePersistenceHandler.ENTITY_WRITE_DELAYED, null);
childSm.setAssociatedValue(ecs.getOrderMapping(), index);
handler.insertObject(childSm);
}
}
if (ecs.getOwnerMemberMetaData().getCollection().isDependentElement() &&
allowDependentField && obj != null) {
ownerSm.getObjectManager().deleteObjectInternal(obj);
}
if (!om.getTransaction().isActive()) {
om.getTransaction().addTransactionEventListener(
new ForceFlushPreCommitTransactionEventListener(ownerSm));
}
return obj;
}