Search in sources :

Example 1 with ContainerMapping

use of org.eclipse.persistence.mappings.ContainerMapping in project eclipselink by eclipse-ee4j.

the class JAXBValueStore method unsetDeclaredProperty.

/**
 * For isMany=false properties set the value to null. For isMany=true set
 * the value to an empty container of the appropriate type.
 */
@Override
public void unsetDeclaredProperty(int propertyIndex) {
    SDOProperty declaredProperty = (SDOProperty) dataObject.getType().getDeclaredProperties().get(propertyIndex);
    Mapping mapping = this.getJAXBMappingForProperty(declaredProperty);
    if (declaredProperty.isMany()) {
        ContainerMapping containerMapping = (ContainerMapping) mapping;
        ContainerPolicy containerPolicy = containerMapping.getContainerPolicy();
        // OLD VALUE
        if (mapping.isAbstractCompositeCollectionMapping()) {
            XMLCompositeCollectionMapping compositeMapping = (XMLCompositeCollectionMapping) mapping;
            XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
            if (inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
                Object oldContainer = mapping.getAttributeValueFromObject(entity);
                if (oldContainer != null) {
                    AbstractSession session = ((JAXBContext) jaxbHelperContext.getJAXBContext()).getXMLContext().getSession(entity);
                    Object iterator = containerPolicy.iteratorFor(oldContainer);
                    while (containerPolicy.hasNext(iterator)) {
                        Object oldValue = containerPolicy.next(iterator, session);
                        inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(oldValue, null);
                    }
                }
            }
        }
        // NEW VALUE
        Object container = containerPolicy.containerInstance();
        mapping.getAttributeAccessor().setAttributeValueInObject(entity, container);
    } else {
        // OLD VALUE
        Object oldValue = mapping.getAttributeAccessor().getAttributeValueFromObject(entity);
        if (mapping.isAbstractCompositeObjectMapping()) {
            XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) mapping;
            final XMLInverseReferenceMapping inverseReferenceMapping = compositeMapping.getInverseReferenceMapping();
            if (inverseReferenceMapping != null && inverseReferenceMapping.getAttributeAccessor() != null) {
                if (oldValue != null) {
                    inverseReferenceMapping.getAttributeAccessor().setAttributeValueInObject(oldValue, null);
                }
            }
        }
        // NEW VALUE
        mapping.getAttributeAccessor().setAttributeValueInObject(entity, null);
    }
}
Also used : CoreContainerPolicy(org.eclipse.persistence.internal.core.queries.CoreContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) ContainerMapping(org.eclipse.persistence.mappings.ContainerMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ContainerMapping(org.eclipse.persistence.mappings.ContainerMapping) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Aggregations

DataObject (commonj.sdo.DataObject)1 CoreContainerPolicy (org.eclipse.persistence.internal.core.queries.CoreContainerPolicy)1 Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)1 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 ContainerMapping (org.eclipse.persistence.mappings.ContainerMapping)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)1 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)1 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)1 XMLInverseReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping)1 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)1 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)1 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)1