Top Description Fields Constructors Methods
org.eclipse.persistence.mappings

public Class ManyToManyMapping

extends CollectionMapping
implements RelationalMapping, MapComponentMapping
Class Inheritance
All Implemented Interfaces
org.eclipse.persistence.mappings.foundation.MapComponentMapping, org.eclipse.persistence.mappings.RelationalMapping
Imports
java.util.*, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.exceptions.*, org.eclipse.persistence.expressions.*, org.eclipse.persistence.history.*, org.eclipse.persistence.internal.expressions.*, org.eclipse.persistence.internal.helper.*, org.eclipse.persistence.internal.identitymaps.CacheKey, org.eclipse.persistence.internal.queries.*, org.eclipse.persistence.internal.sessions.*, org.eclipse.persistence.mappings.foundation.MapComponentMapping, org.eclipse.persistence.sessions.DatabaseRecord, org.eclipse.persistence.queries.*

Purpose: Many to many mappings are used to represent the relationships between a collection of source objects and a collection of target objects. The mapping requires the creation of an intermediate table for managing the associations between the source and target records.

Author
Sati
Since
TOPLink/Java 1.0

Field Summary

Modifier and TypeField and Description
protected HistoryPolicy
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)

protected RelationTableMechanism
mechanism

Mechanism holds relationTable and all fields and queries associated with it.

protected static final String
protected static final String
protected static final String
PostInsert

Used for data modification events.

Inherited from org.eclipse.persistence.mappings.CollectionMapping:
changeOrderTargetQuerycontainerPolicydeleteAllQueryhasCustomDeleteAllQueryhasOrderByisListOrderFieldSupportedisSynchronizeOnMergelistOrderFieldmustDeleteReferenceObjectsOneByOneorderCorrectionType

Constructor Summary

AccessConstructor and Description
public
ManyToManyMapping()

PUBLIC: Default constructor.

Method Summary

Modifier and TypeMethod and Description
public void
addSourceRelationKeyField(DatabaseField sourceRelationKeyField, DatabaseField sourcePrimaryKeyField)

PUBLIC: Add the fields in the intermediate table that corresponds to the primary key in the source table.

public void
addSourceRelationKeyFieldName(String sourceRelationKeyFieldName, String sourcePrimaryKeyFieldName)

PUBLIC: Add the fields in the intermediate table that corresponds to the primary key in the source table.

public void
addTargetRelationKeyField(DatabaseField targetRelationKeyField, DatabaseField targetPrimaryKeyField)

PUBLIC: Add the fields in the intermediate table that corresponds to the primary key in the target table.

public void
addTargetRelationKeyFieldName(String targetRelationKeyFieldName, String targetPrimaryKeyFieldName)

PUBLIC: Add the fields in the intermediate table that corresponds to the primary key in the target table.

protected Expression
buildBatchCriteria(ExpressionBuilder builder, ObjectLevelReadQuery query)

Overrides org.eclipse.persistence.mappings.ForeignReferenceMapping.buildBatchCriteria.

INTERNAL: Return the selection criteria used to IN batch fetching.
protected void
buildListOrderField()

Overrides org.eclipse.persistence.mappings.CollectionMapping.buildListOrderField.

INTERNAL: Verifies listOrderField's table: it must be relation table.
public Object
public void
collectQueryParameters(Set<DatabaseField>
TODO
cacheFields
)

Overrides org.eclipse.persistence.mappings.CollectionMapping.collectQueryParameters.

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
public Object
createMapComponentFromRow(AbstractRecord dbRow, ObjectBuildingQuery query, CacheKey parentCacheKey, AbstractSession session, boolean isTargetProtected)

Implements org.eclipse.persistence.mappings.foundation.MapComponentMapping.createMapComponentFromRow.

INTERNAL Called when a DatabaseMapping is used to map the key in a collection.
public void
earlyPreDelete(DeleteObjectQuery
TODO
query
,
Object
TODO
object
)

Overrides org.eclipse.persistence.mappings.DatabaseMapping.earlyPreDelete.

INTERNAL: Delete join tables before the start of the deletion process to avoid constraint errors.
public void
extendPessimisticLockScopeInSourceQuery(ObjectLevelReadQuery sourceQuery)

Overrides org.eclipse.persistence.mappings.ForeignReferenceMapping.extendPessimisticLockScopeInSourceQuery.

