org.apache.jdo.impl.model.jdo
Class JDORelationshipImpl

java.lang.Object
  extended byorg.apache.jdo.impl.model.jdo.JDOElementImpl
      extended byorg.apache.jdo.impl.model.jdo.JDORelationshipImpl
All Implemented Interfaces:
JDOElement, JDORelationship
Direct Known Subclasses:
JDOArrayImplDynamic, JDOCollectionImplDynamic, JDOMapImplDynamic, JDOReferenceImplDynamic

public abstract class JDORelationshipImpl
extends JDOElementImpl
implements JDORelationship

JDORelationship is the super interface for all interfaces representing JDO relationship metadata of a managed field of a persistence capable class.

Version:
2.0
Author:
Michael Bouschen

Field Summary
private  JDOField declaringField
          Relationship JDOField<->JDORelationship.
protected  JDORelationship inverse
          Relationship JDORelationship<->JDORelationship.
private  java.lang.String inverseName
          Name of the field which is the inverse relationship
private  int lowerBound
          Property lowerBound.
protected  JDORelationship mappedBy
          Relationship JDORelationship<->JDORelationship.
private  int upperBound
          Property upperBound.
 
Fields inherited from class org.apache.jdo.impl.model.jdo.JDOElementImpl
 
Fields inherited from interface org.apache.jdo.model.jdo.JDORelationship
CARDINALITY_N, CARDINALITY_ONE, CARDINALITY_ZERO
 
Constructor Summary
JDORelationshipImpl()
           
 
Method Summary
private  void changeInverseRelationship(JDORelationship inverseRelationship)
          Changes the inverse relationship element for this relationship element.
 JDOField getDeclaringField()
          Get the declaring field of this JDORelationship.
 JDORelationship getInverseRelationship()
          Get the inverse JDORelationship in the case of a two-way relationship.
 java.lang.String getInverseRelationshipName()
          Get the relative name of the inverse relationship field for this relationship.
 int getLowerBound()
          Get the lower cardinality bound for this relationship element.
 JDORelationship getMappedBy()
          Get the mappedBy relationship.
abstract  JavaType getRelatedJavaType()
          Get the type representation of the relationship.
 JDOClass getRelatedJDOClass()
          Get the JDOClass corresponding to the type or element of this relationship.
private  UnresolvedRelationshipHelper getUnresolvedRelationshipHelper()
          Returns the UnresolvedRelationshipHelper instance from the declaring field.
 int getUpperBound()
          Get the upper cardinality bound for this relationship element.
 boolean isJDOArray()
          Determines whether this JDORelationship represents an array relationship or not.
 boolean isJDOCollection()
          Determines whether this JDORelationship represents a collection relationship or not.
 boolean isJDOMap()
          Determines whether this JDORelationship represents a map relationship or not.
 boolean isJDOReference()
          Determines whether this JDORelationship represents a reference relationship or not.
 boolean isOwner()
          Determines whether this side of a two-way relationship is the owning side.
 void setDeclaringField(JDOField declaringField)
          Set the declaring field of this JDORelationship.
 void setInverseRelationship(JDORelationship inverseRelationship)
          Set the inverse JDORelationship in the case of a two-way relationship.
 void setLowerBound(int lowerBound)
          Set the lower cardinality bound for this relationship element.
 void setMappedBy(JDORelationship mappedBy)
          Set the mappedBy relationship for this relationship.
 void setUpperBound(int upperBound)
          Set the upper cardinality bound for this relationship element.
 
Methods inherited from class org.apache.jdo.impl.model.jdo.JDOElementImpl
addPropertyChangeListener, addVetoableChangeListener, createJDOExtension, firePropertyChange, fireVetoableChange, getJDOExtensions, removeJDOExtension, removePropertyChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.jdo.model.jdo.JDOElement
addPropertyChangeListener, addVetoableChangeListener, createJDOExtension, getJDOExtensions, removeJDOExtension, removePropertyChangeListener, removeVetoableChangeListener
 

Field Detail

lowerBound

private int lowerBound
Property lowerBound. No default.


upperBound

private int upperBound
Property upperBound. No default.


declaringField

private JDOField declaringField
Relationship JDOField<->JDORelationship.


mappedBy

protected JDORelationship mappedBy
Relationship JDORelationship<->JDORelationship.


inverseName

private java.lang.String inverseName
Name of the field which is the inverse relationship


inverse

protected JDORelationship inverse
Relationship JDORelationship<->JDORelationship.

Constructor Detail

JDORelationshipImpl

public JDORelationshipImpl()
Method Detail

getLowerBound

public int getLowerBound()
Get the lower cardinality bound for this relationship element.

Specified by:
getLowerBound in interface JDORelationship
Returns:
the lower cardinality bound

setLowerBound

public void setLowerBound(int lowerBound)
Set the lower cardinality bound for this relationship element.

Specified by:
setLowerBound in interface JDORelationship
Parameters:
lowerBound - an integer indicating the lower cardinality bound

getUpperBound

public int getUpperBound()
Get the upper cardinality bound for this relationship element.

Specified by:
getUpperBound in interface JDORelationship
Returns:
the upper cardinality bound

setUpperBound

