/** * INTERNAL: Build and return the change record that results from comparing the two collection * attributes. */ public ChangeRecord compareForChange( Object clone, Object backup, ObjectChangeSet owner, AbstractSession session) { ContainerPolicy cp = this.getContainerPolicy(); Object cloneCollection = this.getRealCollectionAttributeValueFromObject(clone, session); Object backupCollection = null; if (owner.isNew()) { backupCollection = cp.containerInstance(1); } else { backupCollection = this.getRealCollectionAttributeValueFromObject(backup, session); } if (cp.hasOrder()) { return this.compareAttributeValuesForChangeWithOrder( cloneCollection, backupCollection, owner, session); } else { return this.compareAttributeValuesForChangeWithoutOrder( cloneCollection, backupCollection, owner, session); } }
/** * Commit changed of the objects of the class type in the change set. This allows for the order of * the classes to be processed optimally. */ protected void commitChangedObjectsForClassWithChangeSet( UnitOfWorkChangeSet uowChangeSet, Class theClass) { Map<ObjectChangeSet, ObjectChangeSet> objectChangesList = uowChangeSet.getObjectChanges().get(theClass); if (objectChangesList != null) { // may be no changes for that class type. ClassDescriptor descriptor = null; AbstractSession session = getSession(); Collection<ObjectChangeSet> changes = objectChangesList.values(); if (((UnitOfWorkImpl) session).shouldOrderUpdates()) { changes = new ArrayList(objectChangesList.values()); Collections.sort((List) changes); } for (ObjectChangeSet changeSetToWrite : changes) { Object objectToWrite = changeSetToWrite.getUnitOfWorkClone(); if (descriptor == null) { descriptor = session.getDescriptor(objectToWrite); } if (!isProcessedCommit(objectToWrite)) { // Commit and resume on failure can cause a new change set to be in existing, so need to // check here. WriteObjectQuery commitQuery = null; if (changeSetToWrite.isNew()) { commitQuery = new InsertObjectQuery(); } else { commitQuery = new UpdateObjectQuery(); } commitQuery.setIsExecutionClone(true); commitQuery.setDescriptor(descriptor); commitQuery.setObjectChangeSet(changeSetToWrite); commitQuery.setObject(objectToWrite); commitQuery.cascadeOnlyDependentParts(); // removed checking session type to set cascade level // will always be a unitOfWork so we need to cascade dependent parts session.executeQuery(commitQuery); } } } }