Class EISOneToManyMapping

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, EISMapping, ContainerMapping

    public class EISOneToManyMapping
    extends CollectionMapping
    implements EISMapping

    An EIS one-to-many mapping is a reference mapping that represents the relationship between a single source object and a collection of mapped persistent Java objects. The source object usually contains a foreign key (pointer) to the target objects (key on source); alternatively, the target objects may contain a foreign key to the source object (key on target). Because both the source and target objects use interactions, they must all be configured as root object types.

    Record Type Description
    Indexed Ordered collection of record elements. The indexed record EIS format enables Java class attribute values to be retreived by position or index.
    Mapped Key-value map based representation of record elements. The mapped record EIS format enables Java class attribute values to be retreived by an object key.
    XML Record/Map representation of an XML DOM element.
    See Also:
    EISDescriptor.useIndexedRecordFormat(), EISDescriptor.useMappedRecordFormat(), EISDescriptor.useXMLRecordFormat(), Serialized Form
    Since:
    Oracle TopLink 10g Release 2 (10.1.3)
    • Field Detail

      • isForeignKeyRelationship

        protected boolean isForeignKeyRelationship
        Keeps track if any of the fields are foreign keys.
      • targetForeignKeyFields

        protected transient java.util.List<org.eclipse.persistence.internal.helper.DatabaseField> targetForeignKeyFields
        The target foreign key fields that reference the sourceKeyFields.
      • sourceForeignKeyFields

        protected transient java.util.List<org.eclipse.persistence.internal.helper.DatabaseField> sourceForeignKeyFields
        The (typically primary) source key fields that are referenced by the targetForeignKeyFields.
      • sourceForeignKeysToTargetKeys

        protected transient java.util.Map<org.eclipse.persistence.internal.helper.DatabaseField,​org.eclipse.persistence.internal.helper.DatabaseField> sourceForeignKeysToTargetKeys
        This maps the source foreign key fields to the corresponding (primary) target key fields.
      • foreignKeyGroupingElement

        protected org.eclipse.persistence.internal.helper.DatabaseField foreignKeyGroupingElement
        The grouping-element field.
    • Constructor Detail

      • EISOneToManyMapping

        public EISOneToManyMapping()
    • Method Detail

      • addForeignKeyField

        public void addForeignKeyField​(org.eclipse.persistence.internal.helper.DatabaseField sourceForeignKeyField,
                                       org.eclipse.persistence.internal.helper.DatabaseField targetKeyField)
        PUBLIC: Define the source foreign key relationship in the one-to-many mapping. This method is used for composite source foreign key relationships. That is, the source object's table has multiple foreign key fields that are references to the target object's (typically primary) key fields. Both the source foreign key field name and the corresponding target primary key field name must be specified.
        Overrides:
        addForeignKeyField in class ForeignReferenceMapping
      • addForeignKeyFieldName

        public void addForeignKeyFieldName​(java.lang.String sourceForeignKeyFieldName,
                                           java.lang.String targetKeyFieldName)
        PUBLIC: Define the source foreign key relationship in the one-to-many mapping. This method is used for composite source foreign key relationships. That is, the source object's table has multiple foreign key fields that are references to the target object's (typically primary) key fields. Both the source foreign key field name and the corresponding target primary key field name must be specified.
      • isForeignKeyRelationship

        public boolean isForeignKeyRelationship()
        INTERNAL: Return if the 1-M mapping has a foreign key dependency to its target. This is true if any of the foreign key fields are true foreign keys, i.e. populated on write from the targets primary key.
      • setIsForeignKeyRelationship

        public void setIsForeignKeyRelationship​(boolean isForeignKeyRelationship)
        INTERNAL: Set if the 1-M mapping has a foreign key dependency to its target. This is true if any of the foreign key fields are true foreign keys, i.e. populated on write from the targets primary key.
      • getForeignKeyGroupingElement

        public org.eclipse.persistence.internal.helper.DatabaseField getForeignKeyGroupingElement()
        Get the grouping element field on the mapping. This is an optional setting.
      • setForeignKeyGroupingElement

        public void setForeignKeyGroupingElement​(java.lang.String name)
        Set the grouping element field on the mapping. This is an optional setting; however it is a required setting when there are more than one foreign keys specified
      • setDeleteAllCall

        public void setDeleteAllCall​(Call call)
        PUBLIC: The default delete all call for this mapping can be overridden by specifying the new call. This call is responsible for doing the deletion required by the mapping, such as optimized delete all of target objects for 1-M.
        Overrides:
        setDeleteAllCall in class CollectionMapping
      • setForeignKeyGroupingElement

        public void setForeignKeyGroupingElement​(org.eclipse.persistence.internal.helper.DatabaseField field)
        Set if the grouping element field on the mapping. This is an optional setting; however it is a required setting when there are more than one foreign keys specified.
      • getSourceForeignKeyFields

        public java.util.List<org.eclipse.persistence.internal.helper.DatabaseField> getSourceForeignKeyFields()
        INTERNAL: Return the source foreign key fields.
      • setSourceForeignKeyFields

        public void setSourceForeignKeyFields​(java.util.List<org.eclipse.persistence.internal.helper.DatabaseField> fields)
        INTERNAL: Sets the source foreign key fields.
      • getTargetForeignKeyFields

        public java.util.List<org.eclipse.persistence.internal.helper.DatabaseField> getTargetForeignKeyFields()
        INTERNAL: Return the source foreign key fields.
      • setTargetForeignKeyFields

        public void setTargetForeignKeyFields​(java.util.List<org.eclipse.persistence.internal.helper.DatabaseField> fields)
        INTERNAL: Sets the target foreign key fields.
      • getSourceForeignKeysToTargetKeys

        public java.util.Map<org.eclipse.persistence.internal.helper.DatabaseField,​org.eclipse.persistence.internal.helper.DatabaseField> getSourceForeignKeysToTargetKeys()
        INTERNAL: Sets the target foreign key fields.
      • setSourceForeignKeysToTargetKeys

        public void setSourceForeignKeysToTargetKeys​(java.util.Map<org.eclipse.persistence.internal.helper.DatabaseField,​org.eclipse.persistence.internal.helper.DatabaseField> sourceToTargetKeyFields)
        INTERNAL: Set the source keys to target keys fields association.
      • hasInverseConstraintDependency

        public boolean hasInverseConstraintDependency()
        INTERNAL: Return whether the mapping has any inverse constraint dependencies, such as foreign keys.
        Overrides:
        hasInverseConstraintDependency in class DatabaseMapping
      • initializeSelectionCriteria

        protected void initializeSelectionCriteria​(org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Selection criteria is created with source foreign keys and target keys. This criteria is then used to read target records from the table. CR#3922 - This method is almost the same as buildSelectionCriteria() the difference is that getSelectionCriteria() is called
      • initializeDeleteAllQuery

        protected void initializeDeleteAllQuery()
        Initialize the delete all query. This query is used to delete the collection of objects from the database.
      • preInitialize

        public void preInitialize​(org.eclipse.persistence.internal.sessions.AbstractSession session)
        Fix field names for XML data descriptors. Since fields are fixed to use text() by default in descriptor, ensure the correct non text field is used here.
        Overrides:
        preInitialize in class ForeignReferenceMapping
      • verifyDelete

        public boolean verifyDelete​(java.lang.Object object,
                                    org.eclipse.persistence.internal.sessions.AbstractSession session)
                             throws DatabaseException
        INTERNAL: Used to verify whether the specified object is deleted or not.
        Overrides:
        verifyDelete in class CollectionMapping
        Throws:
        DatabaseException
      • buildAddedElementFromChangeSet

        public java.lang.Object buildAddedElementFromChangeSet​(java.lang.Object changeSet,
                                                               org.eclipse.persistence.internal.sessions.MergeManager mergeManager,
                                                               org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
        INTERNAL: Build and return a new element based on the change set.
      • buildChangeSet

        public java.lang.Object buildChangeSet​(java.lang.Object element,
                                               org.eclipse.persistence.internal.sessions.ObjectChangeSet owner,
                                               org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Build and return a change set for the specified element.
      • buildElementFromChangeSet

        protected java.lang.Object buildElementFromChangeSet​(java.lang.Object changeSet,
                                                             org.eclipse.persistence.internal.sessions.MergeManager mergeManager,
                                                             org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
        Build and return a new element based on the change set.
      • buildElementFromElement

        public java.lang.Object buildElementFromElement​(java.lang.Object element,
                                                        org.eclipse.persistence.internal.sessions.MergeManager mergeManager,
                                                        org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
        INTERNAL: Build and return a new element based on the specified element.
      • buildExpression

        public Expression buildExpression​(java.lang.Object queryObject,
                                          QueryByExamplePolicy policy,
                                          Expression expressionBuilder,
                                          java.util.Map processedObjects,
                                          org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: In case Query By Example is used, this method builds and returns an expression that corresponds to a single attribute and it's value.
        Overrides:
        buildExpression in class CollectionMapping
      • buildRemovedElementFromChangeSet

        public java.lang.Object buildRemovedElementFromChangeSet​(java.lang.Object changeSet,
                                                                 org.eclipse.persistence.internal.sessions.MergeManager mergeManager,
                                                                 org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
        INTERNAL: Build and return a new element based on the change set.
      • clone

        public java.lang.Object clone()
        INTERNAL: Clone the appropriate attributes.
        Overrides:
        clone in class CollectionMapping
      • collectFields

        protected java.util.Vector collectFields()
        Return all the fields mapped by the mapping.
        Overrides:
        collectFields in class DatabaseMapping
      • compareElements

        public boolean compareElements​(java.lang.Object element1,
                                       java.lang.Object element2,
                                       org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Compare the non-null elements and return true if they are alike.
      • mapKeyHasChanged

        public boolean mapKeyHasChanged​(java.lang.Object element,
                                        org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Return whether the element's user-defined Map key has changed since it was cloned from the original version. Object elements can change their keys without detection. Get the original object and compare keys.
      • compareElementsForChange

        public boolean compareElementsForChange​(java.lang.Object element1,
                                                java.lang.Object element2,
                                                org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Compare the non-null elements and return true if they are alike. Here we use object identity.
      • compareForChange

        public org.eclipse.persistence.internal.sessions.ChangeRecord compareForChange​(java.lang.Object clone,
                                                                                       java.lang.Object backup,
                                                                                       org.eclipse.persistence.internal.sessions.ObjectChangeSet owner,
                                                                                       org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Compare the changes between two collections. Element comparisons are made using identity and, when appropriate, the value of the element's key for the Map container.
        Overrides:
        compareForChange in class CollectionMapping
        Returns:
        prototype.changeset.ChangeRecord
      • compareObjects

        public boolean compareObjects​(java.lang.Object object1,
                                      java.lang.Object object2,
                                      org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Compare the attributes belonging to this mapping for the objects.
        Overrides:
        compareObjects in class CollectionMapping
      • mergeChangesIntoObject

        public void mergeChangesIntoObject​(java.lang.Object target,
                                           org.eclipse.persistence.internal.sessions.ChangeRecord chgRecord,
                                           java.lang.Object source,
                                           org.eclipse.persistence.internal.sessions.MergeManager mergeManager,
                                           org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
        INTERNAL: If the mapping has a foreign key, it is order, so must use a different merge.
        Overrides:
        mergeChangesIntoObject in class CollectionMapping
      • mergeIntoObject

        public void mergeIntoObject​(java.lang.Object target,
                                    boolean isTargetUnInitialized,
                                    java.lang.Object source,
                                    org.eclipse.persistence.internal.sessions.MergeManager mergeManager,
                                    org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
        INTERNAL: If the mapping has a foreign key, it is order, so must use a different merge.
        Overrides:
        mergeIntoObject in class CollectionMapping
      • simpleAddToCollectionChangeRecord

        public void simpleAddToCollectionChangeRecord​(java.lang.Object referenceKey,
                                                      java.lang.Object changeSetToAdd,
                                                      org.eclipse.persistence.internal.sessions.ObjectChangeSet changeSet,
                                                      org.eclipse.persistence.internal.sessions.AbstractSession 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.
        Overrides:
        simpleAddToCollectionChangeRecord in class CollectionMapping
      • simpleRemoveFromCollectionChangeRecord

        public void simpleRemoveFromCollectionChangeRecord​(java.lang.Object referenceKey,
                                                           java.lang.Object changeSetToRemove,
                                                           org.eclipse.persistence.internal.sessions.ObjectChangeSet changeSet,
                                                           org.eclipse.persistence.internal.sessions.AbstractSession session)
        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.
        Overrides:
        simpleRemoveFromCollectionChangeRecord in class CollectionMapping
      • extractKeyRowFromReferenceObject

        protected org.eclipse.persistence.internal.sessions.AbstractRecord extractKeyRowFromReferenceObject​(java.lang.Object object,
                                                                                                            org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                                                                            org.eclipse.persistence.internal.sessions.AbstractRecord parentRecord)
        Build and return a database row that contains a foreign key for the specified reference object. This will be stored in the nested row(s).
      • valueFromRow

        public java.lang.Object valueFromRow​(org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                             org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager,
                                             ObjectBuildingQuery sourceQuery,
                                             org.eclipse.persistence.internal.identitymaps.CacheKey cacheKey,
                                             org.eclipse.persistence.internal.sessions.AbstractSession executionSession,
                                             boolean isTargetProtected,
                                             java.lang.Boolean[] wasCacheUsed)
                                      throws DatabaseException
        INTERNAL: Return the value of the reference attribute or a value holder. Check whether the mapping's attribute should be optimized through batch and joining.
        Overrides:
        valueFromRow in class ForeignReferenceMapping
        Throws:
        DatabaseException
      • getForeignKeyRows

        public java.util.Vector getForeignKeyRows​(org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                                  org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL:
      • writeFromObjectIntoRow

        public void writeFromObjectIntoRow​(java.lang.Object object,
                                           org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                           org.eclipse.persistence.internal.sessions.AbstractSession session,
                                           DatabaseMapping.WriteType writeType)
        INTERNAL: Get the appropriate attribute value from the object and put it in the appropriate field of the database row. Loop through the reference objects and extract the primary keys and put them in the vector of "nested" rows.
        Overrides:
        writeFromObjectIntoRow in class DatabaseMapping
      • writeFromObjectIntoRowForShallowInsert

        public void writeFromObjectIntoRowForShallowInsert​(java.lang.Object object,
                                                           org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                                           org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: This row is built for shallow insert which happens in case of bidirectional inserts. The foreign keys must be set to null to avoid constraints.
        Overrides:
        writeFromObjectIntoRowForShallowInsert in class DatabaseMapping
      • writeFromObjectIntoRowForUpdateAfterShallowInsert

        public void writeFromObjectIntoRowForUpdateAfterShallowInsert​(java.lang.Object object,
                                                                      org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                                                      org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                                      org.eclipse.persistence.internal.helper.DatabaseTable table)
        INTERNAL: This row is built for update after shallow insert which happens in case of bidirectional inserts. It contains the foreign keys with non null values that were set to null for shallow insert. If mapping overrides writeFromObjectIntoRowForShallowInsert method it must override this one, too.
        Overrides:
        writeFromObjectIntoRowForUpdateAfterShallowInsert in class DatabaseMapping
      • writeFromObjectIntoRowForShallowInsertWithChangeRecord

        public void writeFromObjectIntoRowForShallowInsertWithChangeRecord​(org.eclipse.persistence.internal.sessions.ChangeRecord changeRecord,
                                                                           org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                                                           org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: This row is built for shallow insert which happens in case of bidirectional inserts. The foreign keys must be set to null to avoid constraints.
        Overrides:
        writeFromObjectIntoRowForShallowInsertWithChangeRecord in class DatabaseMapping
      • writeFromObjectIntoRowWithChangeRecord

        public void writeFromObjectIntoRowWithChangeRecord​(org.eclipse.persistence.internal.sessions.ChangeRecord changeRecord,
                                                           org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                                           org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                           DatabaseMapping.WriteType writeType)
        INTERNAL: Get the appropriate attribute value from the object and put it in the appropriate field of the database row. Loop through the reference objects and extract the primary keys and put them in the vector of "nested" rows.
        Overrides:
        writeFromObjectIntoRowWithChangeRecord in class DatabaseMapping
      • writeInsertFieldsIntoRow

        public void writeInsertFieldsIntoRow​(org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                             org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Write fields needed for insert into the template for with null values.
        Overrides:
        writeInsertFieldsIntoRow in class DatabaseMapping
      • setSelectionSQLString

        public void setSelectionSQLString​(java.lang.String sqlString)
        INTERNAL: This method is not supported in an EIS environment.
        Overrides:
        setSelectionSQLString in class ForeignReferenceMapping
      • setDeleteAllSQLString

        public void setDeleteAllSQLString​(java.lang.String sqlString)
        INTERNAL: This method is not supported in an EIS environment.
        Overrides:
        setDeleteAllSQLString in class CollectionMapping