/** * 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: * 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: * 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: * Copy of the attribute of the object. * This is NOT used for unit of work but for templatizing an object. */ @Override public void buildCopy(Object copy, Object original, CopyGroup group) { Object attributeValue = getAttributeValueFromObject(original); if (attributeValue == null) { attributeValue = getContainerPolicy().containerInstance(); } else { attributeValue = getContainerPolicy().cloneFor(attributeValue); } setAttributeValueInObject(copy, attributeValue); }
/** * INTERNAL: * Copy of the attribute of the object. * This is NOT used for unit of work but for templatizing an object. */ public void buildCopy(Object copy, Object original, ObjectCopyingPolicy policy) { Object attributeValue = getAttributeValueFromObject(original); if (attributeValue == null) { attributeValue = getContainerPolicy().containerInstance(); } else { attributeValue = getContainerPolicy().cloneFor(attributeValue); } setAttributeValueInObject(copy, attributeValue); }
/** * INTERNAL: * Copy of the attribute of the object. * This is NOT used for unit of work but for templatizing an object. */ @Override public void buildCopy(Object copy, Object original, CopyGroup group) { Object attributeValue = getAttributeValueFromObject(original); if (attributeValue == null) { attributeValue = getContainerPolicy().containerInstance(); } else { attributeValue = getContainerPolicy().cloneFor(attributeValue); } setAttributeValueInObject(copy, attributeValue); }
/** * Build and return a clone of the specified attribute value. */ protected Object buildClonePart(Object attributeValue, CacheKey parentCacheKey, AbstractSession cloningSession) { if (attributeValue == null) { return this.getContainerPolicy().containerInstance(); } else { if ((getValueConverter() == null) || (!getValueConverter().isMutable())) { return this.getContainerPolicy().cloneFor(attributeValue); } // Clone the values of the collection as well. Object cloneContainer = this.getContainerPolicy().containerInstance(); Object iterator = this.getContainerPolicy().iteratorFor(attributeValue); while (this.getContainerPolicy().hasNext(iterator)) { Object originalValue = this.getContainerPolicy().next(iterator, cloningSession); // Bug 4182377 - there was a typo in the conversion logic Object cloneValue = getValueConverter().convertDataValueToObjectValue(getValueConverter().convertObjectValueToDataValue(originalValue, cloningSession), cloningSession); this.getContainerPolicy().addInto(cloneValue, cloneContainer, cloningSession); } return cloneContainer; } }
/** * Build and return a clone of the specified attribute value. */ protected Object buildClonePart(Object attributeValue, UnitOfWorkImpl unitOfWork) { if (attributeValue == null) { return this.getContainerPolicy().containerInstance(); } else { if ((getValueConverter() == null) || (!getValueConverter().isMutable())) { return this.getContainerPolicy().cloneFor(attributeValue); } // Clone the values of the collection as well. Object cloneContainer = this.getContainerPolicy().containerInstance(); Object iterator = this.getContainerPolicy().iteratorFor(attributeValue); while (this.getContainerPolicy().hasNext(iterator)) { Object originalValue = this.getContainerPolicy().next(iterator, unitOfWork); // Bug 4182377 - there was a typo in the conversion logic Object cloneValue = getValueConverter().convertDataValueToObjectValue(getValueConverter().convertObjectValueToDataValue(originalValue, unitOfWork), unitOfWork); this.getContainerPolicy().addInto(cloneValue, cloneContainer, unitOfWork); } return cloneContainer; } }
/** * Build and return a clone of the specified attribute value. */ protected Object buildClonePart(Object attributeValue, CacheKey parentCacheKey, AbstractSession cloningSession) { if (attributeValue == null) { return this.getContainerPolicy().containerInstance(); } else { if ((getValueConverter() == null) || (!getValueConverter().isMutable())) { return this.getContainerPolicy().cloneFor(attributeValue); } // Clone the values of the collection as well. Object cloneContainer = this.getContainerPolicy().containerInstance(); Object iterator = this.getContainerPolicy().iteratorFor(attributeValue); while (this.getContainerPolicy().hasNext(iterator)) { Object originalValue = this.getContainerPolicy().next(iterator, cloningSession); // Bug 4182377 - there was a typo in the conversion logic Object cloneValue = getValueConverter().convertDataValueToObjectValue(getValueConverter().convertObjectValueToDataValue(originalValue, cloningSession), cloningSession); this.getContainerPolicy().addInto(cloneValue, cloneContainer, cloningSession); } return cloneContainer; } }
/** * INTERNAL: * Build the nested collection from the database row. */ public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, AbstractSession executionSession) throws DatabaseException { ContainerPolicy cp = this.getContainerPolicy(); Object fieldValue = row.getValues(this.getField()); if (fieldValue == null) { return cp.containerInstance(); } Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue); if (fieldValues == null) { return cp.containerInstance(); } Object result = cp.containerInstance(fieldValues.size()); for (Enumeration stream = fieldValues.elements(); stream.hasMoreElements();) { Object element = stream.nextElement(); if (this.getValueConverter() != null) { element = getValueConverter().convertDataValueToObjectValue(element, executionSession); } cp.addInto(element, result, sourceQuery.getSession()); } return result; }
/** * 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) { DirectToFieldChangeRecord collectionChangeRecord = (DirectToFieldChangeRecord)changeSet.getAttributesToChanges().get(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 = (DirectToFieldChangeRecord)convertToChangeRecord(cloneCollection, changeSet, session); changeSet.addChange(collectionChangeRecord); } else { getContainerPolicy().removeFrom(changeSetToRemove, collectionChangeRecord.getNewValue(), 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. */ public void simpleAddToCollectionChangeRecord(Object referenceKey, Object changeSetToAdd, ObjectChangeSet changeSet, AbstractSession session) { DirectToFieldChangeRecord collectionChangeRecord = (DirectToFieldChangeRecord)changeSet.getAttributesToChanges().get(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 = (DirectToFieldChangeRecord)convertToChangeRecord(cloneCollection, changeSet, session); changeSet.addChange(collectionChangeRecord); } else { getContainerPolicy().addInto(changeSetToAdd, collectionChangeRecord.getNewValue(), session); } }
/** * INTERNAL: * Iterate on the appropriate attribute value. */ public void iterate(DescriptorIterator iterator) { // PERF: Only iterate when required. if (iterator.shouldIterateOnPrimitives()) { Object attributeValue = this.getAttributeValueFromObject(iterator.getVisitedParent()); if (attributeValue == null) { return; } ContainerPolicy cp = this.getContainerPolicy(); for (Object iter = cp.iteratorFor(attributeValue); cp.hasNext(iter);) { iterator.iteratePrimitiveForMapping(cp.next(iter, iterator.getSession()), this); } } }
/** * INTERNAL: * Iterate on the appropriate attribute value. */ public void iterate(DescriptorIterator iterator) { // PERF: Only iterate when required. if (iterator.shouldIterateOnPrimitives()) { Object attributeValue = this.getAttributeValueFromObject(iterator.getVisitedParent()); if (attributeValue == null) { return; } ContainerPolicy cp = this.getContainerPolicy(); for (Object iter = cp.iteratorFor(attributeValue); cp.hasNext(iter);) { iterator.iteratePrimitiveForMapping(cp.next(iter, iterator.getSession()), this); } } }
/** * INTERNAL: * Iterate on the appropriate attribute value. */ public void iterate(DescriptorIterator iterator) { // PERF: Only iterate when required. if (iterator.shouldIterateOnPrimitives()) { Object attributeValue = this.getAttributeValueFromObject(iterator.getVisitedParent()); if (attributeValue == null) { return; } ContainerPolicy cp = this.getContainerPolicy(); for (Object iter = cp.iteratorFor(attributeValue); cp.hasNext(iter);) { iterator.iteratePrimitiveForMapping(cp.next(iter, iterator.getSession()), this); } } }
/** * INTERNAL: * Merge changes from the source to the target object. This merge is only called when a changeSet for the target * does not exist or the target is uninitialized. * Treat the collection as a simple direct value. */ public void mergeIntoObject(Object target, boolean isTargetUnInitialized, Object source, MergeManager mergeManager) { Object attributeValue = getAttributeValueFromObject(source); ContainerPolicy cp = this.getContainerPolicy(); Object container = cp.containerInstance(); Object iter = cp.iteratorFor(attributeValue); while (cp.hasNext(iter)) { cp.addInto(cp.next(iter, mergeManager.getSession()), container, mergeManager.getSession()); } setAttributeValueInObject(target, container); }
protected ChangeRecord convertToChangeRecord(Object cloneCollection, ObjectChangeSet owner, AbstractSession session) { //since a minimal update for composites can't be done, we are only recording //an all-or-none change. Therefore, this can be treated as a simple direct //value. ContainerPolicy cp = this.getContainerPolicy(); Object container = cp.containerInstance(); Object iter = cp.iteratorFor(cloneCollection); while (cp.hasNext(iter)) { cp.addInto(cp.next(iter, session), container, session); } DirectToFieldChangeRecord changeRecord = new DirectToFieldChangeRecord(owner); changeRecord.setAttribute(getAttributeName()); changeRecord.setMapping(this); changeRecord.setNewValue(container); return changeRecord; }
protected ChangeRecord convertToChangeRecord(Object cloneCollection, ObjectChangeSet owner, AbstractSession session) { //since a minimal update for composites can't be done, we are only recording //an all-or-none change. Therefore, this can be treated as a simple direct //value. ContainerPolicy cp = this.getContainerPolicy(); Object container = cp.containerInstance(); Object iter = cp.iteratorFor(cloneCollection); while (cp.hasNext(iter)) { cp.addInto(cp.next(iter, session), container, session); } DirectToFieldChangeRecord changeRecord = new DirectToFieldChangeRecord(owner); changeRecord.setAttribute(getAttributeName()); changeRecord.setMapping(this); changeRecord.setNewValue(container); return changeRecord; }
protected ChangeRecord convertToChangeRecord(Object cloneCollection, ObjectChangeSet owner, AbstractSession session) { //since a minimal update for composites can't be done, we are only recording //an all-or-none change. Therefore, this can be treated as a simple direct //value. ContainerPolicy cp = this.getContainerPolicy(); Object container = cp.containerInstance(); Object iter = cp.iteratorFor(cloneCollection); while (cp.hasNext(iter)) { cp.addInto(cp.next(iter, session), container, session); } DirectToFieldChangeRecord changeRecord = new DirectToFieldChangeRecord(owner); changeRecord.setAttribute(getAttributeName()); changeRecord.setMapping(this); changeRecord.setNewValue(container); return changeRecord; }
/** * INTERNAL: * Merge changes from the source to the target object. Treat the collection as a * simple direct value, since minimal update isn't possible. */ public void mergeChangesIntoObject(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager) { if (changeRecord == null) {// I have not calculated changes then simply merge value into target Object targetValue = getRealAttributeValueFromObject(source, mergeManager.getSession()); ContainerPolicy cp = this.getContainerPolicy(); Object container = cp.containerInstance(); Object iter = cp.iteratorFor(targetValue); while (cp.hasNext(iter)) { cp.addInto(cp.next(iter, mergeManager.getSession()), container, mergeManager.getSession()); } setAttributeValueInObject(target, container); } else { setAttributeValueInObject(target, ((DirectToFieldChangeRecord)changeRecord).getNewValue()); } }