- java.lang.Object
-
- org.datanucleus.state.RelationshipManagerImpl
-
- All Implemented Interfaces:
RelationshipManager
public class RelationshipManagerImpl extends Object implements 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.
-
-
Constructor Summary
Constructors Constructor Description RelationshipManagerImpl(DNStateManager sm)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkConsistency()
Method to check for consistency the managed relations of this object with the related objects.protected void
checkManyToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<org.datanucleus.state.RelationshipManagerImpl.RelationChange> changes)
Method to check consistency of the passed field as M-N.protected void
checkManyToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<org.datanucleus.state.RelationshipManagerImpl.RelationChange> changes)
Method to check the consistency of the passed field as N-1.protected void
checkOneToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<org.datanucleus.state.RelationshipManagerImpl.RelationChange> changes)
Method to check the consistency of the passed field as 1-N.protected void
checkOneToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<org.datanucleus.state.RelationshipManagerImpl.RelationChange> changes)
Method to check the consistency of the passed field as 1-1.void
clearFields()
Convenience method to clear all fields from being managed.boolean
managesField(int fieldNumber)
Accessor for whether a field is being managed.void
process()
Method to process the (bidirectional) relations for this object.protected void
processManyToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<org.datanucleus.state.RelationshipManagerImpl.RelationChange> changes)
Method to process all M-N bidirectional fields.protected void
processManyToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<org.datanucleus.state.RelationshipManagerImpl.RelationChange> changes)
Method to process all N-1 bidirectional fields.protected void
processOneToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<org.datanucleus.state.RelationshipManagerImpl.RelationChange> changes)
Method to process all 1-N bidirectional fields.protected void
processOneToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<org.datanucleus.state.RelationshipManagerImpl.RelationChange> changes)
Method to process all 1-1 bidir fields.void
relationAdd(int fieldNumber, Object val)
Method to register a change in the contents of a container field, with an object being added.void
relationChange(int fieldNumber, Object oldValue, Object newValue)
Method that is called when the user calls setXXX() on a field.void
relationRemove(int fieldNumber, Object val)
Method to register a change in the contents of a container field, with an object being removed.
-
-
-
Constructor Detail
-
RelationshipManagerImpl
public RelationshipManagerImpl(DNStateManager sm)
Constructor.- Parameters:
sm
- StateManager for the object that we are managing relations for.
-
-
Method Detail
-
clearFields
public void clearFields()
Description copied from interface:RelationshipManager
Convenience method to clear all fields from being managed.- Specified by:
clearFields
in interfaceRelationshipManager
-
relationChange
public void relationChange(int fieldNumber, Object oldValue, Object newValue)
Description copied from interface:RelationshipManager
Method that is called when the user calls setXXX() on a field.- Specified by:
relationChange
in interfaceRelationshipManager
- Parameters:
fieldNumber
- Number of the fieldoldValue
- The old valuenewValue
- The new value
-
relationAdd
public void relationAdd(int fieldNumber, Object val)
Description copied from interface:RelationshipManager
Method to register a change in the contents of a container field, with an object being added.- Specified by:
relationAdd
in interfaceRelationshipManager
- Parameters:
fieldNumber
- Number of the fieldval
- Value being added
-
relationRemove
public void relationRemove(int fieldNumber, Object val)
Description copied from interface:RelationshipManager
Method to register a change in the contents of a container field, with an object being removed.- Specified by:
relationRemove
in 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:
managesField
in interfaceRelationshipManager
- Parameters:
fieldNumber
- Number of the field- Returns:
- Whether it is currently managed
-
checkConsistency
public void checkConsistency()
Description copied from interface:RelationshipManager
Method to check for consistency the managed relations of this object with the related objects.- Specified by:
checkConsistency
in interfaceRelationshipManager
-
process
public void process()
Description copied from interface:RelationshipManager
Method to process the (bidirectional) relations for this object.- Specified by:
process
in interfaceRelationshipManager
-
checkOneToOneBidirectionalRelation
protected void checkOneToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ExecutionContext ec, List<org.datanucleus.state.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<org.datanucleus.state.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<org.datanucleus.state.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<org.datanucleus.state.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<org.datanucleus.state.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<org.datanucleus.state.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<org.datanucleus.state.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<org.datanucleus.state.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
-
-