Class RelationshipManagerImpl
java.lang.Object
org.datanucleus.state.RelationshipManagerImpl
- All Implemented Interfaces:
RelationshipManager
Manager for (bidirectional) relationships of an object (StateManager).
Designed as a stand-alone process to run just before flush.
Updates on bidirectional relations are registered during the persistence process.
Call to checkConsistency() will check for consistency and throw exceptions as appropriate.
Call to process() will perform updates at the other side of the registered relations so all is consistent.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumprivate static classDefinition of a change in a relation. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ExecutionContext(package private) final Map<Integer, List<RelationshipManagerImpl.RelationChange>> Map of bidirectional field "changes", keyed by the absolute field number of the owner object.(package private) final DNStateManagerStateManager for the object we are managing the relationships for.(package private) final ObjectObject being managed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidMethod to check for consistency the managed relations of this object with the related objects.protected voidcheckManyToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to check consistency of the passed field as M-N.protected voidcheckManyToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to check the consistency of the passed field as N-1.protected voidcheckOneToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to check the consistency of the passed field as 1-N.protected voidcheckOneToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to check the consistency of the passed field as 1-1.voidConvenience method to clear all fields from being managed.booleanmanagesField(int fieldNumber) Accessor for whether a field is being managed.voidprocess()Method to process the (bidirectional) relations for this object.protected voidprocessManyToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to process all M-N bidirectional fields.protected voidprocessManyToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to process all N-1 bidirectional fields.protected voidprocessOneToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to process all 1-N bidirectional fields.protected voidprocessOneToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to process all 1-1 bidir fields.voidrelationAdd(int fieldNumber, Object val) Method to register a change in the contents of a container field, with an object being added.voidrelationChange(int fieldNumber, Object oldValue, Object newValue) Method that is called when the user calls setXXX() on a field.voidrelationRemove(int fieldNumber, Object val) Method to register a change in the contents of a container field, with an object being removed.
-
Field Details
-
ownerSM
StateManager for the object we are managing the relationships for. -
ec
-
pc
Object being managed. -
fieldChanges
Map of bidirectional field "changes", keyed by the absolute field number of the owner object.
-
-
Constructor Details
-
RelationshipManagerImpl
Constructor.- Parameters:
sm- StateManager for the object that we are managing relations for.
-
-
Method Details
-
clearFields
public void clearFields()Description copied from interface:RelationshipManagerConvenience method to clear all fields from being managed.- Specified by:
clearFieldsin interfaceRelationshipManager
-
relationChange
Description copied from interface:RelationshipManagerMethod that is called when the user calls setXXX() on a field.- Specified by:
relationChangein interfaceRelationshipManager- Parameters:
fieldNumber- Number of the fieldoldValue- The old valuenewValue- The new value
-
relationAdd
Description copied from interface:RelationshipManagerMethod to register a change in the contents of a container field, with an object being added.- Specified by:
relationAddin interfaceRelationshipManager- Parameters:
fieldNumber- Number of the fieldval- Value being added
-
relationRemove
Description copied from interface:RelationshipManagerMethod to register a change in the contents of a container field, with an object being removed.- Specified by:
relationRemovein interfaceRelationshipManager- Parameters:
fieldNumber- Number of the fieldval- Value being removed
-
managesField
public boolean managesField(int fieldNumber) Accessor for whether a field is being managed.- Specified by:
managesFieldin interfaceRelationshipManager- Parameters:
fieldNumber- Number of the field- Returns:
- Whether it is currently managed
-
checkConsistency
public void checkConsistency()Description copied from interface:RelationshipManagerMethod to check for consistency the managed relations of this object with the related objects.- Specified by:
checkConsistencyin interfaceRelationshipManager
-
process
public void process()Description copied from interface:RelationshipManagerMethod to process the (bidirectional) relations for this object.- Specified by:
processin interfaceRelationshipManager
-
checkOneToOneBidirectionalRelation
protected void checkOneToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to check the consistency of the passed field as 1-1. Processes the case where we had a 1-1 field set at this side previously to some value and now to some other value. We need to make sure that all of the affected objects are now related consistently. Taking an examplea.b = b1; a.b = b2;
so A's b field is changed from b1 to b2. The following changes are likely to be necessary- b1.a = null - so we null out the old related objects link back to this object
- b2.oldA = null - if b2 was previously related to a different A, null out that objects link to b2
- b2.a = a - set the link from b2 back to a so it is bidirectional
- Parameters:
mmd- MetaData for the fieldclr- ClassLoader resolverec- ExecutionContextchanges- List of changes to the field
-
checkOneToManyBidirectionalRelation
protected void checkOneToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to check the consistency of the passed field as 1-N.- Parameters:
mmd- MetaData for the fieldclr- ClassLoader resolverec- ExecutionContextchanges- List of changes to the collection
-
checkManyToOneBidirectionalRelation
protected void checkManyToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to check the consistency of the passed field as N-1. Processes the case where we had an N-1 field set at this side previously to some value and now to some other value.That is, this object was in some collection/map originally, and now should be in some other collection/map. So in terms of an example this object "a" was in collection "b1.as" before and is now in "b2.as". The following changes are likely to be necessary- b1.getAs().remove(a) - remove it from b1.as if still present
- b2.getAs().add(a) - add it to b1.as if not present
- Parameters:
mmd- MetaData for the fieldclr- ClassLoader resolverec- ExecutionContextchanges- List of changes to the field
-
checkManyToManyBidirectionalRelation
protected void checkManyToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to check consistency of the passed field as M-N.- Parameters:
mmd- MetaData for the fieldclr- ClassLoader resolverec- ExecutionContextchanges- List of changes to the collection
-
processOneToOneBidirectionalRelation
protected void processOneToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to process all 1-1 bidir fields. Processes the case where we had a 1-1 field set at this side previously to some value and now to some other value. We need to make sure that all of the affected objects are now related consistently. Taking an examplea.b = b1; a.b = b2;
so A's b field is changed from b1 to b2. The following changes are likely to be necessary- b1.a = null - so we null out the old related objects link back to this object
- b2.oldA = null - if b2 was previously related to a different A, null out that objects link to b2
- b2.a = a - set the link from b2 back to a so it is bidirectional
- Parameters:
mmd- MetaData for the fieldclr- ClassLoader resolverec- ExecutionContextchanges- List of changes to the field
-
processOneToManyBidirectionalRelation
protected void processOneToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to process all 1-N bidirectional fields.- Parameters:
mmd- MetaData for the fieldclr- ClassLoader resolverec- ExecutionContextchanges- List of changes to the collection
-
processManyToOneBidirectionalRelation
protected void processManyToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to process all N-1 bidirectional fields. Processes the case where we had an N-1 field set at this side previously to some value and now to some other value.That is, this object was in some collection/map originally, and now should be in some other collection/map. So in terms of an example this object "a" was in collection "b1.as" before and is now in "b2.as". The following changes are likely to be necessary- b1.getAs().remove(a) - remove it from b1.as if still present
- b2.getAs().add(a) - add it to b1.as if not present
- Parameters:
mmd- MetaData for the fieldclr- ClassLoader resolverec- ExecutionContextchanges- List of changes to the collection
-
processManyToManyBidirectionalRelation
protected void processManyToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<RelationshipManagerImpl.RelationChange> changes) Method to process all M-N bidirectional fields.- Parameters:
mmd- MetaData for the fieldclr- ClassLoader resolverec- ExecutionContextchanges- List of changes to the collection
-