public class ManyToManyMapping extends CollectionMapping implements RelationalMapping
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 require the creation of an intermediate table for managing the associations between the source and target records.
Modifier and Type | Field and Description |
---|---|
protected DataModifyQuery |
deleteQuery
Query used for single row deletion.
|
protected boolean |
hasCustomDeleteQuery |
protected boolean |
hasCustomInsertQuery |
protected DataModifyQuery |
insertQuery
Used for insertion.
|
protected static String |
ObjectAdded |
protected static String |
ObjectRemoved |
protected static String |
PostInsert
Used for data modification events.
|
protected DatabaseTable |
relationTable
The intermediate relation table.
|
protected Vector<DatabaseField> |
sourceKeyFields
The field in the source table that corresponds to the key in the relation table
|
protected Vector<DatabaseField> |
sourceRelationKeyFields
The field in the intermediate table that corresponds to the key in the source table
|
protected Vector<DatabaseField> |
targetKeyFields
The field in the target table that corresponds to the key in the relation table
|
protected Vector<DatabaseField> |
targetRelationKeyFields
The field in the intermediate table that corresponds to the key in the target table
|
containerPolicy, deleteAllQuery, hasCustomDeleteAllQuery, hasOrderBy
cascadeMerge, cascadePersist, cascadeRefresh, cascadeRemove, hasCustomSelectionQuery, indirectionPolicy, isPrivateOwned, referenceClass, referenceClassName, referenceDescriptor, relationshipPartner, relationshipPartnerAttributeName, selectionQuery, tempInitSession
attributeAccessor, descriptor, fields, isOptional, isReadOnly, isRemotelyInitialized, NO_FIELDS, NO_WEIGHT, primaryKeyMapping, properties, weight, WEIGHT_1
Constructor and Description |
---|
ManyToManyMapping()
PUBLIC:
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addSourceRelationKeyField(DatabaseField sourceRelationKeyField,
DatabaseField sourcePrimaryKeyField)
PUBLIC:
Add the fields in the intermediate table that corresponds to the primary
key in the source table.
|
void |
addSourceRelationKeyFieldName(String sourceRelationKeyFieldName,
String sourcePrimaryKeyFieldName)
PUBLIC:
Add the fields in the intermediate table that corresponds to the primary
key in the source table.
|
void |
addTargetRelationKeyField(DatabaseField targetRelationKeyField,
DatabaseField targetPrimaryKeyField)
PUBLIC:
Add the fields in the intermediate table that corresponds to the primary
key in the target table.
|
void |
addTargetRelationKeyFieldName(String targetRelationKeyFieldName,
String targetPrimaryKeyFieldName)
PUBLIC:
Add the fields in the intermediate table that corresponds to the primary
key in the target table.
|
Object |
clone()
INTERNAL:
The mapping clones itself to create deep copy.
|
protected Vector |
extractKeyFromRelationRow(AbstractRecord row,
AbstractSession session)
INTERNAL:
Extract the source primary key value from the relation row.
|
protected Vector |
extractPrimaryKeyFromRow(AbstractRecord row,
AbstractSession session)
INTERNAL:
Extract the primary key value from the source row.
|
protected DataModifyQuery |
getDeleteQuery() |
protected DataModifyQuery |
getInsertQuery() |
DatabaseTable |
getRelationTable()
INTERNAL:
Return the relation table associated with the mapping.
|
String |
getRelationTableName()
PUBLIC:
Return the relation table name associated with the mapping.
|
String |
getRelationTableQualifiedName()
PUBLIC:
Return the relation table qualified name associated with the mapping.
|
Expression |
getSelectionCriteria()
INTERNAL:
Returns the selection criteria stored in the mapping selection query.
|
ReadQuery |
getSelectionQuery()
INTERNAL:
Returns the read query assoicated with the mapping.
|
Vector |
getSourceKeyFieldNames()
PUBLIC:
Return the source key field names associated with the mapping.
|
Vector<DatabaseField> |
getSourceKeyFields()
INTERNAL:
Return all the source key fields associated with the mapping.
|
Vector |
getSourceRelationKeyFieldNames()
PUBLIC:
Return the source relation key field names associated with the mapping.
|
Vector<DatabaseField> |
getSourceRelationKeyFields()
INTERNAL:
Return all the source realtion key fields associated with the mapping.
|
Vector |
getTargetKeyFieldNames()
PUBLIC:
Return the target key field names associated with the mapping.
|
Vector<DatabaseField> |
getTargetKeyFields()
INTERNAL:
Return all the target keys associated with the mapping.
|
Vector |
getTargetRelationKeyFieldNames()
PUBLIC:
Return the target relation key field names associated with the mapping.
|
Vector<DatabaseField> |
getTargetRelationKeyFields()
INTERNAL:
Return all the target relation key fields associated with the mapping.
|
protected boolean |
hasCustomDeleteQuery() |
protected boolean |
hasCustomInsertQuery() |
boolean |
hasDependency()
INTERNAL:
The join table is a dependency if not read-only.
|
void |
initialize(AbstractSession session)
INTERNAL:
Initialize mappings
|
protected void |
initializeDeleteAllQuery(AbstractSession session)
Initialize delete all query.
|
protected void |
initializeDeleteQuery(AbstractSession session)
INTERNAL:
Initialize delete query.
|
protected void |
initializeInsertQuery(AbstractSession session)
INTERNAL:
Initialize insert query.
|
protected void |
initializeRelationTable(AbstractSession session)
INTERNAL:
Set the table qualifier on the relation table if required
|
protected void |
initializeSelectionCriteria(AbstractSession session)
INTERNAL:
Selection criteria is created to read target records from the table.
|
protected void |
initializeSourceKeys(AbstractSession session)
INTERNAL:
All the source key field names are converted to DatabaseField and stored.
|
protected void |
initializeSourceKeysWithDefaults(AbstractSession session)
INTERNAL:
If a user does not specify the source key then the primary keys of the source table are used.
|
protected void |
initializeSourceRelationKeys(AbstractSession session)
INTERNAL:
All the source relation key field names are converted to DatabaseField and stored.
|
protected void |
initializeTargetKeys(AbstractSession session)
INTERNAL:
All the target key field names are converted to DatabaseField and stored.
|
protected void |
initializeTargetKeysWithDefaults(AbstractSession session)
INTERNAL:
If a user does not specify the target key then the primary keys of the target table are used.
|
protected void |
initializeTargetRelationKeys(AbstractSession session)
INTERNAL:
All the target relation key field names are converted to DatabaseField and stored.
|
protected void |
insertAddedObjectEntry(ObjectLevelModifyQuery query,
Object objectAdded)
INTERNAL:
An object was added to the collection during an update, insert it.
|
void |
insertIntoRelationTable(WriteObjectQuery query)
INTERNAL:
Insert into relation table.
|
void |
insertTargetObjects(WriteObjectQuery query)
INTERNAL:
Write the target objects if the cascade policy requires them to be written first.
|
boolean |
isJoiningSupported()
INTERNAL:
Return if this mapping support joining.
|
boolean |
isManyToManyMapping()
INTERNAL:
|
boolean |
isRelationalMapping()
INTERNAL:
|
protected boolean |
isSingleSourceRelationKeySpecified()
INTERNAL:
Checks if a single source key was specified.
|
protected boolean |
isSingleTargetRelationKeySpecified()
INTERNAL:
Checks if a single target key was specified.
|
protected void |
objectAddedDuringUpdate(ObjectLevelModifyQuery query,
Object objectAdded,
ObjectChangeSet changeSet)
INTERNAL:
An object was added to the collection during an update, insert it if private.
|
protected void |
objectRemovedDuringUpdate(ObjectLevelModifyQuery query,
Object objectDeleted)
INTERNAL:
An object was removed to the collection during an update, delete it if private.
|
void |
performDataModificationEvent(Object[] event,
AbstractSession session)
INTERNAL:
Perform the commit event.
|
void |
postInsert(WriteObjectQuery query)
INTERNAL:
Insert into relation table.
|
void |
postUpdate(WriteObjectQuery query)
INTERNAL:
Update the relation table with the entries related to this mapping.
|
void |
preDelete(WriteObjectQuery query)
INTERNAL:
Delete entries related to this mapping from the relation table.
|
protected void |
prepareTranslationRow(AbstractRecord translationRow,
Object object,
AbstractSession session)
INTERNAL:
The translation row may require additional fields than the primary key if the mapping in not on the primary key.
|
void |
setCustomDeleteQuery(DataModifyQuery query)
PUBLIC:
The default delete query for mapping can be overridden by specifying the new query.
|
void |
setCustomInsertQuery(DataModifyQuery query)
PUBLIC:
The default insert query for mapping can be overridden by specifying the new query.
|
void |
setDeleteCall(Call call)
PUBLIC:
Set the receiver's delete Call.
|
protected void |
setDeleteQuery(DataModifyQuery deleteQuery) |
void |
setDeleteSQLString(String sqlString)
PUBLIC:
Set the receiver's delete SQL string.
|
protected void |
setHasCustomDeleteQuery(boolean hasCustomDeleteQuery) |
protected void |
setHasCustomInsertQuery(boolean bool) |
void |
setInsertCall(Call call)
PUBLIC:
Set the receiver's insert Call.
|
protected void |
setInsertQuery(DataModifyQuery insertQuery) |
void |
setInsertSQLString(String sqlString)
PUBLIC:
Set the receiver's insert SQL string.
|
void |
setRelationTable(DatabaseTable relationTable)
PUBLIC:
Set the relational table.
|
void |
setRelationTableName(String tableName)
PUBLIC:
Set the name of the relational table.
|
void |
setSessionName(String name)
PUBLIC:
Set the name of the session to execute the mapping's queries under.
|
void |
setSourceKeyFieldNames(Vector fieldNames)
PUBLIC:
Set the source key field names associated with the mapping.
|
void |
setSourceKeyFields(Vector<DatabaseField> sourceKeyFields)
INTERNAL:
Set the source fields.
|
void |
setSourceRelationKeyFieldName(String sourceRelationKeyFieldName)
PUBLIC:
Set the source key field in the relation table.
|
void |
setSourceRelationKeyFieldNames(Vector fieldNames)
PUBLIC:
Set the source relation key field names associated with the mapping.
|
void |
setSourceRelationKeyFields(Vector<DatabaseField> sourceRelationKeyFields)
INTERNAL:
Set the source fields.
|
void |
setTargetKeyFieldNames(Vector fieldNames)
INTERNAL:
Set the target key field names associated with the mapping.
|
void |
setTargetKeyFields(Vector<DatabaseField> targetKeyFields)
INTERNAL:
Set the target fields.
|
void |
setTargetRelationKeyFieldName(String targetRelationKeyFieldName)
PUBLIC:
Set the target key field in the relation table.
|
void |
setTargetRelationKeyFieldNames(Vector fieldNames)
INTERNAL:
Set the target relation key field names associated with the mapping.
|
void |
setTargetRelationKeyFields(Vector<DatabaseField> targetRelationKeyFields)
INTERNAL:
Set the target fields.
|
addAggregateOrderBy, addAscendingOrdering, addDescendingOrdering, addOrderBy, addToCollectionChangeRecord, buildBackupCloneForPartObject, buildChangeRecord, buildCloneForPartObject, buildCopy, buildElementClone, calculateDeferredChanges, cascadeMerge, cascadePerformRemoveIfRequired, cascadeRegisterNewIfRequired, compareCollectionsForChange, compareForChange, compareObjects, compareObjectsAndWrite, compareObjectsWithoutPrivateOwned, compareObjectsWithPrivateOwned, convertClassNamesToClasses, getContainerPolicy, getDeleteAllQuery, getRealAttributeValueFromObject, getRealCollectionAttributeValueFromObject, hasCustomDeleteAllQuery, hasOrderBy, isChangeTrackingSupported, isCollectionMapping, iterateOnElement, iterateOnRealAttributeValue, mergeChangesIntoObject, mergeIntoObject, objectUnchangedDuringUpdate, objectUnchangedDuringUpdate, readPrivateOwnedForObject, removeFromCollectionChangeRecord, setContainerPolicy, setCustomDeleteAllQuery, setDeleteAllCall, setDeleteAllQuery, setDeleteAllSQLString, setHasCustomDeleteAllQuery, shouldUseValueFromRowWithJoin, simpleAddToCollectionChangeRecord, simpleRemoveFromCollectionChangeRecord, updateChangeRecord, useCollectionClass, useMapClass, useMapClass, useSortedSetClass, useTransparentCollection, useTransparentList, useTransparentMap, useTransparentSet, validateBeforeInitialization, valueFromRowInternalWithJoin, verifyDelete
buildBackupClone, buildClone, buildCloneFromRow, createUnitOfWorkValueHolder, dontDoMerge, dontUseIndirection, getAttributeValueFromObject, getAttributeValueWithClonedValueHolders, getIndirectionPolicy, getJoinCriteria, getReferenceClass, getReferenceClassName, getReferenceDescriptor, getRelationshipPartner, getRelationshipPartnerAttributeName, getTempSession, hasCustomSelectionQuery, initializeReferenceDescriptor, initializeSelectionQuery, isAttributeValueInstantiated, isCascadeMerge, isCascadePersist, isCascadeRefresh, isCascadeRemove, isForeignReferenceMapping, isPrivateOwned, iterate, prepareHistoricalQuery, prepareNestedJoins, privateOwnedRelationship, setCascadeAll, setCascadeMerge, setCascadePersist, setCascadeRefresh, setCascadeRemove, setCustomSelectionQuery, setHasCustomSelectionQuery, setIndirectionPolicy, setIsPrivateOwned, setRealAttributeValueInObject, setReferenceClass, setReferenceClassName, setReferenceDescriptor, setRelationshipPartner, setRelationshipPartnerAttributeName, setSelectionCall, setSelectionCriteria, setSelectionQuery, setSelectionSQLString, setTempSession, setUsesIndirection, shouldInitializeSelectionCriteria, shouldMergeCascadeParts, shouldMergeCascadeReference, shouldObjectModifyCascadeToParts, shouldObjectModifyCascadeToPartsForPreDelete, trimRowForJoin, trimRowForJoin, useBasicIndirection, usesIndirection, useWeavedIndirection, valueFromRow, valueFromRowInternal
buildObjectJoinExpression, buildObjectJoinExpression, buildShallowOriginalFromRow, cloneFields, collectFields, extractNestedExpressions, getAttributeAccessor, getAttributeClassification, getAttributeName, getDescriptor, getField, getFieldClassification, getFields, getGetMethodName, getProperties, getProperty, getReferenceClassDescriptor, getSetMethodName, getWeight, hasConstraintDependency, hasInverseConstraintDependency, isAbstractCompositeCollectionMapping, isAbstractCompositeDirectCollectionMapping, isAbstractCompositeObjectMapping, isAbstractDirectMapping, isAggregateCollectionMapping, isAggregateMapping, isAggregateObjectMapping, isCascadedLockingSupported, isCloningRequired, isDatabaseMapping, isDirectCollectionMapping, isDirectMapMapping, isDirectToFieldMapping, isDirectToXMLTypeMapping, isEISMapping, isNestedTableMapping, isObjectReferenceMapping, isObjectTypeMapping, isOneToManyMapping, isOneToOneMapping, isOptional, isPrimaryKeyMapping, isReadOnly, isReferenceMapping, isRemotelyInitialized, isSerializedObjectMapping, isStructureMapping, isTransformationMapping, isTypeConversionMapping, isUsingMethodAccess, isVariableOneToOneMapping, isWriteOnly, isXMLMapping, postDelete, postInitialize, preInitialize, preInsert, prepareCascadeLockingPolicy, preUpdate, readFromRowIntoObject, readFromRowIntoObject, readOnly, readWrite, rehashFieldDependancies, setAttributeAccessor, setAttributeName, setAttributeValueInObject, setDescriptor, setFields, setGetMethodName, setIsOptional, setIsPrimaryKeyMapping, setIsReadOnly, setProperties, setProperty, setSetMethodName, setWeight, toString, validateAfterInitialization, valueFromObject, valueFromRow, writeFromAttributeIntoRow, writeFromObjectIntoRow, writeFromObjectIntoRowForShallowDelete, writeFromObjectIntoRowForShallowInsert, writeFromObjectIntoRowForShallowInsertWithChangeRecord, writeFromObjectIntoRowForUpdate, writeFromObjectIntoRowForWhereClause, writeFromObjectIntoRowWithChangeRecord, writeInsertFieldsIntoRow, writeUpdateFieldsIntoRow
protected static final String PostInsert
protected static final String ObjectRemoved
protected static final String ObjectAdded
protected transient DatabaseTable relationTable
protected transient Vector<DatabaseField> sourceKeyFields
protected transient Vector<DatabaseField> targetKeyFields
protected transient Vector<DatabaseField> sourceRelationKeyFields
protected transient Vector<DatabaseField> targetRelationKeyFields
protected transient DataModifyQuery deleteQuery
protected transient boolean hasCustomDeleteQuery
protected transient DataModifyQuery insertQuery
protected transient boolean hasCustomInsertQuery
public boolean isRelationalMapping()
isRelationalMapping
in class DatabaseMapping
public void addSourceRelationKeyField(DatabaseField sourceRelationKeyField, DatabaseField sourcePrimaryKeyField)
public void addSourceRelationKeyFieldName(String sourceRelationKeyFieldName, String sourcePrimaryKeyFieldName)
public void addTargetRelationKeyField(DatabaseField targetRelationKeyField, DatabaseField targetPrimaryKeyField)
public void addTargetRelationKeyFieldName(String targetRelationKeyFieldName, String targetPrimaryKeyFieldName)
public Object clone()
clone
in class ForeignReferenceMapping
protected Vector extractKeyFromRelationRow(AbstractRecord row, AbstractSession session)
protected Vector extractPrimaryKeyFromRow(AbstractRecord row, AbstractSession session)
protected DataModifyQuery getDeleteQuery()
protected DataModifyQuery getInsertQuery()
public DatabaseTable getRelationTable()
public String getRelationTableName()
public String getRelationTableQualifiedName()
public Expression getSelectionCriteria()
getSelectionCriteria
in class ForeignReferenceMapping
public ReadQuery getSelectionQuery()
getSelectionQuery
in class ForeignReferenceMapping
public Vector getSourceKeyFieldNames()
public Vector<DatabaseField> getSourceKeyFields()
public Vector getSourceRelationKeyFieldNames()
public Vector<DatabaseField> getSourceRelationKeyFields()
public Vector getTargetKeyFieldNames()
public Vector<DatabaseField> getTargetKeyFields()
public Vector getTargetRelationKeyFieldNames()
public Vector<DatabaseField> getTargetRelationKeyFields()
protected boolean hasCustomDeleteQuery()
protected boolean hasCustomInsertQuery()
public boolean hasDependency()
hasDependency
in class DatabaseMapping
public void initialize(AbstractSession session) throws DescriptorException
initialize
in class CollectionMapping
DescriptorException
protected void initializeDeleteAllQuery(AbstractSession session)
protected void initializeDeleteQuery(AbstractSession session)
protected void initializeInsertQuery(AbstractSession session)
protected void initializeRelationTable(AbstractSession session) throws DescriptorException
DescriptorException
protected void initializeSelectionCriteria(AbstractSession session)
protected void initializeSourceKeys(AbstractSession session)
protected void initializeSourceKeysWithDefaults(AbstractSession session)
protected void initializeSourceRelationKeys(AbstractSession session) throws DescriptorException
DescriptorException
protected void initializeTargetKeys(AbstractSession session)
protected void initializeTargetKeysWithDefaults(AbstractSession session)
protected void initializeTargetRelationKeys(AbstractSession session)
protected void insertAddedObjectEntry(ObjectLevelModifyQuery query, Object objectAdded) throws DatabaseException, OptimisticLockException
public void insertIntoRelationTable(WriteObjectQuery query) throws DatabaseException
- 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.
DatabaseException
public void insertTargetObjects(WriteObjectQuery query) throws DatabaseException, OptimisticLockException
public boolean isJoiningSupported()
isJoiningSupported
in class DatabaseMapping
public boolean isManyToManyMapping()
isManyToManyMapping
in class DatabaseMapping
protected boolean isSingleSourceRelationKeySpecified()
protected boolean isSingleTargetRelationKeySpecified()
protected void objectAddedDuringUpdate(ObjectLevelModifyQuery query, Object objectAdded, ObjectChangeSet changeSet) throws DatabaseException, OptimisticLockException
objectAddedDuringUpdate
in class CollectionMapping
DatabaseException
OptimisticLockException
protected void objectRemovedDuringUpdate(ObjectLevelModifyQuery query, Object objectDeleted) throws DatabaseException, OptimisticLockException
objectRemovedDuringUpdate
in class CollectionMapping
DatabaseException
OptimisticLockException
public void performDataModificationEvent(Object[] event, AbstractSession session) throws DatabaseException, DescriptorException
performDataModificationEvent
in class DatabaseMapping
DatabaseException
DescriptorException
public void postInsert(WriteObjectQuery query) throws DatabaseException
- 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.
postInsert
in class DatabaseMapping
DatabaseException
public void postUpdate(WriteObjectQuery query) throws DatabaseException
postUpdate
in class DatabaseMapping
DatabaseException
public void preDelete(WriteObjectQuery query) throws DatabaseException
preDelete
in class DatabaseMapping
DatabaseException
protected void prepareTranslationRow(AbstractRecord translationRow, Object object, AbstractSession session)
prepareTranslationRow
in class CollectionMapping
public void setCustomDeleteQuery(DataModifyQuery query)
public void setCustomInsertQuery(DataModifyQuery query)
protected void setDeleteQuery(DataModifyQuery deleteQuery)
public void setDeleteSQLString(String sqlString)
public void setDeleteCall(Call call)
protected void setHasCustomDeleteQuery(boolean hasCustomDeleteQuery)
protected void setHasCustomInsertQuery(boolean bool)
protected void setInsertQuery(DataModifyQuery insertQuery)
public void setInsertSQLString(String sqlString)
public void setInsertCall(Call call)
public void setRelationTable(DatabaseTable relationTable)
public void setRelationTableName(String tableName)
public void setSessionName(String name)
setSessionName
in class CollectionMapping
public void setSourceKeyFieldNames(Vector fieldNames)
public void setSourceKeyFields(Vector<DatabaseField> sourceKeyFields)
public void setSourceRelationKeyFieldName(String sourceRelationKeyFieldName)
public void setSourceRelationKeyFieldNames(Vector fieldNames)
public void setSourceRelationKeyFields(Vector<DatabaseField> sourceRelationKeyFields)
public void setTargetKeyFieldNames(Vector fieldNames)
public void setTargetKeyFields(Vector<DatabaseField> targetKeyFields)
public void setTargetRelationKeyFieldName(String targetRelationKeyFieldName)
public void setTargetRelationKeyFieldNames(Vector fieldNames)
public void setTargetRelationKeyFields(Vector<DatabaseField> targetRelationKeyFields)
Copyright © 2023. All rights reserved.