/** * INTERNAL: * Remove change. Used by the event mechanism to reset changes after client has * updated the object within an event; */ public void removeChange(String attributeName){ Object record = getChangesForAttributeNamed(attributeName); if (record != null){ getChanges().removeElement(record); } }
/** * ADVANCED: * Returns true if this particular changeSet has changes. * @return boolean */ public boolean hasChanges() { // a change set must also be considered dirty if only the version number has been updated // and the version is not a mapped field. This is required to propagate the change // set via cache sync. to avoid opt. lock exceptions on the remote servers. return this.hasVersionChange || !this.getChanges().isEmpty(); }
/** * INTERNAL: * Iterate through the change records and ensure the cache synchronization types * are set on the change sets associated with those records. */ public void prepareChangeRecordsForSynchronization(AbstractSession session) { Enumeration records = getChanges().elements(); while (records.hasMoreElements()) { ((ChangeRecord)records.nextElement()).prepareForSynchronization(session); } }
for (int index = 0; index < changeSetToMergeFrom.getChanges().size(); ++index) { ChangeRecord record = (ChangeRecord)changeSetToMergeFrom.getChanges().get(index); ChangeRecord thisRecord = (ChangeRecord) this.getChangesForAttributeNamed(record.getAttribute()); if (thisRecord == null) {
/** * INTERNAL: * This method will be used when merging changesets into other changesets. * It will fix references within a changeSet so that it's records point to * changesets within this UOWChangeSet. */ public void updateReferences(UnitOfWorkChangeSet localChangeSet, UnitOfWorkChangeSet mergingChangeSet) { for (int index = 0; index < this.getChanges().size(); ++index) { ChangeRecord record = (ChangeRecord)this.getChanges().get(index); record.updateReferences(localChangeSet, mergingChangeSet); record.setOwner(this); } }
/** * ADVANCED: * This method will return a collection of the fieldnames of attributes changed in an object * */ public Vector getChangedAttributeNames() { Vector names = new Vector(); Enumeration attributes = getChanges().elements(); while (attributes.hasMoreElements()) { names.addElement(((ChangeRecord)attributes.nextElement()).getAttribute()); } return names; }
/** * ADVANCED: * This method will return true if the specified attributue has been changed * * @param String the name of the attribute to search for */ public boolean hasChangeFor(String attributeName) { Enumeration attributes = getChanges().elements(); while (attributes.hasMoreElements()) { if (((ChangeRecord)attributes.nextElement()).getAttribute().equals(attributeName)) { return true; } } return false; }
public String toString() { return this.getClass().getName() + "(" + this.getClassName() + ")" + getChanges().toString(); }
/** * @param changeRecord prototype.changeset.ChangeRecord */ public void addChange(ChangeRecord changeRecord) { if (changeRecord == null) { return; } ChangeRecord existingChangeRecord = (ChangeRecord)getAttributesToChanges().get(changeRecord.getAttribute()); // change tracking may add a change to an existing attribute fix that here. if ( existingChangeRecord != null){ getChanges().remove(existingChangeRecord); } getChanges().addElement(changeRecord); getAttributesToChanges().put(changeRecord.getAttribute(), changeRecord); updateUOWChangeSet(); }
/** * Build the row representation of the object for update. The row built does not * contain entries for uninstantiated attributes. */ public AbstractRecord buildRowForUpdateWithChangeSet(WriteObjectQuery query) { AbstractRecord databaseRow = createRecord(); for (Iterator changeRecords = query.getObjectChangeSet().getChanges().iterator(); changeRecords.hasNext();) { ChangeRecord changeRecord = (ChangeRecord)changeRecords.next(); DatabaseMapping mapping = changeRecord.getMapping(); mapping.writeFromObjectIntoRowWithChangeRecord(changeRecord, databaseRow, query.getSession()); } return databaseRow; }
/** * Build the row representation of an object. */ public AbstractRecord buildRowWithChangeSet(AbstractRecord databaseRow, ObjectChangeSet objectChangeSet, AbstractSession session) { for (Enumeration changeRecords = objectChangeSet.getChanges().elements(); changeRecords.hasMoreElements();) { ChangeRecord changeRecord = (ChangeRecord)changeRecords.nextElement(); DatabaseMapping mapping = changeRecord.getMapping(); mapping.writeFromObjectIntoRowWithChangeRecord(changeRecord, databaseRow, session); } // If this descriptor is involved in inheritence add the class type. if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } return databaseRow; }
/** * Build the row representation of the object for update. The row built does not * contain entries for uninstantiated attributes. */ public AbstractRecord buildRowForShallowInsertWithChangeSet(AbstractRecord databaseRow, ObjectChangeSet objectChangeSet, AbstractSession session) { for (Iterator changeRecords = objectChangeSet.getChanges().iterator(); changeRecords.hasNext();) { ChangeRecord changeRecord = (ChangeRecord)changeRecords.next(); DatabaseMapping mapping = changeRecord.getMapping(); mapping.writeFromObjectIntoRowForShallowInsertWithChangeRecord(changeRecord, databaseRow, session); } // If this descriptor is involved in inheritence add the class type. if (getDescriptor().hasInheritance()) { getDescriptor().getInheritancePolicy().addClassIndicatorFieldToRow(databaseRow); } // If this descriptor has multiple tables then we need to append the primary keys for // the non default tables. if (!getDescriptor().isAggregateDescriptor()) { addPrimaryKeyForNonDefaultTable(databaseRow); } return databaseRow; }
/** * INTERNAL: * Merge changes between the objects, this merge algorthim is dependent on the merge manager. */ public void mergeChangesIntoObject(Object target, ObjectChangeSet changeSet, Object source, MergeManager mergeManager) { for (Enumeration changes = changeSet.getChanges().elements(); changes.hasMoreElements();) { ChangeRecord record = (ChangeRecord)changes.nextElement(); //cr 4236, use ObjectBuilder getMappingForAttributeName not the Descriptor one because the // ObjectBuilder method is much more efficient. DatabaseMapping mapping = getMappingForAttributeName(record.getAttribute()); mapping.mergeChangesIntoObject(target, record, source, mergeManager); } // PERF: Avoid events if no listeners. if (getDescriptor().getEventManager().hasAnyEventListeners()) { oracle.toplink.essentials.descriptors.DescriptorEvent event = new oracle.toplink.essentials.descriptors.DescriptorEvent(target); event.setSession(mergeManager.getSession()); event.setOriginalObject(source); event.setChangeSet(changeSet); event.setEventCode(DescriptorEventManager.PostMergeEvent); getDescriptor().getEventManager().executeEvent(event); } }