Class XMLObjectReferenceMapping

java.lang.Object
org.eclipse.persistence.core.mappings.CoreMapping<AttributeAccessor,org.eclipse.persistence.internal.sessions.AbstractSession,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField>
org.eclipse.persistence.mappings.DatabaseMapping
org.eclipse.persistence.mappings.AggregateMapping
org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping
All Implemented Interfaces:
Serializable, Cloneable, org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLRecord>, org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>, XMLMapping
Direct Known Subclasses:
XMLCollectionReferenceMapping

public class XMLObjectReferenceMapping extends AggregateMapping implements org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>, XMLMapping
TopLink OXM version of a 1-1 mapping. A list of source-target key field associations is used to link the source xpaths to their related target xpaths, and hence their primary key (unique identifier) values used when (un)marshalling. This mapping has a Vector of XMLFields as opposed to a single XMLField. It is important to note that each target xpath is assumed to be set as a primary key field on the target (reference) class descriptor - this is necessary in order to locate the correct target object instance in the session cache when resolving mapping references.
See Also:
  • Field Details

    • sourceToTargetKeyFieldAssociations

      protected HashMap sourceToTargetKeyFieldAssociations
    • sourceToTargetKeys

      protected Vector sourceToTargetKeys
  • Constructor Details

    • XMLObjectReferenceMapping

      public XMLObjectReferenceMapping()
      PUBLIC: The default constructor initializes the sourceToTargetKeyFieldAssociations and sourceToTargetKeys data structures.
  • Method Details

    • addSourceToTargetKeyFieldAssociation

      public void addSourceToTargetKeyFieldAssociation(String srcXPath, String tgtXPath)
      PUBLIC: Add a source-target xpath pair to the map.
      Specified by:
      addSourceToTargetKeyFieldAssociation in interface org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>
      Parameters:
      srcXPath -
      tgtXPath -
    • addSourceToTargetKeyFieldAssociation

      public void addSourceToTargetKeyFieldAssociation(XMLField srcField, XMLField tgtField)
    • buildFieldValue

      public Object buildFieldValue(Object targetObject, XMLField xmlFld, org.eclipse.persistence.internal.sessions.AbstractSession session)
      INTERNAL: Retrieve the target object's primary key value that is mapped to a given source xpath (in the source-target key field association list).
      Specified by:
      buildFieldValue in interface org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>
      Parameters:
      targetObject -
      xmlFld -
      session -
      Returns:
      null if the target object is null, the reference class is null, or a primary key field name does not exist on the reference descriptor that matches the target field name - otherwise, return the associated primary key value
    • buildReference

      public void buildReference(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord record, XMLField xmlField, Object object, org.eclipse.persistence.internal.sessions.AbstractSession session)
      INTERNAL: Create (if necessary) and populate a reference object that will be used during the mapping reference resolution phase after unmarshalling is complete.
      Specified by:
      buildReference in interface org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>
      Parameters:
      record -
      xmlField -
      object -
      session -
    • cascadePerformRemoveIfRequired

      public void cascadePerformRemoveIfRequired(Object object, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, Map visitedObjects)
      INTERNAL: Cascade perform delete through mappings that require the cascade
      Specified by:
      cascadePerformRemoveIfRequired in class DatabaseMapping
    • cascadeRegisterNewIfRequired

      public void cascadeRegisterNewIfRequired(Object object, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, Map visitedObjects)
      INTERNAL: Cascade registerNew for Create through mappings that require the cascade
      Specified by:
      cascadeRegisterNewIfRequired in class DatabaseMapping
    • getFields

      public Vector getFields()
      INTERNAL: Return a list of XMLFields based on the source XPath values in the source-target key field associations list.
      Specified by:
      getFields in interface org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>
      Overrides:
      getFields in class DatabaseMapping
    • getSchemaType

      protected QName getSchemaType(XMLField xmlField, Object value, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Return a QName representation the schema type for a given XMLField, if applicable. Note: This method performs the same functionality as 'getSchemaType' in org.eclipse.persistence.internal.oxm.XMLSimpleMappingNodeValue.
      Parameters:
      xmlField -
      value -
      Returns:
    • getSingleValueToWriteForUnion

      protected QName getSingleValueToWriteForUnion(XMLUnionField xmlField, Object value, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Return a single QName representation for a given XMLUnionField, if applicable. Note: This method performs the same functionality as 'getSingleValueToWriteForUnion' in org.eclipse.persistence.internal.oxm.XMLSimpleMappingNodeValue.
      Parameters:
      xmlField -
      value -
      Returns:
    • getSourceToTargetKeyFieldAssociations

      public HashMap getSourceToTargetKeyFieldAssociations()
      INTERNAL: Return a list of source-target xmlfield pairs.
      Specified by:
      getSourceToTargetKeyFieldAssociations in interface org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>
      Returns:
    • getValueToWrite

      protected String getValueToWrite(QName schemaType, Object value, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Return a string representation of a given value, based on a given schema type. Note: This method performs the same functionality as 'getValueToWrite' in org.eclipse.persistence.internal.oxm.XMLSimpleMappingNodeValue.
      Parameters:
      schemaType -
      value -
      Returns:
    • initialize

      public void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session) throws DescriptorException
      INTERNAL: Register a ReferenceResolver as an event listener on the session, if one doesn't already exist. Each source/target field will have a namespace resolver set as well.
      Overrides:
      initialize in class AggregateMapping
      Throws:
      DescriptorException
      See Also:
    • preInitialize

      public void preInitialize(org.eclipse.persistence.internal.sessions.AbstractSession session) throws DescriptorException
      Description copied from class: DatabaseMapping
      INTERNAL: Allow for initialization of properties and validation.
      Overrides:
      preInitialize in class DatabaseMapping
      Throws:
      DescriptorException
    • isXMLMapping

      public boolean isXMLMapping()
      INTERNAL: Indicates that this is an XML mapping.
      Overrides:
      isXMLMapping in class DatabaseMapping
    • readFromRowIntoObject

      public Object readFromRowIntoObject(org.eclipse.persistence.internal.sessions.AbstractRecord databaseRow, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, Object targetObject, org.eclipse.persistence.internal.identitymaps.CacheKey parentCacheKey, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.sessions.AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException
      INTERNAL: Extract the primary key values from the row, then create an org.eclipse.persistence.internal.oxm.Reference instance and store it on the session's org.eclipse.persistence.internal.oxm.ReferenceResolver.
      Overrides:
      readFromRowIntoObject in class DatabaseMapping
      Throws:
      DatabaseException
    • setField

      public void setField(org.eclipse.persistence.internal.helper.DatabaseField field)
      Parameters:
      field -
    • setSourceToTargetKeyFieldAssociations

      public void setSourceToTargetKeyFieldAssociations(HashMap sourceToTargetKeyFieldAssociations)
      INTERNAL: Set the list of source-target xmlfield pairs.
    • writeFromObjectIntoRow

      public void writeFromObjectIntoRow(Object object, org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session, DatabaseMapping.WriteType writeType)
      INTERNAL: Write the attribute value from the object to the row.
      Overrides:
      writeFromObjectIntoRow in class DatabaseMapping
    • writeSingleValue

      public void writeSingleValue(Object value, Object parent, XMLRecord row, org.eclipse.persistence.internal.sessions.AbstractSession session)
      Description copied from interface: XMLMapping
      INTERNAL: A method that marshals a single value to the provided Record based on this mapping's XPath. Used for Sequenced marshalling.
      Specified by:
      writeSingleValue in interface org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLRecord>
      Specified by:
      writeSingleValue in interface XMLMapping
      Parameters:
      value - - The value to be marshalled
      row - - The Record the value is being marshalled too.
    • setIsWriteOnly

      public void setIsWriteOnly(boolean b)
      Specified by:
      setIsWriteOnly in interface org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>
      Specified by:
      setIsWriteOnly in interface XMLMapping
    • isWriteOnly

      public boolean isWriteOnly()
      Description copied from class: DatabaseMapping
      INTERNAL: Some mappings support no attribute (transformation and multitenant primary key).
      Specified by:
      isWriteOnly in interface org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>
      Specified by:
      isWriteOnly in interface XMLMapping
      Overrides:
      isWriteOnly in class DatabaseMapping
    • setAttributeValueInObject

      public void setAttributeValueInObject(Object object, Object value) throws DescriptorException
      Description copied from class: DatabaseMapping
      INTERNAL: Set the value of the attribute mapped by this mapping.
      Specified by:
      setAttributeValueInObject in interface org.eclipse.persistence.internal.oxm.mappings.Mapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,XMLRecord>
      Overrides:
      setAttributeValueInObject in class DatabaseMapping
      Throws:
      DescriptorException
    • getInverseReferenceMapping

      public XMLInverseReferenceMapping getInverseReferenceMapping()
      Specified by:
      getInverseReferenceMapping in interface org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping<org.eclipse.persistence.internal.sessions.AbstractSession,AttributeAccessor,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField,org.eclipse.persistence.internal.oxm.record.UnmarshalRecord,XMLField,XMLRecord>
    • isObjectReferenceMapping

      public boolean isObjectReferenceMapping()
      Description copied from class: DatabaseMapping
      INTERNAL: Related mapping should implement this method to return true.
      Overrides:
      isObjectReferenceMapping in class DatabaseMapping