public void setUpperBound(int upperBound)
Set the upper cardinality bound for this relationship element.

Specified by:
setUpperBound in interface JDORelationship
Parameters:
upperBound - an integer indicating the upper cardinality bound

getDeclaringField

public JDOField getDeclaringField()
Get the declaring field of this JDORelationship.

Specified by:
getDeclaringField in interface JDORelationship
Returns:
the field that owns this JDORelationship, or null if the element is not attached to any field

setDeclaringField

public void setDeclaringField(JDOField declaringField)
Set the declaring field of this JDORelationship.

Specified by:
setDeclaringField in interface JDORelationship
Parameters:
declaringField - the declaring field of this relationship element

getRelatedJDOClass

public JDOClass getRelatedJDOClass()
Get the JDOClass corresponding to the type or element of this relationship.

Specified by:
getRelatedJDOClass in interface JDORelationship
Returns:
the related class

getMappedBy

public JDORelationship getMappedBy()
Get the mappedBy relationship. If there is no mappedBy relationship set, the method checks the mappedBy name as specified in the declaring field and resolves the relationship. The method return null if there is no mappedBy relationship set and there is no mappedBy name specified on the declaring field.

Specified by:
getMappedBy in interface JDORelationship
Returns:
the mappedBy relationship if available; null otherwise.

setMappedBy

public void setMappedBy(JDORelationship mappedBy)
                 throws ModelException
Set the mappedBy relationship for this relationship. This method automatically updates the mappedBy name of the declaring field of this relationship.

Specified by:
setMappedBy in interface JDORelationship
Parameters:
mappedBy - the mappedBy relationship.
Throws:
ModelException - if impossible

getInverseRelationshipName

public java.lang.String getInverseRelationshipName()
Get the relative name of the inverse relationship field for this relationship. In the case of two-way relationships, the two relationships involved are inverses of each other. If this relationship element does not participate in a two-way relationship, this returns null. Note that it is possible to have this method return a value, but because of the combination of related class and lookup, there may be no corresponding JDORelationship which can be found.

Specified by:
getInverseRelationshipName in interface JDORelationship
Returns:
the relative name of the inverse JDORelationship
See Also:
getInverseRelationship()

getInverseRelationship

public JDORelationship getInverseRelationship()
Get the inverse JDORelationship in the case of a two-way relationship.

Specified by:
getInverseRelationship in interface JDORelationship
Returns:
the inverse relationship

setInverseRelationship

public void setInverseRelationship(JDORelationship inverseRelationship)
                            throws ModelException
Set the inverse JDORelationship in the case of a two-way relationship. The two relationship elements involved are set as inverses of each other and the old inverse is unset.

Warning: this methods casts the existing and the specified inverse relationship instance to JDORelationshipImpl.

Specified by:
setInverseRelationship in interface JDORelationship
Parameters:
inverseRelationship - the inverse relationship
Throws:
ModelException - if impossible

isOwner

public boolean isOwner()
Determines whether this side of a two-way relationship is the owning side.

Specified by:
isOwner in interface JDORelationship
Returns:
true if this side is the owning side; false otherwise.

isJDOReference

public boolean isJDOReference()
Determines whether this JDORelationship represents a reference relationship or not. A return of true means this JDORelationship is a JDOReference instance.

Specified by:
isJDOReference in interface JDORelationship
Returns:
true if this JDORelationship represents a reference relationship; false otherwise.

isJDOCollection

public boolean isJDOCollection()
Determines whether this JDORelationship represents a collection relationship or not. A return of true means this JDORelationship is a JDOCollection instance.

Specified by:
isJDOCollection in interface JDORelationship
Returns:
true if this JDORelationship represents a collection relationship; false otherwise.

isJDOArray

public boolean isJDOArray()
Determines whether this JDORelationship represents an array relationship or not. A return of true means this JDORelationship is a JDOArray instance.

Specified by:
isJDOArray in interface JDORelationship
Returns:
true if this JDORelationship represents an array relationship; false otherwise.

isJDOMap

public boolean isJDOMap()
Determines whether this JDORelationship represents a map relationship or not. A return of true means this JDORelationship is a JDOMap instance.

Specified by:
isJDOMap in interface JDORelationship
Returns:
true if this JDORelationship represents a map relationship; false otherwise.

getRelatedJavaType

public abstract JavaType getRelatedJavaType()
Get the type representation of the relationship. This will be the JavaType for references, the element type for collections and arrays, and the value type for maps.

Returns:
the relationship type

changeInverseRelationship

private void changeInverseRelationship(JDORelationship inverseRelationship)
                                throws ModelException
Changes the inverse relationship element for this relationship element. This method is invoked for both sides from setInverseRelationship(org.apache.jdo.model.jdo.JDORelationship) and should handle setting the internal variable.

Parameters:
inverseRelationship - - a relationship element to be used as the inverse for this relationship element or null if this relationship element does not participate in a two-way relationship.
Throws:
ModelException - if impossible

getUnresolvedRelationshipHelper

private UnresolvedRelationshipHelper getUnresolvedRelationshipHelper()
Returns the UnresolvedRelationshipHelper instance from the declaring field.

Returns:
the current UnresolvedRelationshipHelper