INTERNAL: Called only if both shouldExtendPessimisticLockScope and shouldExtendPessimisticLockScopeInSourceQuery are true.
protected void
extendPessimisticLockScopeInTargetQuery(ObjectLevelReadQuery targetQuery, ObjectBuildingQuery sourceQuery)

Overrides org.eclipse.persistence.mappings.ForeignReferenceMapping.extendPessimisticLockScopeInTargetQuery.

INTERNAL: Adds locking clause to the target query to extend pessimistic lock scope.
protected Object
extractBatchKeyFromRow(AbstractRecord row, AbstractSession session)

Overrides org.eclipse.persistence.mappings.ForeignReferenceMapping.extractBatchKeyFromRow.

INTERNAL: Extract the primary key value from the source row.
protected Object
extractKeyFromTargetRow(AbstractRecord row, AbstractSession session)

Overrides org.eclipse.persistence.mappings.CollectionMapping.extractKeyFromTargetRow.

INTERNAL: Extract the source primary key value from the relation row.
protected Expression
getAdditionalFieldsBaseExpression(ReadQuery query)

Overrides org.eclipse.persistence.mappings.CollectionMapping.getAdditionalFieldsBaseExpression.

INTERNAL: Return the base expression to use for adding fields to the query.
protected DataModifyQuery
protected ReadQuery
getExtendPessimisticLockScopeDedicatedQuery(AbstractSession session, short lockMode)

Overrides org.eclipse.persistence.mappings.ForeignReferenceMapping.getExtendPessimisticLockScopeDedicatedQuery.

INTERNAL: Should be overridden by subclass that allows setting extendPessimisticLockScope to DEDICATED_QUERY.
public Collection<E>
getFieldsForTranslationInAggregate()

Overrides org.eclipse.persistence.mappings.ForeignReferenceMapping.getFieldsForTranslationInAggregate.

INTERNAL: Return source key fields for translation by an AggregateObjectMapping
public HistoryPolicy
getHistoryPolicy()

PUBLIC: Allows history tracking on the m-m join table.

protected DataModifyQuery
public Expression
getJoinCriteria(ObjectExpression context, Expression base)

Overrides org.eclipse.persistence.mappings.CollectionMapping.getJoinCriteria.

INTERNAL: Returns the join criteria stored in the mapping selection query.
public DatabaseTable
getRelationTable()

INTERNAL: Return the relation table associated with the mapping.

public RelationTableMechanism
getRelationTableMechanism()

PUBLIC: Returns RelationTableMechanism that may be owned by the mapping.

public String
getRelationTableName()

PUBLIC: Return the relation table name associated with the mapping.

public String
getRelationTableQualifiedName()

PUBLIC: Return the relation table qualified name associated with the mapping.

public Vector<E>
getSourceKeyFieldNames()

PUBLIC: Return the source key field names associated with the mapping.

public Vector<DatabaseField>
getSourceKeyFields()

INTERNAL: Return all the source key fields associated with the mapping.

public Vector<E>
getSourceRelationKeyFieldNames()

PUBLIC: Return the source relation key field names associated with the mapping.

public Vector<DatabaseField>
getSourceRelationKeyFields()

INTERNAL: Return all the source relation key fields associated with the mapping.

public Vector<E>
getTargetKeyFieldNames()

PUBLIC: Return the target key field names associated with the mapping.

public Vector<DatabaseField>
getTargetKeyFields()

INTERNAL: Return all the target keys associated with the mapping.

public Vector<E>
getTargetRelationKeyFieldNames()

PUBLIC: Return the target relation key field names associated with the mapping.

public Vector<DatabaseField>
getTargetRelationKeyFields()

INTERNAL: Return all the target relation key fields associated with the mapping.

protected boolean
protected boolean
public boolean
hasDependency()

Overrides org.eclipse.persistence.mappings.ForeignReferenceMapping.hasDependency.

INTERNAL: The join table is a dependency if not read-only.
public void
protected void
protected void
initializeDeleteAllQuery(AbstractSession session)

Initialize delete all query.

protected void
protected void
initializeSelectionCriteriaAndAddFieldsToQuery(Expression startCriteria)

INTERNAL: Selection criteria is created to read target records from the table.

protected void
insertAddedObjectEntry(ObjectLevelModifyQuery query, Object objectAdded, Map<K, V> extraData)

INTERNAL: An object was added to the collection during an update, insert it.

public void
insertIntoRelationTable(WriteObjectQuery query)

INTERNAL: Insert into relation table.

