/** * INTERNAL: * Compare the attributes belonging to this mapping for the objects. */ @Override public boolean compareObjects(Object object1, Object object2, AbstractSession session) { if (isForeignKeyRelationship()) { return (new EISOneToManyMappingHelper(this)).compareObjects(object1, object2, session); } return super.compareObjects(object1, object2, session); }
/** * INTERNAL: * Compare the attributes belonging to this mapping for the objects. */ public boolean compareObjects(Object object1, Object object2, AbstractSession session) { return this.compareAttributeValues(this.getRealCollectionAttributeValueFromObject(object1, session), this.getRealCollectionAttributeValueFromObject(object2, session), session); }
/** * ADVANCED: * This method is used to have an object removed from a collection once the changeSet is applied * The referenceKey parameter should only be used for direct Maps. */ public void simpleRemoveFromCollectionChangeRecord(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) { (new EISOneToManyMappingHelper(this)).simpleRemoveFromCollectionChangeRecord(referenceKey, changeSetToRemove, changeSet, session); }
/** * ADVANCED: * This method is used to have an object add to a collection once the changeSet is applied * The referenceKey parameter should only be used for direct Maps. */ @Override public void simpleAddToCollectionChangeRecord(Object referenceKey, Object changeSetToAdd, ObjectChangeSet changeSet, AbstractSession session) { (new EISOneToManyMappingHelper(this)).simpleAddToCollectionChangeRecord(referenceKey, changeSetToAdd, changeSet, session); }
ContainerPolicy cp = this.getContainerPolicy(); EISOrderedCollectionChangeRecord changeRecord = new EISOrderedCollectionChangeRecord(owner, this.getAttributeName(), this.getDatabaseMapping()); boolean found = false; for (int j = 0; j < backupVector.size(); j++) { if (this.compareElementsForChange(cloneElement, backupVector.get(j), session)) { changeRecord.addMovedChangeSet(this.buildChangeSet(cloneElement, owner, session), j, i); break;// matching backup element found - skip the rest of them changeRecord.addAddedChangeSet(this.buildChangeSet(cloneElement, owner, session), i); if (backupElement != XXX) { changeRecord.addRemovedChangeSet(this.buildChangeSet(backupElement, owner, session), i);
ContainerPolicy cp = this.getContainerPolicy(); AbstractSession session = mergeManager.getSession(); targetCollection = cp.containerInstance(sdkChangeRecord.getAdds().size()); } else { targetCollection = this.getRealCollectionAttributeValueFromObject(target, session); Object removeElement = this.buildRemovedElementFromChangeSet(stream.nextElement(), mergeManager); if (this.compareElements(targetElement, removeElement, session)) { break;// matching element found - skip the rest of them Object addElement = this.buildAddedElementFromChangeSet(stream.nextElement(), mergeManager); cp.addInto(addElement, targetCollection, session); Object changedMapKeyElement = this.buildAddedElementFromChangeSet(stream.nextElement(), mergeManager); Object originalElement = ((UnitOfWorkImpl)session).getOriginalVersionOfObject(changedMapKeyElement); cp.removeFrom(originalElement, targetCollection, session); this.setRealAttributeValueInObject(target, targetCollection);
/** * INTERNAL: * Merge changes from the source to the target object. * Simply replace the entire target collection. */ public void mergeIntoObject(Object target, boolean isTargetUnInitialized, Object source, MergeManager mergeManager, AbstractSession targetSession) { ContainerPolicy cp = this.getContainerPolicy(); AbstractSession session = mergeManager.getSession(); Object sourceCollection = this.getRealCollectionAttributeValueFromObject(source, session); Object targetCollection = cp.containerInstance(cp.sizeFor(sourceCollection)); for (Object iter = cp.iteratorFor(sourceCollection); cp.hasNext(iter);) { Object targetElement = this.buildElementFromElement(cp.next(iter, session), mergeManager, targetSession); cp.addInto(targetElement, targetCollection, session); } // reset the attribute to allow for set method to re-morph changes if the collection is not being stored directly setRealAttributeValueInObject(target, targetCollection); }
/** * 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); } }
/** * Merge changes from the source to the target object. * Simply replace the entire target collection. */ private void mergeChangesIntoObjectWithOrder(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager) { ContainerPolicy cp = this.getContainerPolicy(); AbstractSession session = mergeManager.getSession(); Vector changes = ((EISOrderedCollectionChangeRecord)changeRecord).getNewCollection(); Object targetCollection = cp.containerInstance(changes.size()); for (Enumeration stream = changes.elements(); stream.hasMoreElements();) { Object targetElement = this.buildAddedElementFromChangeSet(stream.nextElement(), mergeManager); cp.addInto(targetElement, targetCollection, session); } // reset the attribute to allow for set method to re-morph changes if the collection is not being stored directly this.setRealAttributeValueInObject(target, targetCollection); }
/** * Compare the attributes. Return true if they are alike. * Assume the passed-in attributes are non-null. */ private boolean compareAttributeValues(Object collection1, Object collection2, AbstractSession session) { ContainerPolicy cp = this.getContainerPolicy(); if (cp.sizeFor(collection1) != cp.sizeFor(collection2)) { return false; } // if they are both empty, go no further... if (cp.sizeFor(collection1) == 0) { return true; } if (cp.hasOrder()) { return this.compareAttributeValuesWithOrder(collection1, collection2, session); } else { return this.compareAttributeValuesWithoutOrder(collection1, collection2, session); } }
/** * INTERNAL: * Compare the changes between two collections. Element comparisons are * made using identity and, when appropriate, the value of the element's key * for the Map container. */ public ChangeRecord compareForChange(Object clone, Object backup, ObjectChangeSet owner, AbstractSession session) { if (isForeignKeyRelationship()) { if ((this.getAttributeValueFromObject(clone) != null) && (!this.isAttributeValueInstantiatedOrChanged(clone))) { return null;// never instantiated - no changes to report } return (new EISOneToManyMappingHelper(this)).compareForChange(clone, backup, owner, session); } else { return super.compareForChange(clone, backup, owner, session); } }
/** * INTERNAL: * If the mapping has a foreign key, it is order, so must use a different merge. */ @Override public void mergeIntoObject(Object target, boolean isTargetUnInitialized, Object source, MergeManager mergeManager, AbstractSession targetSession) { if (isForeignKeyRelationship()) { (new EISOneToManyMappingHelper(this)).mergeIntoObject(target, isTargetUnInitialized, source, mergeManager, targetSession); return; } super.mergeIntoObject(target, isTargetUnInitialized, source, mergeManager, targetSession); }
/** * INTERNAL: * If the mapping has a foreign key, it is order, so must use a different merge. */ @Override public void mergeChangesIntoObject(Object target, ChangeRecord chgRecord, Object source, MergeManager mergeManager, AbstractSession targetSession) { if (isForeignKeyRelationship()) { (new EISOneToManyMappingHelper(this)).mergeChangesIntoObject(target, chgRecord, source, mergeManager, targetSession); return; } super.mergeChangesIntoObject(target, chgRecord, source, mergeManager, targetSession); }
ContainerPolicy cp = this.getContainerPolicy(); EISOrderedCollectionChangeRecord changeRecord = new EISOrderedCollectionChangeRecord(owner, this.getAttributeName(), this.getDatabaseMapping()); boolean found = false; for (int j = 0; j < backupVector.size(); j++) { if (this.compareElementsForChange(cloneElement, backupVector.get(j), session)) { changeRecord.addMovedChangeSet(this.buildChangeSet(cloneElement, owner, session), j, i); break;// matching backup element found - skip the rest of them changeRecord.addAddedChangeSet(this.buildChangeSet(cloneElement, owner, session), i); if (backupElement != XXX) { changeRecord.addRemovedChangeSet(this.buildChangeSet(backupElement, owner, session), i);
ContainerPolicy cp = this.getContainerPolicy(); AbstractSession session = mergeManager.getSession(); targetCollection = cp.containerInstance(sdkChangeRecord.getAdds().size()); } else { targetCollection = this.getRealCollectionAttributeValueFromObject(target, session); Object removeElement = buildRemovedElementFromChangeSet(removed, mergeManager, targetSession); if (this.compareElements(targetElement, removeElement, session)) { break;// matching element found - skip the rest of them Object addElement = buildAddedElementFromChangeSet(added, mergeManager, targetSession); cp.addInto(addElement, targetCollection, session); Object changedMapKeyElement = buildAddedElementFromChangeSet(changed, mergeManager, targetSession); Object originalElement = ((UnitOfWorkImpl)session).getOriginalVersionOfObject(changedMapKeyElement); cp.removeFrom(originalElement, targetCollection, session); setRealAttributeValueInObject(target, targetCollection);
/** * INTERNAL: * Merge changes from the source to the target object. * Simply replace the entire target collection. */ public void mergeIntoObject(Object target, boolean isTargetUnInitialized, Object source, MergeManager mergeManager) { ContainerPolicy cp = this.getContainerPolicy(); AbstractSession session = mergeManager.getSession(); Object sourceCollection = this.getRealCollectionAttributeValueFromObject(source, session); Object targetCollection = cp.containerInstance(cp.sizeFor(sourceCollection)); for (Object iter = cp.iteratorFor(sourceCollection); cp.hasNext(iter);) { Object targetElement = this.buildElementFromElement(cp.next(iter, session), mergeManager); cp.addInto(targetElement, targetCollection, session); } // reset the attribute to allow for set method to re-morph changes if the collection is not being stored directly this.setRealAttributeValueInObject(target, targetCollection); }
/** * 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); } }
/** * Merge changes from the source to the target object. * Simply replace the entire target collection. */ private void mergeChangesIntoObjectWithOrder(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager, AbstractSession targetSession) { ContainerPolicy cp = this.getContainerPolicy(); AbstractSession session = mergeManager.getSession(); List changes = ((EISOrderedCollectionChangeRecord)changeRecord).getNewCollection(); Object targetCollection = cp.containerInstance(changes.size()); for (Object changed : changes) { Object targetElement = buildAddedElementFromChangeSet(changed, mergeManager, targetSession); cp.addInto(targetElement, targetCollection, session); } // reset the attribute to allow for set method to re-morph changes if the collection is not being stored directly this.setRealAttributeValueInObject(target, targetCollection); }
/** * Compare the attributes. Return true if they are alike. * Assume the passed-in attributes are non-null. */ private boolean compareAttributeValues(Object collection1, Object collection2, AbstractSession session) { ContainerPolicy cp = this.getContainerPolicy(); if (cp.sizeFor(collection1) != cp.sizeFor(collection2)) { return false; } // if they are both empty, go no further... if (cp.sizeFor(collection1) == 0) { return true; } if (cp.hasOrder()) { return this.compareAttributeValuesWithOrder(collection1, collection2, session); } else { return this.compareAttributeValuesWithoutOrder(collection1, collection2, session); } }
/** * ADVANCED: * This method is used to have an object removed from a collection once the changeSet is applied * The referenceKey parameter should only be used for direct Maps. */ @Override public void simpleRemoveFromCollectionChangeRecord(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) { (new EISOneToManyMappingHelper(this)).simpleRemoveFromCollectionChangeRecord(referenceKey, changeSetToRemove, changeSet, session); }