* their changes written to the database. It will then decrement the depth
* level.
*/
public void writeChanges() {
if(unregisteredDeletedObjectsCloneToBackupAndOriginal == null) {
unregisteredDeletedObjectsCloneToBackupAndOriginal = new IdentityHashtable(2);
}
IdentityHashtable allObjectsList = new IdentityHashtable(2);
IdentityHashtable visitedNodes = new IdentityHashtable(2);
IdentityHashtable newObjects = new IdentityHashtable(2);
IdentityHashtable existingObjects = new IdentityHashtable(2);
IdentityHashtable insertedNewObjects = new IdentityHashtable(2);
for (Enumeration clones = getCloneMapping().keys(); clones.hasMoreElements();){
Object object = clones.nextElement();
allObjectsList.put(object, object);
}
discoverUnregisteredNewObjects(newObjects, existingObjects, visitedNodes);
for (Enumeration newClones = getNewObjectsCloneToOriginal().keys();newClones.hasMoreElements();){
Object object = newClones.nextElement();
assignSequenceNumber(object);
insertedNewObjects.put(object, object);
// add potentially newly discovered new objects
allObjectsList.put(object, object);
}
if (getUnitOfWorkChangeSet() == null) {
setUnitOfWorkChangeSet(new UnitOfWorkChangeSet());
}
calculateChanges(allObjectsList, (UnitOfWorkChangeSet)getUnitOfWorkChangeSet());
// write those changes to the database.
UnitOfWorkChangeSet changeSet = (UnitOfWorkChangeSet)getUnitOfWorkChangeSet();
if (!changeSet.hasChanges() && !changeSet.hasForcedChanges() && ! this.hasDeletedObjects() && ! this.hasModifyAllQueries()){
return;
}
try {
commitToDatabaseWithPreBuiltChangeSet(changeSet, false);
this.writesCompleted();
} catch (RuntimeException ex) {
clearFlushClearCache();
setLifecycle(WriteChangesFailed);
throw ex;
}
//bug 4730595: fix puts deleted objects in the UnitOfWorkChangeSet as they are removed.
getDeletedObjects().clear();
// unregister all deleted objects,
// keep them along with their original and backup values in unregisteredDeletedObjectsCloneToBackupAndOriginal
Enumeration enumDeleted = getObjectsDeletedDuringCommit().keys();
while(enumDeleted.hasMoreElements()) {
Object deletedObject = enumDeleted.nextElement();
Object[] backupAndOriginal = {getCloneMapping().get(deletedObject), getCloneToOriginals().get(deletedObject)};
unregisteredDeletedObjectsCloneToBackupAndOriginal.put(deletedObject, backupAndOriginal);
unregisterObject(deletedObject);
}
getObjectsDeletedDuringCommit().clear();
if(this.cumulativeUOWChangeSet == null) {
this.cumulativeUOWChangeSet = (UnitOfWorkChangeSet)getUnitOfWorkChangeSet();
} else {
//merge those changes back into the backup clones and the final uowChangeSet
this.cumulativeUOWChangeSet.mergeUnitOfWorkChangeSet((UnitOfWorkChangeSet)getUnitOfWorkChangeSet(), this, true);
}
//clean up
setUnitOfWorkChangeSet(new UnitOfWorkChangeSet());
Enumeration enumtr = insertedNewObjects.elements();
while (enumtr.hasMoreElements()) {
Object clone = enumtr.nextElement();
Object original = getNewObjectsCloneToOriginal().remove(clone);
if (original != null) {
getNewObjectsOriginalToClone().remove(original);