if (this.isReadOnly()) { return; Object attributeValue = this.getAttributeValueFromObject(object); if (attributeValue == null) { row.put(this.getField(), null); return; ContainerPolicy cp = this.getContainerPolicy(); Object element = cp.next(iter, session); if (hasConverter()) { element = getConverter().convertObjectValueToDataValue(element, session); nestedRows.addElement(buildCompositeRow(element, session, row, writeType)); fieldValue = this.getReferenceDescriptor().buildFieldValueFromNestedRows(nestedRows, getStructureName(), session); row.put(this.getField(), fieldValue);
/** * INTERNAL: * Build and return a new element based on the change set. */ public Object buildAddedElementFromChangeSet(Object changeSet, MergeManager mergeManager, AbstractSession targetSession) { return this.buildElementFromChangeSet(changeSet, mergeManager, targetSession); }
/** * INTERNAL: * The mapping is initialized with the given session. This mapping is fully initialized * after this. */ @Override public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); if (getField() == null) { throw DescriptorException.fieldNameNotSetInMapping(this); } setField(getDescriptor().buildField(getField())); setFields(collectFields()); if (hasConverter()) { getConverter().initialize(this, session); } }
/** * INTERNAL: * Write fields needed for insert into the template with null values. */ @Override public void writeInsertFieldsIntoRow(AbstractRecord record, AbstractSession session) { if (this.isReadOnly()) { return; } record.put(this.getField(), null); }
/** * INTERNAL: * Convenience method. * Return the value of an attribute, unwrapping value holders if necessary. * If the value is null, build a new container. */ public Object getRealCollectionAttributeValueFromObject(Object object, AbstractSession session) throws DescriptorException { Object value = this.getRealAttributeValueFromObject(object, session); if (value == null) { value = this.getContainerPolicy().containerInstance(1); } return value; }
/** * INTERNAL: * Cascade discover and persist new objects during commit. */ public void cascadeDiscoverAndPersistUnregisteredNewObjects(Object object, Map newObjects, Map unregisteredExistingObjects, Map visitedObjects, UnitOfWorkImpl uow) { Object cloneAttribute = getAttributeValueFromObject(object); if (cloneAttribute == null ) { return; } ContainerPolicy containerPolicy = getContainerPolicy(); Object cloneObjectCollection = getRealCollectionAttributeValueFromObject(object, uow); Object iterator = containerPolicy.iteratorFor(cloneObjectCollection); while (containerPolicy.hasNext(iterator)) { Object nextObject = containerPolicy.next(iterator, uow); if (nextObject != null) { ObjectBuilder builder = getReferenceDescriptor(nextObject.getClass(), uow).getObjectBuilder(); builder.cascadeDiscoverAndPersistUnregisteredNewObjects(nextObject, newObjects, unregisteredExistingObjects, visitedObjects, uow); } } }
wasCacheUsed[0] = Boolean.TRUE; Object attributeValue = this.getAttributeValueFromObject(cached); Integer refreshCascade = null; if (sourceQuery != null && sourceQuery.isObjectBuildingQuery() && sourceQuery.shouldRefreshIdentityMapResult()) { refreshCascade = sourceQuery.getCascadePolicy(); return buildClonePart(cached, null, cacheKey, attributeValue, refreshCascade, executionSession); return getAttributeValueFromObject(row.getSopObject()); ContainerPolicy cp = this.getContainerPolicy(); Object fieldValue = row.getValues(this.getField()); Vector nestedRows = this.getReferenceDescriptor().buildNestedRowsFromFieldValue(fieldValue, executionSession); if (nestedRows == null) { return cp.containerInstance(); ClassDescriptor descriptor = this.getReferenceDescriptor(); if (descriptor.hasInheritance()) { Class newElementClass = descriptor.getInheritancePolicy().classFromRow(nestedRow, executionSession); descriptor = this.getReferenceDescriptor(newElementClass, executionSession); Object element = buildCompositeObject(descriptor, nestedRow, sourceQuery, cacheKey, joinManager, executionSession); if (hasConverter()) { element = getConverter().convertDataValueToObjectValue(element, executionSession);
ContainerPolicy cp = this.getContainerPolicy(); Object fieldValue = row.getValues(this.getField()); Vector nestedRows = this.getReferenceDescriptor().buildNestedRowsFromFieldValue(fieldValue, executionSession); if (nestedRows == null) { return cp.containerInstance(); AbstractRecord nestedRow = (AbstractRecord)stream.nextElement(); ClassDescriptor descriptor = this.getReferenceDescriptor(); if (descriptor.hasInheritance()) { Class newElementClass = descriptor.getInheritancePolicy().classFromRow(nestedRow, executionSession); descriptor = this.getReferenceDescriptor(newElementClass, executionSession); Object element = buildCompositeObject(descriptor, nestedRow, sourceQuery, joinManager); if (hasConverter()) { element = getConverter().convertDataValueToObjectValue(element, executionSession);
if (session.isClassReadOnly(this.getReferenceClass())) { return null; cloneAttribute = getAttributeValueFromObject(clone); backUpAttribute = getAttributeValueFromObject(backup); if ((backUpAttribute == null) && (cloneAttribute == null)) { return null; ContainerPolicy cp = getContainerPolicy(); Object backupCollection = null; Object cloneCollection = null; cloneCollection = getRealCollectionAttributeValueFromObject(clone, session); backupCollection = getRealCollectionAttributeValueFromObject(backup, session); return convertToChangeRecord(cloneCollection, owner, session); ObjectBuilder builder = getReferenceDescriptor(cloneObject.getClass(), session).getObjectBuilder(); ObjectChangeSet initialChanges = builder.createObjectChangeSet(cloneObject, uowComparisonChangeSet, owner.isNew(), session); return convertToChangeRecord(cloneCollection, owner, session); } else { return null; return convertToChangeRecord(getRealCollectionAttributeValueFromObject(clone, session), owner, session);
/** * An object has been serialized from the server to the remote client. * Replace the transient attributes of the remote value holders * with client-side objects. */ @Override protected void fixAttributeValue(Object attributeValue, Map objectDescriptors, Map processedObjects, ObjectLevelReadQuery query, DistributedSession session) { if (attributeValue == null) { return; } ContainerPolicy cp = this.getContainerPolicy(); for (Object iter = cp.iteratorFor(attributeValue); cp.hasNext(iter);) { super.fixAttributeValue(cp.next(iter, session), objectDescriptors, processedObjects, query, session); } }
protected ChangeRecord convertToChangeRecord(Object cloneCollection, ObjectChangeSet owner, AbstractSession session) { ContainerPolicy cp = getContainerPolicy(); Object cloneIter = cp.iteratorFor(cloneCollection); Vector collectionChanges = new Vector(2); while (cp.hasNext(cloneIter)) { Object aggregateObject = cp.next(cloneIter, session); // For CR#2258 quietly ignore nulls inserted into a collection. if (aggregateObject != null) { ObjectChangeSet changes = getReferenceDescriptor(aggregateObject.getClass(), session).getObjectBuilder().compareForChange(aggregateObject, null, (UnitOfWorkChangeSet)owner.getUOWChangeSet(), session); collectionChanges.addElement(changes); } } //cr 3013 Removed if collection is empty return null block, which prevents recording clear() change AggregateCollectionChangeRecord changeRecord = new AggregateCollectionChangeRecord(owner); changeRecord.setAttribute(getAttributeName()); changeRecord.setMapping(this); changeRecord.setChangedValues(collectionChanges); return changeRecord; }
/** * INTERNAL: * Get the attribute value from the object and add the changed * values to the specified database row. */ public void writeFromObjectIntoRowForUpdate(WriteObjectQuery writeQuery, AbstractRecord row) throws DescriptorException { AbstractSession session = writeQuery.getSession(); //Helper.toDo("bjv: need to figure out how to handle read-only elements..."); if (session.isClassReadOnly(this.getReferenceClass())) { return; } if (session.isUnitOfWork()) { if (this.compareObjects(writeQuery.getObject(), writeQuery.getBackupClone(), session)) { return;// nothing has changed - don't put anything in the row } } this.writeFromObjectIntoRow(writeQuery.getObject(), row, session); }
/** * 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) { if (!mergeManager.shouldCascadeReferences()) { // This is only going to happen on mergeClone, and we should not attempt to merge the reference return; } ContainerPolicy containerPolicy = getContainerPolicy(); Object valueOfSource = getRealCollectionAttributeValueFromObject(source, mergeManager.getSession()); Object valueOfTarget = containerPolicy.containerInstance(containerPolicy.sizeFor(valueOfSource)); for (Object sourceValuesIterator = containerPolicy.iteratorFor(valueOfSource); containerPolicy.hasNext(sourceValuesIterator);) { Object sourceValue = containerPolicy.next(sourceValuesIterator, mergeManager.getSession()); //CR#2896 - TW Object originalValue = getReferenceDescriptor(sourceValue.getClass(), mergeManager.getSession()).getObjectBuilder().buildNewInstance(); getReferenceDescriptor(sourceValue.getClass(), mergeManager.getSession()).getObjectBuilder().mergeIntoObject(originalValue, true, sourceValue, mergeManager); containerPolicy.addInto(originalValue, valueOfTarget, mergeManager.getSession()); } // Must re-set variable to allow for set method to re-morph changes if the collection is not being stored directly. setRealAttributeValueInObject(target, valueOfTarget); }
/** * INTERNAL: * Compare the attributes belonging to this mapping for the objects. */ public boolean compareObjects(Object object1, Object object2, AbstractSession session) { Object firstCollection = getRealCollectionAttributeValueFromObject(object1, session); Object secondCollection = getRealCollectionAttributeValueFromObject(object2, session); ContainerPolicy containerPolicy = getContainerPolicy(); if (containerPolicy.sizeFor(firstCollection) != containerPolicy.sizeFor(secondCollection)) { return false; } if (containerPolicy.sizeFor(firstCollection) == 0) { return true; } Object iterFirst = containerPolicy.iteratorFor(firstCollection); Object iterSecond = containerPolicy.iteratorFor(secondCollection); //loop through the elements in both collections and compare elements at the //same index. This ensures that a change to order registers as a change. while (containerPolicy.hasNext(iterFirst)) { //fetch the next object from the first iterator. Object firstAggregateObject = containerPolicy.next(iterFirst, session); Object secondAggregateObject = containerPolicy.next(iterSecond, session); //fetch the next object from the second iterator. //matched object found, break to outer FOR loop if (!getReferenceDescriptor().getObjectBuilder().compareObjects(firstAggregateObject, secondAggregateObject, session)) { return false; } } return true; }
/** * 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. PLEASE ENSURE that the changes * have been made in the object model first. */ public void simpleRemoveFromCollectionChangeRecord(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) { AggregateCollectionChangeRecord collectionChangeRecord = (AggregateCollectionChangeRecord)changeSet.getChangesForAttributeNamed(this.getAttributeName()); if (collectionChangeRecord == null) { //if there is no change for this attribute then create a changeSet for it. no need to modify the resulting // change record as it should be built from the clone which has the changes allready Object cloneObject = ((UnitOfWorkChangeSet)changeSet.getUOWChangeSet()).getUOWCloneForObjectChangeSet(changeSet); Object cloneCollection = this.getRealAttributeValueFromObject(cloneObject, session); collectionChangeRecord = (AggregateCollectionChangeRecord)convertToChangeRecord(cloneCollection, changeSet, session); changeSet.addChange(collectionChangeRecord); } else { collectionChangeRecord.getChangedValues().remove(changeSetToRemove); } }
/** * INTERNAL: * Merge changes from the source to the target object. */ public void mergeChangesIntoObject(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager) { ContainerPolicy containerPolicy = getContainerPolicy(); AbstractSession session = mergeManager.getSession(); // Iterate over the changes and merge the collections Vector aggregateObjects = ((AggregateCollectionChangeRecord)changeRecord).getChangedValues(); Object valueOfTarget = containerPolicy.containerInstance(); // Next iterate over the changes and add them to the container ObjectChangeSet objectChanges = null; int size = aggregateObjects.size(); for (int index = 0; index < size; ++index) { objectChanges = (ObjectChangeSet)aggregateObjects.get(index); // Since the CompositeCollectionMapping only registers an all or none // change set, we can simply replace the entire collection; containerPolicy.addInto(buildElementFromChangeSet(objectChanges, mergeManager), valueOfTarget, session); } setRealAttributeValueInObject(target, valueOfTarget); }
/** * Return the fields handled by the mapping. */ @Override protected Vector collectFields() { Vector fields = new Vector(1); fields.addElement(this.getField()); return fields; }
/** * INTERNAL: * Compare the non-null elements and return true if they are alike. */ public boolean compareElementsForChange(Object element1, Object element2, AbstractSession session) { return this.compareElements(element1, element2, session); }
/** * INTERNAL: * Cascade discover and persist new objects during commit. */ @Override public void cascadeDiscoverAndPersistUnregisteredNewObjects(Object object, Map newObjects, Map unregisteredExistingObjects, Map visitedObjects, UnitOfWorkImpl uow, Set cascadeErrors) { Object cloneAttribute = getAttributeValueFromObject(object); if (cloneAttribute == null ) { return; } ContainerPolicy containerPolicy = getContainerPolicy(); Object cloneObjectCollection = getRealCollectionAttributeValueFromObject(object, uow); Object iterator = containerPolicy.iteratorFor(cloneObjectCollection); while (containerPolicy.hasNext(iterator)) { Object nextObject = containerPolicy.next(iterator, uow); if (nextObject != null) { ObjectBuilder builder = getReferenceDescriptor(nextObject.getClass(), uow).getObjectBuilder(); builder.cascadeDiscoverAndPersistUnregisteredNewObjects(nextObject, newObjects, unregisteredExistingObjects, visitedObjects, uow, cascadeErrors); } } }
wasCacheUsed[0] = Boolean.TRUE; Object attributeValue = this.getAttributeValueFromObject(cached); Integer refreshCascade = null; if (sourceQuery != null && sourceQuery.isObjectBuildingQuery() && sourceQuery.shouldRefreshIdentityMapResult()) { refreshCascade = sourceQuery.getCascadePolicy(); return buildClonePart(cached, null, cacheKey, attributeValue, refreshCascade, executionSession); return getAttributeValueFromObject(row.getSopObject()); ContainerPolicy cp = this.getContainerPolicy(); Object fieldValue = row.getValues(this.getField()); Vector nestedRows = this.getReferenceDescriptor().buildNestedRowsFromFieldValue(fieldValue, executionSession); if (nestedRows == null) { return cp.containerInstance(); ClassDescriptor descriptor = this.getReferenceDescriptor(); if (descriptor.hasInheritance()) { Class newElementClass = descriptor.getInheritancePolicy().classFromRow(nestedRow, executionSession); descriptor = this.getReferenceDescriptor(newElementClass, executionSession); Object element = buildCompositeObject(descriptor, nestedRow, sourceQuery, cacheKey, joinManager, executionSession); if (hasConverter()) { element = getConverter().convertDataValueToObjectValue(element, executionSession);