Search in sources :

Example 41 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class XMLCompositeDirectCollectionMapping method valueFromRow.

/**
 * INTERNAL:
 * Build the nested collection from the database row.
 */
@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
    ContainerPolicy cp = this.getContainerPolicy();
    DOMRecord domRecord = (DOMRecord) row;
    Object fieldValue = domRecord.getValues(this.getField(), this.getNullPolicy());
    if (fieldValue == null) {
        if (reuseContainer) {
            Object currentObject = ((XMLRecord) row).getCurrentObject();
            Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
            return container != null ? container : cp.containerInstance();
        } else {
            return cp.containerInstance();
        }
    }
    Vector fieldValues = this.getDescriptor().buildDirectValuesFromFieldValue(fieldValue);
    if (fieldValues == null) {
        if (reuseContainer) {
            Object currentObject = ((XMLRecord) row).getCurrentObject();
            Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
            return container != null ? container : cp.containerInstance();
        } else {
            return cp.containerInstance();
        }
    }
    Object result = null;
    if (reuseContainer) {
        Object currentObject = ((XMLRecord) row).getCurrentObject();
        Object container = getAttributeAccessor().getAttributeValueFromObject(currentObject);
        result = container != null ? container : cp.containerInstance();
    } else {
        result = cp.containerInstance(fieldValues.size());
    }
    for (Enumeration stream = fieldValues.elements(); stream.hasMoreElements(); ) {
        Object element = stream.nextElement();
        element = convertDataValueToObjectValue(element, executionSession, ((XMLRecord) row).getUnmarshaller());
        if (element != null && element.getClass() == ClassConstants.STRING) {
            if (isCollapsingStringValues) {
                element = XMLConversionManager.getDefaultXMLManager().collapseStringValue((String) element);
            } else if (isNormalizingStringValues) {
                element = XMLConversionManager.getDefaultXMLManager().normalizeStringValue((String) element);
            }
        }
        cp.addInto(element, result, sourceQuery.getSession());
    }
    return result;
}
Also used : CollectionContainerPolicy(org.eclipse.persistence.internal.queries.CollectionContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) Enumeration(java.util.Enumeration) DOMRecord(org.eclipse.persistence.oxm.record.DOMRecord) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) Vector(java.util.Vector)

Example 42 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class XMLCompositeDirectCollectionMapping method writeFromObjectIntoRow.

/**
 * INTERNAL:
 */
@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) {
    if (this.isReadOnly()) {
        return;
    }
    Object attributeValue = this.getAttributeValueFromObject(object);
    if (attributeValue == null) {
        row.put(this.getField(), null);
        return;
    }
    ContainerPolicy cp = this.getContainerPolicy();
    Vector elements = new Vector(cp.sizeFor(attributeValue));
    Object iter = cp.iteratorFor(attributeValue);
    if (null != iter) {
        while (cp.hasNext(iter)) {
            Object element = cp.next(iter, session);
            element = convertObjectValueToDataValue(element, session, ((XMLRecord) row).getMarshaller());
            if (element != null) {
                elements.addElement(element);
            } else if (!usesSingleNode()) {
                AbstractNullPolicy nullPolicy = getNullPolicy();
                if (nullPolicy == null) {
                    elements.addElement(null);
                } else {
                    if (nullPolicy.getMarshalNullRepresentation() == XMLNullRepresentationType.XSI_NIL) {
                        elements.addElement(XMLRecord.NIL);
                    } else if (nullPolicy.getMarshalNullRepresentation() == XMLNullRepresentationType.ABSENT_NODE) {
                    // Do nothing
                    } else {
                        elements.addElement(XMLConstants.EMPTY_STRING);
                    }
                }
            }
        }
    }
    Object fieldValue = null;
    if (!elements.isEmpty()) {
        fieldValue = this.getDescriptor().buildFieldValueFromDirectValues(elements, elementDataTypeName, session);
    }
    row.put(this.getField(), fieldValue);
}
Also used : AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) CollectionContainerPolicy(org.eclipse.persistence.internal.queries.CollectionContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) Vector(java.util.Vector) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 43 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class XMLCompositeDirectCollectionMapping method initialize.

/**
 * INTERNAL:
 * Initialize the mapping.
 */
@Override
public void initialize(AbstractSession session) throws DescriptorException {
    super.initialize(session);
    if (this.getField() instanceof XMLField) {
        if (valueConverter instanceof TypeConversionConverter) {
            TypeConversionConverter converter = (TypeConversionConverter) valueConverter;
            this.getField().setType(converter.getObjectClass());
        }
        String xpathString = ((XMLField) getField()).getXPath();
        if (this.isAbstractCompositeDirectCollectionMapping() && (xpathString.indexOf(XMLConstants.ATTRIBUTE) == -1) && (!xpathString.endsWith(XMLConstants.TEXT))) {
            throw DescriptorException.invalidXpathForXMLDirectMapping(this);
        }
    }
    ContainerPolicy cp = getContainerPolicy();
    if (cp != null) {
        if (cp.getContainerClass() == null) {
            Class<Object> cls = session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(cp.getContainerClassName());
            cp.setContainerClass(cls);
        }
    }
    ((XMLField) this.getField()).setIsCDATA(this.isCDATA());
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) CollectionContainerPolicy(org.eclipse.persistence.internal.queries.CollectionContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy)

Example 44 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class XMLFragmentCollectionMapping method writeFromObjectIntoRow.

/**
 * INTERNAL:
 */
@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) {
    if (this.isReadOnly()) {
        return;
    }
    Object attributeValue = this.getAttributeValueFromObject(object);
    if (attributeValue == null) {
        row.put(this.getField(), null);
        return;
    }
    ContainerPolicy cp = this.getContainerPolicy();
    Vector elements = new Vector(cp.sizeFor(attributeValue));
    for (Object iter = cp.iteratorFor(attributeValue); cp.hasNext(iter); ) {
        Object element = cp.next(iter, session);
        if (element != null) {
            elements.addElement(element);
        }
    }
    Object fieldValue = null;
    if (!elements.isEmpty()) {
        fieldValue = this.getDescriptor().buildFieldValueFromDirectValues(elements, elementDataTypeName, session);
    }
    row.put(this.getField(), fieldValue);
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) Vector(java.util.Vector)

Example 45 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class XMLAnyAttributeMapping method initialize.

@Override
public void initialize(AbstractSession session) throws DescriptorException {
    if (getField() != null) {
        setField(getDescriptor().buildField(getField()));
    }
    ContainerPolicy cp = getContainerPolicy();
    if (cp != null && cp.getContainerClass() == null) {
        Class<Object> cls = session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(cp.getContainerClassName());
        cp.setContainerClass(cls);
    }
}
Also used : MappedKeyMapContainerPolicy(org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy)

Aggregations

ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)119 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)28 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)17 XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)17 List (java.util.List)14 Vector (java.util.Vector)14 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)14 XMLField (org.eclipse.persistence.oxm.XMLField)14 ArrayList (java.util.ArrayList)13 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)13 Collection (java.util.Collection)12 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)10 CollectionContainerPolicy (org.eclipse.persistence.internal.queries.CollectionContainerPolicy)9 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)8 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)8 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)8 HashMap (java.util.HashMap)7 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)7 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)7 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)7