/** * INTERNAL: */ protected void registerRemoveNewObjectIfRequired(ObjectChangeSet objectChanges, MergeManager mergeManager) { if (! mergeManager.shouldMergeChangesIntoDistributedCache()) { mergeManager.registerRemovedNewObjectIfRequired(objectChanges.getUnitOfWorkClone()); } }
/** * INTERNAL: * This method can be used find the equivalent changeset within this UnitOfWorkChangeSet * Aggregates, and new objects without primaryKeys from serialized ChangeSets will not be found * Which may result in duplicates, in the UnitOfWorkChangeSet. */ public ObjectChangeSet findObjectChangeSet(ObjectChangeSet changeSet, UnitOfWorkChangeSet mergeFromChangeSet) { Hashtable changes = (Hashtable)getObjectChanges().get(changeSet.getClassName()); ObjectChangeSet potential = null; if (changes != null) { potential = (ObjectChangeSet)changes.get(changeSet); } if (potential == null) { potential = (ObjectChangeSet)this.getObjectChangeSetForClone(changeSet.getUnitOfWorkClone()); } return potential; }
/** * INTERNAL: * This method will be used during the merge process to either find an equivalent change set * within this UnitOfWorkChangeSet or integrate that changeset into this UOW ChangeSet */ public ObjectChangeSet findOrIntegrateObjectChangeSet(ObjectChangeSet tofind, UnitOfWorkChangeSet mergeFromChangeSet) { if (tofind == null) { return tofind; } ObjectChangeSet localChangeSet = this.findObjectChangeSet(tofind, mergeFromChangeSet); if (localChangeSet == null) {//not found locally then replace it with the one from the merging changeset localChangeSet = new ObjectChangeSet(tofind.getPrimaryKeys(), tofind.getClassType(), tofind.getUnitOfWorkClone(), this, tofind.isNew()); this.addObjectChangeSetForIdentity(localChangeSet, localChangeSet.getUnitOfWorkClone()); } return localChangeSet; }
/** * 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 objectToRemove, ObjectChangeSet changeSet, AbstractSession session) { DirectCollectionChangeRecord collectionChangeRecord = (DirectCollectionChangeRecord)changeSet.getChangesForAttributeNamed(getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectCollectionChangeRecord(changeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); changeSet.addChange(collectionChangeRecord); Object collection = getRealAttributeValueFromObject(changeSet.getUnitOfWorkClone(), session); collectionChangeRecord.storeDatabaseCounts(collection, getContainerPolicy(), session); } collectionChangeRecord.addRemoveChange(objectToRemove, new Integer(1)); }
/** * 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. */ public void simpleAddToCollectionChangeRecord(Object referenceKey, Object objectToAdd, ObjectChangeSet changeSet, AbstractSession session) { DirectCollectionChangeRecord collectionChangeRecord = (DirectCollectionChangeRecord)changeSet.getChangesForAttributeNamed(getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectCollectionChangeRecord(changeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); changeSet.addChange(collectionChangeRecord); Object collection = getRealAttributeValueFromObject(changeSet.getUnitOfWorkClone(), session); collectionChangeRecord.storeDatabaseCounts(collection, getContainerPolicy(), session); } collectionChangeRecord.addAdditionChange(objectToAdd, new Integer(1)); }
Object object = ((ObjectChangeSet)changeRecord.getOwner()).getUnitOfWorkClone(); AbstractRecord referenceRow = getIndirectionPolicy().extractReferenceRow(getAttributeValueFromObject(object)); if (referenceRow == null) {
/** * INTERNAL: * Add a new value and its change set to the collection change record. This is used by * attribute change tracking. */ public void addToCollectionChangeRecord(Object newKey, Object newValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { if (newValue == null) { newValue = DirectCollectionChangeRecord.Null; } ClassDescriptor descriptor; DirectCollectionChangeRecord collectionChangeRecord = (DirectCollectionChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectCollectionChangeRecord(objectChangeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); objectChangeSet.addChange(collectionChangeRecord); Object collection = getRealAttributeValueFromObject(objectChangeSet.getUnitOfWorkClone(), uow); collectionChangeRecord.storeDatabaseCounts(collection, getContainerPolicy(), uow); } collectionChangeRecord.addAdditionChange(newValue, new Integer(1)); }
/** * INTERNAL: * Remove a value and its change set from the collection change record. This is used by * attribute change tracking. */ public void removeFromCollectionChangeRecord(Object newKey, Object newValue, ObjectChangeSet objectChangeSet, UnitOfWorkImpl uow) { if (newValue == null) { newValue = DirectCollectionChangeRecord.Null; } ClassDescriptor descriptor; DirectCollectionChangeRecord collectionChangeRecord = (DirectCollectionChangeRecord)objectChangeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { collectionChangeRecord = new DirectCollectionChangeRecord(objectChangeSet); collectionChangeRecord.setAttribute(getAttributeName()); collectionChangeRecord.setMapping(this); objectChangeSet.addChange(collectionChangeRecord); Object collection = getRealAttributeValueFromObject(objectChangeSet.getUnitOfWorkClone(), uow); collectionChangeRecord.storeDatabaseCounts(collection, getContainerPolicy(), uow); } collectionChangeRecord.addRemoveChange(newValue, new Integer(1)); }
/** * Commit all 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 commitNewObjectsForClassWithChangeSet(UnitOfWorkChangeSet uowChangeSet, Class theClass) { IdentityHashtable newObjectChangesList = (IdentityHashtable)uowChangeSet.getNewObjectChangeSets().get(theClass); if (newObjectChangesList != null) {// may be no changes for that class type. ClassDescriptor descriptor = getSession().getDescriptor(theClass); for (Enumeration pendingEnum = newObjectChangesList.elements(); pendingEnum.hasMoreElements();) { ObjectChangeSet changeSetToWrite = (ObjectChangeSet)pendingEnum.nextElement(); Object objectToWrite = changeSetToWrite.getUnitOfWorkClone(); if ((!getProcessedCommits().containsKey(changeSetToWrite)) && (!getProcessedCommits().containsKey(objectToWrite))) { addProcessedCommit(changeSetToWrite); InsertObjectQuery commitQuery = new InsertObjectQuery(); 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 getSession().executeQuery(commitQuery); } ((UnitOfWorkImpl)getSession()).updateChangeTrackersIfRequired(objectToWrite, changeSetToWrite, (UnitOfWorkImpl)getSession(), descriptor); //after the query has executed lets clear the change detection policies //this is important for write changes and non deferred writes support } } }
Object objectToWrite = changeSetToWrite.getUnitOfWorkClone(); if ((!getProcessedCommits().containsKey(changeSetToWrite)) && (!getProcessedCommits().containsKey(objectToWrite))) { addProcessedCommit(changeSetToWrite);
mergeManager.registerRemovedNewObjectIfRequired(objectChanges.getUnitOfWorkClone());
objectRemovedDuringUpdate(query, removedChangeSet.getUnitOfWorkClone()); objectAddedDuringUpdate(query, addedChangeSet.getUnitOfWorkClone(), addedChangeSet);
/** * INTERNAL: * Build and return a database row built with the values from * the specified attribute value. */ protected AbstractRecord buildRowFromAggregateWithChangeRecord(ChangeRecord changeRecord, ObjectChangeSet objectChangeSet, AbstractSession session, boolean forceWriteOfReadOnlyClasses) throws DescriptorException { if (objectChangeSet == null) { if (isNullAllowed()) { return buildNullReferenceRow(); } else { Object object = ((ObjectChangeSet)changeRecord.getOwner()).getUnitOfWorkClone(); throw DescriptorException.nullForNonNullAggregate(object, this); } } else { if ((!forceWriteOfReadOnlyClasses) && (session.isClassReadOnly(objectChangeSet.getClassType(session)))) { return new DatabaseRecord(1); } else { return getReferenceDescriptor(objectChangeSet.getClassType(session), session).getObjectBuilder().buildRowWithChangeSet(objectChangeSet, session); } } }
ObjectChangeSet changeSetToWrite = (ObjectChangeSet)pendingEnum.nextElement(); if (changeSetToWrite.hasChanges()) { Object objectToWrite = changeSetToWrite.getUnitOfWorkClone(); ObjectChangeSet changeSetToWrite = (ObjectChangeSet)pendingEnum.nextElement(); if (changeSetToWrite.hasChanges()) { Object objectToWrite = changeSetToWrite.getUnitOfWorkClone(); manager.mergeChanges(objectToWrite, changeSetToWrite); } else {
objectChanges = (ObjectChangeSet)aggregateObjects.elementAt(i); Class localClassType = objectChanges.getClassType(session); sourceAggregate = objectChanges.getUnitOfWorkClone();
mergeManager.mergeChanges(objectChanges.getUnitOfWorkClone(), objectChanges);
mergeManager.mergeChanges(set.getUnitOfWorkClone(), set);