private void addChoiceElementMapping(XMLField sourceField, String className, XMLField targetField) { XMLCollectionReferenceMapping mapping = new XMLCollectionReferenceMapping(); mapping.setReferenceClassName(className); mapping.setAttributeAccessor(temporaryAccessor); mapping.addSourceToTargetKeyFieldAssociation(sourceField, targetField); this.choiceElementMappings.put(sourceField, mapping); this.choiceElementMappingsByClassName.put(className, mapping); }
public void writeSingleValue(Object value, Object parent, XMLRecord row, AbstractSession session) { for (Iterator fieldIt = getFields().iterator(); fieldIt.hasNext();) { XMLField xmlField = (XMLField) fieldIt.next(); Object fieldValue = buildFieldValue(value, xmlField, session); if (fieldValue != null) { QName schemaType = getSchemaType(xmlField, fieldValue, session); String stringValue = getValueToWrite(schemaType, fieldValue, session); row.add(xmlField, stringValue); } } }
/** * INTERNAL: * Extract the primary key values from the row, then create an * org.eclipse.persistence.internal.oxm.Reference instance and stored it * on the session's org.eclipse.persistence.internal.oxm.ReferenceResolver. */ public Object readFromRowIntoObject(AbstractRecord databaseRow, JoinedAttributeManager joinManager, Object targetObject, CacheKey parentCacheKey, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException { ContainerPolicy cp = getContainerPolicy(); Object container = null; if (reuseContainer) { Object currentObject = ((XMLRecord) databaseRow).getCurrentObject(); container = getAttributeAccessor().getAttributeValueFromObject(currentObject); } if(container == null){ container = cp.containerInstance(); } return readFromRowIntoObject(databaseRow, joinManager, targetObject, parentCacheKey, sourceQuery, executionSession, isTargetProtected, container); }
private void addChoiceElementMapping(XMLField sourceField, Class theClass, XMLField targetField) { XMLCollectionReferenceMapping mapping = new XMLCollectionReferenceMapping(); mapping.setReferenceClass(theClass); mapping.setAttributeAccessor(temporaryAccessor); mapping.addSourceToTargetKeyFieldAssociation(sourceField, targetField); this.choiceElementMappings.put(sourceField, mapping); this.choiceElementMappingsByClass.put(theClass, mapping); }
@Override public boolean isMarshalNodeValue() { return xmlCollectionReferenceMapping.getFields().size() == 1 || xmlCollectionReferenceMapping.usesSingleNode(); }
if(this.isReadOnly()) { return; for (Iterator fieldIt = getFields().iterator(); fieldIt.hasNext();) { XMLField xmlField = (XMLField) fieldIt.next(); ContainerPolicy cp = getContainerPolicy(); Object collection = getAttributeAccessor().getAttributeValueFromObject(object); if (collection == null) { return; QName schemaType; Object iterator = cp.iteratorFor(collection); if (usesSingleNode()) { while (cp.hasNext(iterator)) { objectValue = cp.next(iterator, session); fieldValue = buildFieldValue(objectValue, xmlField, session); if (fieldValue != null) { schemaType = getSchemaType(xmlField, fieldValue, session); String newValue = getValueToWrite(schemaType, fieldValue, session); if (newValue != null) { stringValueBuilder.append(newValue); while (cp.hasNext(iterator)) { objectValue = cp.next(iterator, session); fieldValue = buildFieldValue(objectValue, xmlField, session); if (fieldValue != null) { schemaType = getSchemaType(xmlField, fieldValue, session); String stringValue = getValueToWrite(schemaType, fieldValue, session);
private DatabaseMapping buildXMLCollectionReferenceMapping(String mappingUri) { XMLCollectionReferenceMapping mapping = new XMLCollectionReferenceMapping(); mapping.setAttributeName(getName()); if (getType().isDataObjectType()) { getType().setImplClassName(SDOConstants.SDO_DATA_OBJECT_IMPL_CLASS_NAME); } mapping.setReferenceClassName(getType().getImplClassName()); mapping.setReferenceClass(getType().getImplClass()); mapping.setUsesSingleNode(true); mapping.useCollectionClass(ArrayList.class); String sourcexpath = getQualifiedXPath(getContainingType().getURI(), true); // Get reference ID property if it exists SDOProperty targetIDProp = getIDProp(getType()); if (targetIDProp != null) { String targetxpath = targetIDProp.getQualifiedXPath(getType().getURI(), true); mapping.addSourceToTargetKeyFieldAssociation(sourcexpath, targetxpath); } else { throw SDOException.noTargetIdSpecified(getType().getURI(), getType().getName()); } return mapping; }
/** * INTERNAL: * The mapping is initialized with the given session. This mapping is fully initialized * after this. */ public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); if(null != getField()) { setField(getDescriptor().buildField(getField())); } ContainerPolicy cp = getContainerPolicy(); if (cp != null) { if (cp.getContainerClass() == null) { Class cls = session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(cp.getContainerClassName()); cp.setContainerClass(cls); } } }
/** * INTERNAL: * Extract the primary key values from the row, then create an * org.eclipse.persistence.internal.oxm.Reference instance and stored it * on the session's org.eclipse.persistence.internal.oxm.ReferenceResolver. */ public Object readFromRowIntoObject(AbstractRecord databaseRow, JoinedAttributeManager joinManager, Object targetObject, CacheKey parentCacheKey, ObjectBuildingQuery sourceQuery, AbstractSession executionSession, boolean isTargetProtected, Object container) throws DatabaseException { ClassDescriptor descriptor = sourceQuery.getSession().getClassDescriptor(getReferenceClass()); if(container == null){ readFromRowIntoObject(databaseRow, joinManager, targetObject, parentCacheKey, sourceQuery, executionSession, isTargetProtected); } // for each source xmlField, get the value from the row and store for (Iterator fieldIt = getFields().iterator(); fieldIt.hasNext();) { XMLField fld = (XMLField) fieldIt.next(); // Object fieldValue = databaseRow.getValues(fld); if ((fieldValue == null) || (fieldValue instanceof String) || !(fieldValue instanceof Vector)) { return container; } // fix for bug# 5687430 // need to get the actual type of the target (i.e. int, String, etc.) // and use the converted value when checking the cache. for (Iterator valIt = ((Vector) fieldValue).iterator(); valIt.hasNext();) { Object nextValue = valIt.next(); DOMRecord domRecord = (DOMRecord) databaseRow; this.buildReference(domRecord.getCurrentObject(), fld, nextValue, sourceQuery.getSession(), container, domRecord.getReferenceResolver()); } } return null; }
ContainerPolicy cp = xmlCollectionReferenceMapping.getContainerPolicy(); Object collection = xmlCollectionReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(object); if (collection == null) { return false; QName schemaType; if (xmlCollectionReferenceMapping.usesSingleNode()) { while (cp.hasNext(iterator)) { objectValue = cp.next(iterator, session); Object fieldValue = xmlCollectionReferenceMapping.buildFieldValue(objectValue, xmlField, session); if (fieldValue == null) { if(null != objectValue) { XMLField fkField = (XMLField) xmlCollectionReferenceMapping.getSourceToTargetKeyFieldAssociations().get(xmlField); fieldValue = marshalRecord.getMarshaller().getXMLContext().getValueByXPath(objectValue, fkField.getXPath(), fkField.getNamespaceResolver(), Object.class);
ClassDescriptor descriptor = sourceQuery.getSession().getClassDescriptor(getReferenceClass()); ContainerPolicy cp = this.getContainerPolicy(); Vector pkFieldNames = referenceDescriptor.getPrimaryKeyFieldNames(); Vector primaryKeyValues = new Vector(); HashMap primaryKeyMap = new HashMap(); for (Iterator fieldIt = getFields().iterator(); fieldIt.hasNext();) { XMLField fld = (XMLField) fieldIt.next(); XMLField tgtFld = (XMLField) getSourceToTargetKeyFieldAssociations().get(fld); Object fieldValue = databaseRow.getValues(fld); if ((fieldValue == null) || (fieldValue instanceof String) || !(fieldValue instanceof Vector)) {
ContainerPolicy cPolicy = mapping.getContainerPolicy(); Object currentObject = reference.getSourceObject(); Object container = null; if (mapping.getReuseContainer()) { container = mapping.getAttributeAccessor().getAttributeValueFromObject(currentObject); } else { container = cPolicy.containerInstance(); mapping.setAttributeValueInObject(currentObject, container); if(mapping.getInverseReferenceMapping() != null) { Object iterator = cPolicy.iteratorFor(container); while(cPolicy.hasNext(iterator)) { Object next = cPolicy.next(iterator, session); if(mapping.getInverseReferenceMapping().getContainerPolicy() == null) { mapping.getInverseReferenceMapping().getAttributeAccessor().setAttributeValueInObject(next, currentObject); } else { Object backpointerContainer = mapping.getInverseReferenceMapping().getAttributeAccessor().getAttributeValueFromObject(next); if(backpointerContainer == null) { backpointerContainer = mapping.getInverseReferenceMapping().getContainerPolicy().containerInstance(); mapping.getInverseReferenceMapping().getAttributeAccessor().setAttributeValueInObject(next, backpointerContainer); mapping.getInverseReferenceMapping().getContainerPolicy().addInto(currentObject, backpointerContainer, session);
} else if (xmlMapping instanceof XMLCollectionReferenceMapping) { XMLCollectionReferenceMapping xmlColMapping = (XMLCollectionReferenceMapping)xmlMapping; List fields = xmlColMapping.getFields(); XMLField xmlColMappingField = (XMLField) xmlColMapping.getField(); XPathNode branchNode; if(null == xmlColMappingField) { if(fields.size() > 1 && !xmlColMapping.usesSingleNode()) { addChild(XPathFragment.SELF_FRAGMENT, new XMLCollectionReferenceMappingMarshalNodeValue(xmlColMapping), xmlDescriptor.getNamespaceResolver()); branchNode = addChild(((XMLField) xmlColMapping.getField()).getXPathFragment(), new XMLCollectionReferenceMappingMarshalNodeValue(xmlColMapping), xmlDescriptor.getNamespaceResolver());
public XMLCollectionReferenceMappingMarshalNodeValue(XMLCollectionReferenceMapping xmlCollectionReferenceMapping) { this.xmlCollectionReferenceMapping = xmlCollectionReferenceMapping; branchNode = new XPathNode(); NamespaceResolver namespaceResolver = ((XMLDescriptor) xmlCollectionReferenceMapping.getDescriptor()).getNamespaceResolver(); List fkFields = xmlCollectionReferenceMapping.getFields(); for(int x=0, fkFieldsSize=fkFields.size(); x<fkFieldsSize; x++) { XMLField fkField = (XMLField) fkFields.get(x); branchNode.addChild(fkField.getXPathFragment(), new XMLCollectionReferenceMappingFKMarshalNodeValue(xmlCollectionReferenceMapping, fkField), namespaceResolver); } }
/** * @override * @param xPathFragment * @param unmarshalRecord * @param atts */ public boolean startElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) { if (xmlField.getLastXPathFragment().isAttribute()) { if (!this.xmlCollectionReferenceMapping.usesSingleNode()) { String namespaceURI = xmlField.getLastXPathFragment().getNamespaceURI(); String value; if (namespaceURI == null) { value = atts.getValue(xmlField.getLastXPathFragment().getLocalName()); } else { value = atts.getValue(namespaceURI, xmlField.getLastXPathFragment().getLocalName()); } xmlCollectionReferenceMapping.buildReference(unmarshalRecord, xmlField, value, unmarshalRecord.getSession()); return true; } } return true; }
@Override public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, AbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) { Object fieldValue = xmlCollectionReferenceMapping.buildFieldValue(value, xmlField, session); if (fieldValue == null) { if(null != value) { XMLField f2 = (XMLField) xmlCollectionReferenceMapping.getSourceToTargetKeyFieldAssociations().get(xmlField); fieldValue = marshalRecord.getMarshaller().getXMLContext().getValueByXPath(value, f2.getXPath(), f2.getNamespaceResolver(), Object.class); } if(null == fieldValue) { return false; } } QName schemaType = getSchemaType(xmlField, fieldValue, session); String stringValue = getValueToWrite(schemaType, fieldValue, (XMLConversionManager) session.getDatasourcePlatform().getConversionManager(), namespaceResolver); if (stringValue != null) { if (xPathFragment.isAttribute()) { marshalRecord.attribute(xPathFragment, namespaceResolver, stringValue); marshalRecord.closeStartElement(); } else { marshalRecord.closeStartElement(); marshalRecord.characters(stringValue); } return true; } return false; }
@Override public boolean marshal(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, AbstractSession session, NamespaceResolver namespaceResolver) { if (xmlCollectionReferenceMapping.isReadOnly()) { return false; } Object collection = xmlCollectionReferenceMapping.getAttributeAccessor().getAttributeValueFromObject(object); if (null == collection) { return false; } ContainerPolicy cp = getContainerPolicy(); Object iterator = cp.iteratorFor(collection); if (cp.hasNext(iterator)) { XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver); marshalRecord.closeStartGroupingElements(groupingFragment); } else { return false; } if(xPathFragment != XPathFragment.SELF_FRAGMENT) { marshalRecord.openStartElement(xPathFragment, namespaceResolver); } while (cp.hasNext(iterator)) { Object objectValue = cp.next(iterator, session); marshalSingleValue(xPathFragment, marshalRecord, object, objectValue, session, namespaceResolver, ObjectMarshalContext.getInstance()); } if(xPathFragment != XPathFragment.SELF_FRAGMENT) { marshalRecord.endElement(xPathFragment, namespaceResolver); } return true; }
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, AbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) { if (xmlCollectionReferenceMapping.usesSingleNode()) { XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver); if (xPathFragment.isAttribute()) { Object fieldValue = xmlCollectionReferenceMapping.buildFieldValue(value, xmlField, session); if (fieldValue == null) { return false;
/** * INTERNAL: * Create (if necessary) and populate a reference object that will be used * during the mapping reference resolution phase after unmarshalling is * complete. */ public void buildReference(UnmarshalRecord record, XMLField xmlField, Object object, AbstractSession session, Object container) { buildReference(record.getCurrentObject(), xmlField, object, session, container, record.getReferenceResolver()); }
private Setting convertToSetting(DatabaseMapping mapping, Object value) { XMLDescriptor xmlDescriptor = (XMLDescriptor) mapping.getDescriptor(); NamespaceResolver nsResolver = xmlDescriptor.getNamespaceResolver(); Setting rootSetting = new Setting(); XMLField xmlField = (XMLField) mapping.getField(); if (xmlField == null) { if (mapping instanceof XMLObjectReferenceMapping) { xmlField = (XMLField) ((XMLObjectReferenceMapping) mapping).getFields().get(0); } else if (mapping instanceof XMLCollectionReferenceMapping) { xmlField = (XMLField) ((XMLCollectionReferenceMapping) mapping).getFields().get(0); } } Setting setting = rootSetting; if (xmlField != null) { XPathFragment xPathFragment = xmlField.getXPathFragment(); rootSetting = convertToSetting(xPathFragment, nsResolver); setting = rootSetting; while (xPathFragment.getNextFragment() != null) { xPathFragment = xPathFragment.getNextFragment(); Setting childSetting = convertToSetting(xPathFragment, nsResolver); setting.addChild(childSetting); setting = childSetting; } } setting.setObject(dataObject); setting.setMapping(mapping); setting.setValue(value, false); return rootSetting; }