public void
insertTargetObjects(WriteObjectQuery query)

INTERNAL: Write the target objects if the cascade policy requires them to be written first.

public boolean
isDefinedAsOneToManyMapping()

INTERNAL: Return whether this mapping was originally defined as a OneToMany.

public boolean
isJoiningSupported()

Overrides org.eclipse.persistence.mappings.ForeignReferenceMapping.isJoiningSupported.

INTERNAL: Return if this mapping support joining.
public boolean
isManyToManyMapping()

Overrides org.eclipse.persistence.mappings.DatabaseMapping.isManyToManyMapping.

INTERNAL: Related mapping should implement this method to return true.
public boolean
public boolean
protected void
objectAddedDuringUpdate(ObjectLevelModifyQuery query, Object objectAdded, ObjectChangeSet changeSet, Map<K, V> extraData)

Overrides org.eclipse.persistence.mappings.CollectionMapping.objectAddedDuringUpdate.

INTERNAL: An object was added to the collection during an update, insert it if private.
protected void
protected void
objectRemovedDuringUpdate(ObjectLevelModifyQuery query, Object objectDeleted, Map<K, V> extraData)

Overrides org.eclipse.persistence.mappings.CollectionMapping.objectRemovedDuringUpdate.

INTERNAL: An object was removed to the collection during an update, delete it if private.
public void
public void
postInitialize(AbstractSession session)

Overrides org.eclipse.persistence.mappings.CollectionMapping.postInitialize.

INTERNAL: Ensure the container policy is post initialized
public void
postInsert(WriteObjectQuery query)

Overrides org.eclipse.persistence.mappings.CollectionMapping.postInsert.

INTERNAL: Insert into relation table.
protected void
public void
postUpdate(WriteObjectQuery query)

Overrides org.eclipse.persistence.mappings.DatabaseMapping.postUpdate.

INTERNAL: Update the relation table with the entries related to this mapping.
public void
preDelete(DeleteObjectQuery query)

Overrides org.eclipse.persistence.mappings.DatabaseMapping.preDelete.

INTERNAL: Delete entries related to this mapping from the relation table.
protected ReadQuery
prepareHistoricalQuery(ReadQuery targetQuery, ObjectBuildingQuery sourceQuery, AbstractSession executionSession)

Overrides org.eclipse.persistence.mappings.ForeignReferenceMapping.prepareHistoricalQuery.

INTERNAL: Append the temporal selection to the query selection criteria.
protected void
prepareTranslationRow(AbstractRecord translationRow, Object object, ClassDescriptor descriptor, AbstractSession session)

Overrides org.eclipse.persistence.mappings.CollectionMapping.prepareTranslationRow.

INTERNAL: The translation row may require additional fields than the primary key if the mapping in not on the primary key.
public void
setCustomDeleteQuery(DataModifyQuery query)

PUBLIC: The default delete query for mapping can be overridden by specifying the new query.

public void
setCustomInsertQuery(DataModifyQuery query)

PUBLIC: The default insert query for mapping can be overridden by specifying the new query.

public void
setDefinedAsOneToManyMapping(boolean isDefinedAsOneToManyMapping)

INTERNAL: Set whether this mapping was originally defined as a OneToMany

public void
setDeleteCall(Call call)

PUBLIC: Set the receiver's delete Call.

protected void
public void
setDeleteSQLString(String sqlString)

PUBLIC: Set the receiver's delete SQL string.

public void
setHistoryPolicy(HistoryPolicy policy)

PUBLIC: Enable history tracking on the m-m join table.

public void
setInsertCall(Call call)

PUBLIC: Set the receiver's insert Call.

protected void
public void
setInsertSQLString(String sqlString)

PUBLIC: Set the receiver's insert SQL string.

public void
setRelationTable(DatabaseTable relationTable)

PUBLIC: Set the relational table.

pack-priv void
setRelationTableMechanism(RelationTableMechanism mechanism)

PUBLIC: Allows to set RelationTableMechanism to be owned by the mapping.

public void
setRelationTableName(String tableName)

PUBLIC: Set the name of the relational table.

public void
setSessionName(String name)

Overrides org.eclipse.persistence.mappings.CollectionMapping.setSessionName.

PUBLIC: Set the name of the session to execute the mapping's queries under.
public void
setSourceKeyFieldNames(Vector<E> fieldNames)

PUBLIC: Set the source key field names associated with the mapping.

