org.datanucleus.state
Class RelationshipManager

java.lang.Object
  extended by org.datanucleus.state.RelationshipManager

public class RelationshipManager
extends java.lang.Object

Manager for relationships of a class. Performs management of (bidirectional) relations. If one side is set yet the other isn't, corrects the other side.


Field Summary
protected static Localiser LOCALISER
          Localiser for messages.
 
Constructor Summary
RelationshipManager(StateManager sm)
          Constructor.
 
Method Summary
 void checkConsistency()
          Method to check for consistency the managed relations of this object with the related objects.
protected  void checkManyToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ObjectManager om, java.util.List<org.datanucleus.state.RelationshipManager.RelationChange> changes)
          Method to check consistency of the passed field as M-N.
protected  void checkManyToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ObjectManager om, java.lang.Object oldValue, java.lang.Object newValue)
          Method to check the consistency of the passed field as N-1.
protected  void checkOneToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ObjectManager om, java.util.List<org.datanucleus.state.RelationshipManager.RelationChange> changes)
          Method to check the consistency of the passed field as 1-N.
protected  void checkOneToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ObjectManager om, java.lang.Object oldValue, java.lang.Object newValue)
          Method to check the consistency of the passed field as 1-1.
 void clearFields()
          Convenience method to clear all fields from being managed.
 void process()
          Method to process the (bidirectional) relations for this object.
protected  void processManyToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ObjectManager om, java.util.List<org.datanucleus.state.RelationshipManager.RelationChange> changes)
          Method to process all M-N bidirectional fields.
protected  void processManyToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ObjectManager om, java.lang.Object oldValue, java.lang.Object newValue)
          Method to process all N-1 bidirectional fields.
protected  void processOneToManyBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ObjectManager om, java.util.List<org.datanucleus.state.RelationshipManager.RelationChange> changes)
          Method to process all 1-N bidirectional fields.
protected  void processOneToOneBidirectionalRelation(AbstractMemberMetaData mmd, ClassLoaderResolver clr, ObjectManager om, java.lang.Object oldValue, java.lang.Object newValue)
          Method to process all 1-1 bidir fields.
 void relationAdd(int fieldNumber, java.lang.Object val)
          Method to register a change in the contents of a container field, with an object being added.
 void relationChange(int fieldNumber, java.lang.Object oldValue, java.lang.Object newValue)
          Method that is called when the user calls setXXX() on a field.
 void relationRemove(int fieldNumber, java.lang.Object val)
          Method to register a change in the contents of a container field, with an object being removed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localiser for messages.

Constructor Detail

RelationshipManager

public RelationshipManager(StateManager sm)
Constructor.

Parameters:
sm - StateManager for the object that we are managing relations for.
Method Detail

clearFields

public void clearFields()
Convenience method to clear all fields from being managed.


relationChange

public void relationChange(int fieldNumber,
                           java.lang.Object oldValue,
                           java.lang.Object newValue)
Method that is called when the user calls setXXX() on a field.

Parameters:
fieldNumber - Number of the field
oldValue - The old value
newValue - The new value

relationAdd

public void relationAdd(int fieldNumber,
                        java.lang.Object val)
Method to register a change in the contents of a container field, with an object being added.

Parameters:
fieldNumber - Number of the field
val - Value being added

relationRemove

public void relationRemove(int fieldNumber,
                           java.lang.Object val)
Method to register a change in the contents of a container field, with an object being removed.

Parameters:
fieldNumber - Number of the field
val - Value being removed

checkConsistency

public void checkConsistency()
Method to check for consistency the managed relations of this object with the related objects.


process

public void process()
Method to process the (bidirectional) relations for this object.


checkOneToOneBidirectionalRelation

protected void checkOneToOneBidirectionalRelation(AbstractMemberMetaData mmd,
                                                  ClassLoaderResolver clr,
                                                  ObjectManager om,
                                                  java.lang.Object oldValue,
                                                  java.lang.Object newValue)
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 example
a.b = b1; a.b = b2;
so A's b field is changed from b1 to b2. The following changes are likely to be necessary

Parameters:
mmd - MetaData for the field
clr - ClassLoader resolver
om - ObjectManager
oldValue - The old value
newValue - The new value

checkOneToManyBidirectionalRelation

protected void checkOneToManyBidirectionalRelation(AbstractMemberMetaData mmd,
                                                   ClassLoaderResolver clr,
                                                   ObjectManager om,
                                                   java.util.List<org.datanucleus.state.RelationshipManager.RelationChange> changes)
Method to check the consistency of the passed field as 1-N.

Parameters:
mmd - MetaData for the field
clr - ClassLoader resolver
om - ObjectManager
changes - List of changes to the collection

checkManyToOneBidirectionalRelation

protected void checkManyToOneBidirectionalRelation(AbstractMemberMetaData mmd,
                                                   ClassLoaderResolver clr,
                                                   ObjectManager om,
                                                   java.lang.Object oldValue,
                                                   java.lang.Object newValue)
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

Parameters:
mmd - MetaData for the field
clr - ClassLoader resolver
om - ObjectManager
oldValue - The old value
newValue - The new value

checkManyToManyBidirectionalRelation

protected void checkManyToManyBidirectionalRelation(AbstractMemberMetaData mmd,
                                                    ClassLoaderResolver clr,
                                                    ObjectManager om,
                                                    java.util.List<org.datanucleus.state.RelationshipManager.RelationChange> changes)
Method to check consistency of the passed field as M-N.

Parameters:
mmd - MetaData for the field
clr - ClassLoader resolver
om - ObjectManager
changes - List of changes to the collection

processOneToOneBidirectionalRelation

protected void processOneToOneBidirectionalRelation(AbstractMemberMetaData mmd,
                                                    ClassLoaderResolver clr,
                                                    ObjectManager om,
                                                    java.lang.Object oldValue,
                                                    java.lang.Object newValue)
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 example
a.b = b1; a.b = b2;
so A's b field is changed from b1 to b2. The following changes are likely to be necessary

Parameters:
mmd - MetaData for the field
clr - ClassLoader resolver
om - ObjectManager
oldValue - The old value
newValue - The new value

processOneToManyBidirectionalRelation

protected void processOneToManyBidirectionalRelation(AbstractMemberMetaData mmd,
                                                     ClassLoaderResolver clr,
                                                     ObjectManager om,
                                                     java.util.List<org.datanucleus.state.RelationshipManager.RelationChange> changes)
Method to process all 1-N bidirectional fields.

Parameters:
mmd - MetaData for the field
clr - ClassLoader resolver
om - ObjectManager
changes - List of changes to the collection

processManyToOneBidirectionalRelation

protected void processManyToOneBidirectionalRelation(AbstractMemberMetaData mmd,
                                                     ClassLoaderResolver clr,
                                                     ObjectManager om,
                                                     java.lang.Object oldValue,
                                                     java.lang.Object newValue)
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

Parameters:
mmd - MetaData for the field
clr - ClassLoader resolver
om - ObjectManager
oldValue - The old value
newValue - The new value

processManyToManyBidirectionalRelation

protected void processManyToManyBidirectionalRelation(AbstractMemberMetaData mmd,
                                                      ClassLoaderResolver clr,
                                                      ObjectManager om,
                                                      java.util.List<org.datanucleus.state.RelationshipManager.RelationChange> changes)
Method to process all M-N bidirectional fields.

Parameters:
mmd - MetaData for the field
clr - ClassLoader resolver
om - ObjectManager
changes - List of changes to the collection


Copyright © 2010. All Rights Reserved.