FileDocCategorySizeDatePackage
RelationshipElement.javaAPI DocGlassfish v2 API19744Fri May 04 22:34:42 BST 2007com.sun.jdo.api.persistence.model.jdo

RelationshipElement

public class RelationshipElement extends PersistenceFieldElement
author
raccah
version
%I%

Fields Summary
public static final int
NONE_ACTION
Constant representing no action.
public static final int
NULLIFY_ACTION
Constant representing nullify action.
public static final int
RESTRICT_ACTION
Constant representing restrict action.
public static final int
CASCADE_ACTION
Constant representing cascade action.
public static final int
AGGREGATE_ACTION
Constant representing aggregate action.
Constructors Summary
public RelationshipElement()
Create new RelationshipElement with no implementation. This constructor should only be used for cloning and archiving.


	                 	 
	  
	
		this(null, null);
	
public RelationshipElement(Impl impl, PersistenceClassElement declaringClass)
Create new RelationshipElement with the provided implementation. The implementation is responsible for storing all properties of the object.

param
impl the implementation to use
param
declaringClass the class to attach to

		super(impl, declaringClass);
	
Methods Summary
public voidchangeInverseRelationship(com.sun.jdo.api.persistence.model.jdo.RelationshipElement inverseRelationship)
Changes the inverse relationship element for this relationship element. This method is invoked for both sides from {@link RelationshipElement#setInverseRelationship} and should handle the vetoable change events, property change events, and setting the internal variable.

param
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.
exception
ModelException if impossible

		getRelationshipImpl().changeInverseRelationship(inverseRelationship);
	
public java.lang.StringgetCollectionClass()
Get the collection class (for example Set, List, Vector, etc.) for this relationship element.

return
the collection class

		return getRelationshipImpl().getCollectionClass();
	
public intgetDeleteAction()
Get the delete action for this relationship element.

return
the delete action, one of {@link #NONE_ACTION}, {@link #NULLIFY_ACTION}, {@link #RESTRICT_ACTION}, {@link #CASCADE_ACTION}, or {@link #AGGREGATE_ACTION}

		return getRelationshipImpl().getDeleteAction();
	
public java.lang.StringgetElementClass()
Get the element class for this relationship element. If primitive types are supported, you can use wrapperclass.TYPE.toString() to specify them.

return
the element class

		return getRelationshipImpl().getElementClass();
	
public com.sun.jdo.api.persistence.model.jdo.RelationshipElementgetInverseRelationship(com.sun.jdo.api.persistence.model.Model model)
Get the inverse relationship element for this relationship element. In the case of two-way relationships, the two relationship elements 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 also possible for this method to return null even if {@link #getInverseRelationshipName} returns a value because the corresponding RelationshipElement cannot be found using the combination of related class and lookup (model).

param
model the model object to be used to look it up
return
the inverse relationship element if it exists
see
#getInverseRelationshipName

		String inverseName = getInverseRelationshipName();
		RelationshipElement inverse = null;

		if ((model != null) && (inverseName != null))
		{
			String relatedClass = model.getRelatedClass(this);

			if (relatedClass != null)
			{
				PersistenceClassElement relatedElement =
					model.getPersistenceClass(relatedClass);

				if (relatedElement != null)
					inverse = relatedElement.getRelationship(inverseName);
			}
		}

		return inverse;
	
public java.lang.StringgetInverseRelationshipName()
Get the relative name of the inverse relationship field for this relationship element. In the case of two-way relationships, the two relationship elements 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 RelationshipElement which can be found.

return
the relative name of the inverse relationship element
see
#getInverseRelationship

		return getRelationshipImpl().getInverseRelationshipName();
	
public intgetLowerBound()
Get the lower cardinality bound for this relationship element.

return
the lower cardinality bound

		return getRelationshipImpl().getLowerBound();
	
final com.sun.jdo.api.persistence.model.jdo.RelationshipElement$ImplgetRelationshipImpl()

return
implemetation factory for this relationship

 return (Impl)getImpl(); 
public intgetUpdateAction()
Get the update action for this relationship element.

return
the update action, one of {@link #NONE_ACTION}, {@link #NULLIFY_ACTION}, {@link #RESTRICT_ACTION}, {@link #CASCADE_ACTION}, or {@link #AGGREGATE_ACTION}

		return getRelationshipImpl().getUpdateAction();
	
public intgetUpperBound()
Get the upper cardinality bound for this relationship element. Returns {@link java.lang.Integer#MAX_VALUE} for n

return
the upper cardinality bound

		return getRelationshipImpl().getUpperBound();
	
public booleanisPrefetch()
Determines whether this relationship element should prefetch or not.

return
true if the relationship should prefetch, false otherwise

		return getRelationshipImpl().isPrefetch();
	
public voidsetCollectionClass(java.lang.String collectionClass)
Set the collection class for this relationship element.

param
collectionClass - a string indicating the type of collection (for example Set, List, Vector, etc.)
exception
ModelException if impossible

		getRelationshipImpl().setCollectionClass(collectionClass);
	
public voidsetDeleteAction(int action)
Set the delete action for this relationship element.

param
action - an integer indicating the delete action, one of: {@link #NONE_ACTION}, {@link #NULLIFY_ACTION}, {@link #RESTRICT_ACTION}, {@link #CASCADE_ACTION}, or {@link #AGGREGATE_ACTION}
exception
ModelException if impossible

		if ((action < NONE_ACTION) || (action > AGGREGATE_ACTION))
		{
			throw new ModelException(I18NHelper.getMessage(getMessages(),
				"jdo.relationship.delete_action_invalid", action));	// NOI18N
		}

		getRelationshipImpl().setDeleteAction(action);
	
public voidsetElementClass(java.lang.String elementClass)
Set the element class for this relationship element.

param
elementClass - a string indicating the type of elements in the collection. If primitive types are supported, you can use wrapperclass.TYPE.toString() to specify them.
exception
ModelException if impossible

		getRelationshipImpl().setElementClass(elementClass);
	
public voidsetInverseRelationship(com.sun.jdo.api.persistence.model.jdo.RelationshipElement inverseRelationship, com.sun.jdo.api.persistence.model.Model model)
Set the inverse relationship element for this relationship element. In the case of two-way relationships, the two relationship elements involved are inverses of each other.

param
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.
param
model the model object to be used to look up the old inverse so it can be unset
exception
ModelException if impossible

		RelationshipElement old = getInverseRelationship(model);

		if ((old != inverseRelationship) || ((inverseRelationship == null) && 
			(getInverseRelationshipName() != null)))
		{
			// clear old inverse which still points to here
			if (old != null)
			{
				RelationshipElement oldInverse = 
					old.getInverseRelationship(model);

				if (this.equals(oldInverse))
					old.changeInverseRelationship(null);
			}

			// link from here to new inverse
			changeInverseRelationship(inverseRelationship);

			// link from new inverse back to here
			if (inverseRelationship != null)
				inverseRelationship.changeInverseRelationship(this);
		}
	
public voidsetLowerBound(int lowerBound)
Set the lower cardinality bound for this relationship element.

param
lowerBound - an integer indicating the lower cardinality bound
exception
ModelException if impossible

		if ((lowerBound > getUpperBound()) || (lowerBound < 0))
		{
			throw new ModelException(I18NHelper.getMessage(getMessages(),
				"jdo.relationship.lower_cardinality_invalid"));		// NOI18N
		}

		getRelationshipImpl().setLowerBound(lowerBound);
	
public voidsetPrefetch(boolean flag)
Set whether this relationship element should prefetch or not.

param
flag - if true, the relationship is set to prefetch; otherwise, it is not
exception
ModelException if impossible

		getRelationshipImpl().setPrefetch(flag);
	
public voidsetUpdateAction(int action)
Set the update action for this relationship element.

param
action - an integer indicating the update action, one of: {@link #NONE_ACTION}, {@link #NULLIFY_ACTION}, {@link #RESTRICT_ACTION}, {@link #CASCADE_ACTION}, or {@link #AGGREGATE_ACTION}
exception
ModelException if impossible

		if ((action < NONE_ACTION) || (action > AGGREGATE_ACTION))
		{
			throw new ModelException(I18NHelper.getMessage(getMessages(),
				"jdo.relationship.update_action_invalid", action));	// NOI18N
		}

		getRelationshipImpl().setUpdateAction(action);
	
public voidsetUpperBound(int upperBound)
Set the upper cardinality bound for this relationship element.

param
upperBound - an integer indicating the upper cardinality bound (use {@link java.lang.Integer#MAX_VALUE} for n)
exception
ModelException if impossible

		if ((upperBound < getLowerBound()) || (upperBound <= 0))
		{
			throw new ModelException(I18NHelper.getMessage(getMessages(),
				"jdo.relationship.upper_cardinality_invalid"));		// NOI18N
		}

		getRelationshipImpl().setUpperBound(upperBound);