public void
setSourceKeyFields(Vector<DatabaseField> sourceKeyFields)

INTERNAL: Set the source fields.

public void
setSourceRelationKeyFieldName(String sourceRelationKeyFieldName)

PUBLIC: Set the source key field in the relation table.

public void
setSourceRelationKeyFieldNames(Vector<E> fieldNames)

PUBLIC: Set the source relation key field names associated with the mapping.

public void
setSourceRelationKeyFields(Vector<DatabaseField> sourceRelationKeyFields)

INTERNAL: Set the source fields.

public void
setTargetKeyFieldNames(Vector<E> fieldNames)

INTERNAL: Set the target key field names associated with the mapping.

public void
setTargetKeyFields(Vector<DatabaseField> targetKeyFields)

INTERNAL: Set the target fields.

public void
setTargetRelationKeyFieldName(String targetRelationKeyFieldName)

PUBLIC: Set the target key field in the relation table.

public void
setTargetRelationKeyFieldNames(Vector<E> fieldNames)

INTERNAL: Set the target relation key field names associated with the mapping.

public void
setTargetRelationKeyFields(Vector<DatabaseField> targetRelationKeyFields)

INTERNAL: Set the target fields.

public boolean
shouldUseListOrderFieldTableExpression()

Overrides org.eclipse.persistence.mappings.CollectionMapping.shouldUseListOrderFieldTableExpression.

INTERNAL: Indicates whether getListOrderFieldExpression method should create field expression on table expression.
Inherited from org.eclipse.persistence.mappings.CollectionMapping:
addAggregateOrderByaddAscendingOrderingaddDescendingOrderingaddOrderBybuildBackupCloneForPartObjectbuildChangeRecordbuildCloneForPartObjectbuildContainerClonebuildCopybuildElementClonebuildElementUnitOfWorkClonebuildExpressionbuildReferencesPKListcalculateDeferredChangescascadeDiscoverAndPersistUnregisteredNewObjectscascadePerformRemoveIfRequiredcascadePerformRemovePrivateOwnedObjectFromChangeSetIfRequiredcascadeRegisterNewIfRequiredcompareCollectionsForChangecompareForChangecompareListscompareListsAndWritecompareObjectscompareObjectsAndWritecompareObjectsWithoutPrivateOwnedcompareObjectsWithPrivateOwnedconvertClassNamesToClassescopyElementexecuteBatchQueryextractResultFromBatchQueryfixRealObjectReferencesgetContainerPolicygetDeleteAllQuerygetListOrderFieldgetObjectCorrespondingTogetOrderByQueryKeyExpressionsgetOrderCorrectionTypegetRealCollectionAttributeValueFromObjectgetSelectionQueryContainerPolicygetTargetPrimaryKeyFieldshasCustomDeleteAllQueryhasOrderByinitializeListOrderFieldisAttributeValueInstantiatedOrChangedisChangeTrackingSupportedisCollectionMappingisListOrderFieldSupportedisMapKeyObjectRelationshipiterateOnElementiterateOnRealAttributeValueloadloadAllmergeChangesIntoObjectmergeIntoObjectmustDeleteReferenceObjectsOneByOneobjectUnchangedDuringUpdateobjectUnchangedDuringUpdatepostCalculateChangespostDeletepreInsertpreUpdatereadPrivateOwnedForObjectrecordPrivateOwnedRemovalsreplaceValueHoldersInsetChangeListenersetContainerPolicysetCustomDeleteAllQuerysetDeleteAllCallsetDeleteAllQuerysetDeleteAllSQLStringsetHasCustomDeleteAllQuerysetListOrderFieldsetListOrderFieldNamesetMustDeleteReferenceObjectsOneByOnesetOrderCorrectionTypesetSelectionQueryContainerPolicysetUseLazyInstantiationForIndirectCollectionshouldUseLazyInstantiationForIndirectCollectionsimpleAddToCollectionChangeRecordsimpleRemoveFromCollectionChangeRecordupdateChangeRecordupdateChangeRecordForSelfMergeupdateCollectionChangeRecorduseCollectionClassuseCollectionClassNameuseListClassNameuseMapClassuseMapClassuseMapClassNameuseSortedSetClassuseSortedSetClassNameuseSortedSetClassNameuseTransparentCollectionuseTransparentListuseTransparentMapuseTransparentSetvalidateBeforeInitializationvalueFromPKListvalueFromRowInternalWithJoinverifyDeletewriteChanges