Class ManyToManyMapping

    • Field Detail

      • PostInsert

        protected static final java.lang.String PostInsert
        Used for data modification events.
        See Also:
        Constant Field Values
      • mechanism

        protected RelationTableMechanism mechanism
        Mechanism holds relationTable and all fields and queries associated with it.
      • isDefinedAsOneToManyMapping

        protected boolean isDefinedAsOneToManyMapping
        266912: Since: EclipseLink 2.0 for the Metamodel API For 1:1 and m:m mappings - track the original externally defined mapping if different Note: This field will provide differentiation for the following external to internal representations for mapping types
        - A OneToManyMapping will be represented by a ManyToManyMapping if unidirectional
        - A ManyToOneMapping will be represented by a OneToOneMapping (without a FK constraint)
    • Constructor Detail

      • ManyToManyMapping

        public ManyToManyMapping()
        PUBLIC: Default constructor.
    • Method Detail

      • addSourceRelationKeyField

        public void addSourceRelationKeyField​(org.eclipse.persistence.internal.helper.DatabaseField sourceRelationKeyField,
                                              org.eclipse.persistence.internal.helper.DatabaseField sourcePrimaryKeyField)
        PUBLIC: Add the fields in the intermediate table that corresponds to the primary key in the source table. This method is used if the keys are composite.
      • addSourceRelationKeyFieldName

        public void addSourceRelationKeyFieldName​(java.lang.String sourceRelationKeyFieldName,
                                                  java.lang.String sourcePrimaryKeyFieldName)
        PUBLIC: Add the fields in the intermediate table that corresponds to the primary key in the source table. This method is used if the keys are composite.
      • addTargetRelationKeyField

        public void addTargetRelationKeyField​(org.eclipse.persistence.internal.helper.DatabaseField targetRelationKeyField,
                                              org.eclipse.persistence.internal.helper.DatabaseField targetPrimaryKeyField)
        PUBLIC: Add the fields in the intermediate table that corresponds to the primary key in the target table. This method is used if the keys are composite.
      • addTargetRelationKeyFieldName

        public void addTargetRelationKeyFieldName​(java.lang.String targetRelationKeyFieldName,
                                                  java.lang.String targetPrimaryKeyFieldName)
        PUBLIC: Add the fields in the intermediate table that corresponds to the primary key in the target table. This method is used if the keys are composite.
      • collectQueryParameters

        public void collectQueryParameters​(java.util.Set<org.eclipse.persistence.internal.helper.DatabaseField> cacheFields)
        INTERNAL: This method is used to store the FK fields that can be cached that correspond to noncacheable mappings the FK field values will be used to re-issue the query when cloning the shared cache entity
        Overrides:
        collectQueryParameters in class CollectionMapping
      • earlyPreDelete

        public void earlyPreDelete​(DeleteObjectQuery query,
                                   java.lang.Object object)
        INTERNAL: Delete join tables before the start of the deletion process to avoid constraint errors.
        Overrides:
        earlyPreDelete in class DatabaseMapping
      • createMapComponentFromRow

        public java.lang.Object createMapComponentFromRow​(org.eclipse.persistence.internal.sessions.AbstractRecord dbRow,
                                                          ObjectBuildingQuery query,
                                                          org.eclipse.persistence.internal.identitymaps.CacheKey parentCacheKey,
                                                          org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                          boolean isTargetProtected)
        INTERNAL Called when a DatabaseMapping is used to map the key in a collection. Returns the key.
        Specified by:
        createMapComponentFromRow in interface MapComponentMapping
      • extendPessimisticLockScopeInSourceQuery

        public void extendPessimisticLockScopeInSourceQuery​(ObjectLevelReadQuery sourceQuery)
        INTERNAL: Called only if both shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true. Adds fields to be locked to the where clause of the source query. Note that the sourceQuery must be ObjectLevelReadQuery so that it has ExpressionBuilder. This method must be implemented in subclasses that allow setting shouldExtendPessimisticLockScopeInSourceQuery to true.
        Overrides:
        extendPessimisticLockScopeInSourceQuery in class ForeignReferenceMapping
      • extractKeyFromTargetRow

        protected java.lang.Object extractKeyFromTargetRow​(org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                                           org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Extract the source primary key value from the relation row. Used for batch reading, most following same order and fields as in the mapping.
        Overrides:
        extractKeyFromTargetRow in class CollectionMapping
      • extractBatchKeyFromRow

        protected java.lang.Object extractBatchKeyFromRow​(org.eclipse.persistence.internal.sessions.AbstractRecord row,
                                                          org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Extract the primary key value from the source row. Used for batch reading, most following same order and fields as in the mapping.
        Overrides:
        extractBatchKeyFromRow in class ForeignReferenceMapping
      • getExtendPessimisticLockScopeDedicatedQuery

        protected ReadQuery getExtendPessimisticLockScopeDedicatedQuery​(org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                                        short lockMode)
        INTERNAL: Should be overridden by subclass that allows setting extendPessimisticLockScope to DEDICATED_QUERY.
        Overrides:
        getExtendPessimisticLockScopeDedicatedQuery in class ForeignReferenceMapping
      • getJoinCriteria

        public Expression getJoinCriteria​(org.eclipse.persistence.internal.expressions.ObjectExpression context,
                                          Expression base)
        INTERNAL: Returns the join criteria stored in the mapping selection query. This criteria is used to read reference objects across the tables from the database.
        Overrides:
        getJoinCriteria in class CollectionMapping
      • getHistoryPolicy

        public HistoryPolicy getHistoryPolicy()
        PUBLIC: Allows history tracking on the m-m join table.
      • getRelationTableMechanism

        public RelationTableMechanism getRelationTableMechanism()
        PUBLIC: Returns RelationTableMechanism that may be owned by the mapping. Note that all RelationTableMechanism methods are accessible through the mapping directly. The only reason this method is provided is to allow a uniform approach to RelationTableMechanism in both ManyToManyMapping and OneToOneMapping that uses RelationTableMechanism.
      • getRelationTable

        public org.eclipse.persistence.internal.helper.DatabaseTable getRelationTable()
        INTERNAL: Return the relation table associated with the mapping.
      • getRelationTableName

        public java.lang.String getRelationTableName()
        PUBLIC: Return the relation table name associated with the mapping.
      • getRelationTableQualifiedName

        public java.lang.String getRelationTableQualifiedName()
        PUBLIC: Return the relation table qualified name associated with the mapping.
      • getSourceKeyFieldNames

        public java.util.Vector getSourceKeyFieldNames()
        PUBLIC: Return the source key field names associated with the mapping. These are in-order with the sourceRelationKeyFieldNames.
      • getSourceKeyFields

        public java.util.Vector<org.eclipse.persistence.internal.helper.DatabaseField> getSourceKeyFields()
        INTERNAL: Return all the source key fields associated with the mapping.
      • getSourceRelationKeyFieldNames

        public java.util.Vector getSourceRelationKeyFieldNames()
        PUBLIC: Return the source relation key field names associated with the mapping. These are in-order with the sourceKeyFieldNames.
      • getSourceRelationKeyFields

        public java.util.Vector<org.eclipse.persistence.internal.helper.DatabaseField> getSourceRelationKeyFields()
        INTERNAL: Return all the source relation key fields associated with the mapping.
      • getTargetKeyFieldNames

        public java.util.Vector getTargetKeyFieldNames()
        PUBLIC: Return the target key field names associated with the mapping. These are in-order with the targetRelationKeyFieldNames.
      • getTargetKeyFields

        public java.util.Vector<org.eclipse.persistence.internal.helper.DatabaseField> getTargetKeyFields()
        INTERNAL: Return all the target keys associated with the mapping.
      • getTargetRelationKeyFieldNames

        public java.util.Vector getTargetRelationKeyFieldNames()
        PUBLIC: Return the target relation key field names associated with the mapping. These are in-order with the targetKeyFieldNames.
      • getTargetRelationKeyFields

        public java.util.Vector<org.eclipse.persistence.internal.helper.DatabaseField> getTargetRelationKeyFields()
        INTERNAL: Return all the target relation key fields associated with the mapping.
      • hasCustomDeleteQuery

        protected boolean hasCustomDeleteQuery()
      • hasCustomInsertQuery

        protected boolean hasCustomInsertQuery()
      • buildListOrderField

        protected void buildListOrderField()
        INTERNAL: Verifies listOrderField's table: it must be relation table. Precondition: listOrderField != null.
        Overrides:
        buildListOrderField in class CollectionMapping
      • shouldUseListOrderFieldTableExpression

        public boolean shouldUseListOrderFieldTableExpression()
        INTERNAL: Indicates whether getListOrderFieldExpression method should create field expression on table expression.
        Overrides:
        shouldUseListOrderFieldTableExpression in class CollectionMapping
      • initializeChangeOrderTargetQuery

        protected void initializeChangeOrderTargetQuery​(org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Initialize changeOrderTargetQuery.
        Overrides:
        initializeChangeOrderTargetQuery in class CollectionMapping
      • initializeDeleteAllQuery

        protected void initializeDeleteAllQuery​(org.eclipse.persistence.internal.sessions.AbstractSession session)
        Initialize delete all query. This query is used to all relevant rows from the relation table.
      • initializeListOrderFieldTable

        protected void initializeListOrderFieldTable​(org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Initializes listOrderField's table. Precondition: listOrderField != null.
        Overrides:
        initializeListOrderFieldTable in class CollectionMapping
      • initializeSelectionCriteriaAndAddFieldsToQuery

        protected void initializeSelectionCriteriaAndAddFieldsToQuery​(Expression startCriteria)
        INTERNAL: Selection criteria is created to read target records from the table.
      • insertIntoRelationTable

        public void insertIntoRelationTable​(WriteObjectQuery query)
                                     throws DatabaseException
        INTERNAL: Insert into relation table. This follows following steps.

        - Extract primary key and its value from the source object.

        - Extract target key and its value from the target object.

        - Construct a insert statement with above fields and values for relation table.

        - execute the statement.

        - Repeat above three statements until all the target objects are done.

        Throws:
        DatabaseException
      • isDefinedAsOneToManyMapping

        public boolean isDefinedAsOneToManyMapping()
        INTERNAL: Return whether this mapping was originally defined as a OneToMany.
      • postInitialize

        public void postInitialize​(org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Ensure the container policy is post initialized
        Overrides:
        postInitialize in class CollectionMapping
      • postInsert

        public void postInsert​(WriteObjectQuery query)
                        throws DatabaseException
        INTERNAL: Insert into relation table. This follows following steps.

        - Extract primary key and its value from the source object.

        - Extract target key and its value from the target object.

        - Construct a insert statement with above fields and values for relation table.

        - execute the statement.

        - Repeat above three statements until all the target objects are done.

        Overrides:
        postInsert in class CollectionMapping
        Throws:
        DatabaseException
      • prepareTranslationRow

        protected void prepareTranslationRow​(org.eclipse.persistence.internal.sessions.AbstractRecord translationRow,
                                             java.lang.Object object,
                                             ClassDescriptor descriptor,
                                             org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: The translation row may require additional fields than the primary key if the mapping in not on the primary key.
        Overrides:
        prepareTranslationRow in class CollectionMapping
      • setCustomDeleteQuery

        public void setCustomDeleteQuery​(DataModifyQuery query)
        PUBLIC: The default delete query for mapping can be overridden by specifying the new query. This query must delete the row from the M-M join table.
      • setCustomInsertQuery

        public void setCustomInsertQuery​(DataModifyQuery query)
        PUBLIC: The default insert query for mapping can be overridden by specifying the new query. This query must insert the row into the M-M join table.
      • setDeleteQuery

        protected void setDeleteQuery​(DataModifyQuery deleteQuery)
      • setDeleteSQLString

        public void setDeleteSQLString​(java.lang.String sqlString)
        PUBLIC: Set the receiver's delete SQL string. This allows the user to override the SQL generated by TOPLink, with there own SQL or procedure call. The arguments are translated from the fields of the source row, through replacing the field names marked by '#' with the values for those fields. This is used to delete a single entry from the M-M join table. Example, 'delete from PROJ_EMP where PROJ_ID = #PROJ_ID AND EMP_ID = #EMP_ID'.
      • setDefinedAsOneToManyMapping

        public void setDefinedAsOneToManyMapping​(boolean isDefinedAsOneToManyMapping)
        INTERNAL: Set whether this mapping was originally defined as a OneToMany
        Parameters:
        isDefinedAsOneToManyMapping -
      • setDeleteCall

        public void setDeleteCall​(Call call)
        PUBLIC: Set the receiver's delete Call. This allows the user to override the SQL generated by TOPLink, with there own SQL or procedure call. The arguments are translated from the fields of the source row. This is used to delete a single entry from the M-M join table. Example, 'new SQLCall("delete from PROJ_EMP where PROJ_ID = #PROJ_ID AND EMP_ID = #EMP_ID")'.
      • setInsertQuery

        protected void setInsertQuery​(DataModifyQuery insertQuery)
      • setInsertSQLString

        public void setInsertSQLString​(java.lang.String sqlString)
        PUBLIC: Set the receiver's insert SQL string. This allows the user to override the SQL generated by TOPLink, with there own SQL or procedure call. The arguments are translated from the fields of the source row, through replacing the field names marked by '#' with the values for those fields. This is used to insert an entry into the M-M join table. Example, 'insert into PROJ_EMP (EMP_ID, PROJ_ID) values (#EMP_ID, #PROJ_ID)'.
      • setInsertCall

        public void setInsertCall​(Call call)
        PUBLIC: Set the receiver's insert Call. This allows the user to override the SQL generated by TOPLink, with there own SQL or procedure call. The arguments are translated from the fields of the source row. This is used to insert an entry into the M-M join table. Example, 'new SQLCall("insert into PROJ_EMP (EMP_ID, PROJ_ID) values (#EMP_ID, #PROJ_ID)")'.
      • setRelationTable

        public void setRelationTable​(org.eclipse.persistence.internal.helper.DatabaseTable relationTable)
        PUBLIC: Set the relational table. This is the join table that store both the source and target primary keys.
      • setHistoryPolicy

        public void setHistoryPolicy​(HistoryPolicy policy)
        PUBLIC: Enable history tracking on the m-m join table.
      • setRelationTableName

        public void setRelationTableName​(java.lang.String tableName)
        PUBLIC: Set the name of the relational table. This is the join table that store both the source and target primary keys.
      • setSessionName

        public void setSessionName​(java.lang.String name)
        PUBLIC: Set the name of the session to execute the mapping's queries under. This can be used by the session broker to override the default session to be used for the target class.
        Overrides:
        setSessionName in class CollectionMapping
      • setSourceKeyFieldNames

        public void setSourceKeyFieldNames​(java.util.Vector fieldNames)
        PUBLIC: Set the source key field names associated with the mapping. These must be in-order with the sourceRelationKeyFieldNames.
      • setSourceKeyFields

        public void setSourceKeyFields​(java.util.Vector<org.eclipse.persistence.internal.helper.DatabaseField> sourceKeyFields)
        INTERNAL: Set the source fields.
      • setSourceRelationKeyFieldName

        public void setSourceRelationKeyFieldName​(java.lang.String sourceRelationKeyFieldName)
        PUBLIC: Set the source key field in the relation table. This is the name of the foreign key in the relation table to the source's primary key field. This method is used if the source primary key is a singleton only.
      • setSourceRelationKeyFieldNames

        public void setSourceRelationKeyFieldNames​(java.util.Vector fieldNames)
        PUBLIC: Set the source relation key field names associated with the mapping. These must be in-order with the sourceKeyFieldNames.
      • setSourceRelationKeyFields

        public void setSourceRelationKeyFields​(java.util.Vector<org.eclipse.persistence.internal.helper.DatabaseField> sourceRelationKeyFields)
        INTERNAL: Set the source fields.
      • setTargetKeyFieldNames

        public void setTargetKeyFieldNames​(java.util.Vector fieldNames)
        INTERNAL: Set the target key field names associated with the mapping. These must be in-order with the targetRelationKeyFieldNames.
      • setTargetKeyFields

        public void setTargetKeyFields​(java.util.Vector<org.eclipse.persistence.internal.helper.DatabaseField> targetKeyFields)
        INTERNAL: Set the target fields.
      • setTargetRelationKeyFieldName

        public void setTargetRelationKeyFieldName​(java.lang.String targetRelationKeyFieldName)
        PUBLIC: Set the target key field in the relation table. This is the name of the foreign key in the relation table to the target's primary key field. This method is used if the target's primary key is a singleton only.
      • setTargetRelationKeyFieldNames

        public void setTargetRelationKeyFieldNames​(java.util.Vector fieldNames)
        INTERNAL: Set the target relation key field names associated with the mapping. These must be in-order with the targetKeyFieldNames.
      • setTargetRelationKeyFields

        public void setTargetRelationKeyFields​(java.util.Vector<org.eclipse.persistence.internal.helper.DatabaseField> targetRelationKeyFields)
        INTERNAL: Set the target fields.