org.apache.cayenne.map
Class ObjRelationship

java.lang.Object
  extended by org.apache.cayenne.map.Relationship
      extended by org.apache.cayenne.map.ObjRelationship
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, CayenneMapEntry, XMLSerializable

public class ObjRelationship
extends Relationship
implements java.util.EventListener

Describes navigational association between two Java classes, represented as source and target ObjEntity. Maps to a path of DbRelationships.

Author:
Andrei Adamchik
See Also:
Serialized Form

Field Summary
protected  java.lang.String dbRelationshipPath
           
protected  java.util.List dbRelationships
           
protected  int deleteRule
           
protected  boolean usedForLocking
           
 
Fields inherited from class org.apache.cayenne.map.Relationship
name, sourceEntity, targetEntityName, toMany
 
Constructor Summary
ObjRelationship()
           
ObjRelationship(java.lang.String name)
           
 
Method Summary
 void addDbRelationship(DbRelationship dbRel)
          Appends a DbRelationship to the existing list of DbRelationships.
 void clearDbRelationships()
           
 void dbRelationshipDidChange(RelationshipEvent event)
           
 void encodeAsXML(XMLEncoder encoder)
          Prints itself as XML to the provided XMLEncoder.
 ObjRelationship getClientRelationship()
          Returns an ObjAttribute stripped of any server-side information, such as DbAttribute mapping.
 java.lang.String getDbRelationshipPath()
          Returns a dot-separated path over mapped DbRelationships.
 java.util.List getDbRelationships()
          Returns an immutable list of underlying DbRelationships.
 int getDeleteRule()
          Returns the deleteRule.
 java.lang.String getReverseDbRelationshipPath()
          Returns a reversed dbRelationship path.
 ObjRelationship getReverseRelationship()
          Returns a "complimentary" ObjRelationship going in the opposite direction.
 java.lang.String getReverseRelationshipName()
          Returns the name of a complimentary relationship going in the opposite direction or null if it doesn't exist.
 Entity getTargetEntity()
          Returns a target ObjEntity of this relationship.
 boolean isFlattened()
          Returns true if the relationship is a "flattened" relationship.
 boolean isReadOnly()
          Returns true if the relationship is flattened, but is not of the single case that can have automatic write support.
 boolean isSourceIndependentFromTargetChange()
          Returns a boolean indicating whether modifying a target of such relationship in any way will not change the underlying table row of the source.
 boolean isToDependentEntity()
          Returns true if underlying DbRelationships point to dependent entity.
 boolean isToMany()
          Returns a boolean value that determines relationship multiplicity.
 boolean isToPK()
          Returns true if the underlying DbRelationships point to a at least one of the columns of the target entity.
 boolean isUsedForLocking()
          Returns whether this attribute should be used for locking.
 void removeDbRelationship(DbRelationship dbRel)
          Removes the relationship dbRel from the list of relationships.
 void setDbRelationshipPath(java.lang.String relationshipPath)
          Sets mapped DbRelationships as a dot-separated path.
 void setDeleteRule(int value)
          Sets the delete rule of the relationship.
 void setUsedForLocking(boolean usedForLocking)
          Sets whether this attribute should be used for locking.
 java.lang.String toString()
          Overrides Object.toString() to return informative description.
 
Methods inherited from class org.apache.cayenne.map.Relationship
getName, getParent, getSourceEntity, getTargetEntityName, setName, setParent, setSourceEntity, setTargetEntity, setTargetEntityName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

deleteRule

protected int deleteRule

usedForLocking

protected boolean usedForLocking

dbRelationshipPath

protected java.lang.String dbRelationshipPath

dbRelationships

protected java.util.List dbRelationships
Constructor Detail

ObjRelationship

public ObjRelationship()

ObjRelationship

public ObjRelationship(java.lang.String name)
Method Detail

encodeAsXML

public void encodeAsXML(XMLEncoder encoder)
Prints itself as XML to the provided XMLEncoder.

Specified by:
encodeAsXML in interface XMLSerializable
Since:
1.1

getTargetEntity

public Entity getTargetEntity()
Returns a target ObjEntity of this relationship. Entity is looked up in the parent DataMap using "targetEntityName".

Specified by:
getTargetEntity in class Relationship

getReverseRelationshipName

public java.lang.String getReverseRelationshipName()
Returns the name of a complimentary relationship going in the opposite direction or null if it doesn't exist.

Since:
1.2

getReverseRelationship

public ObjRelationship getReverseRelationship()
Returns a "complimentary" ObjRelationship going in the opposite direction. Returns null if no such relationship is found.


getDbRelationships

public java.util.List getDbRelationships()
Returns an immutable list of underlying DbRelationships.


addDbRelationship

public void addDbRelationship(DbRelationship dbRel)
Appends a DbRelationship to the existing list of DbRelationships.


removeDbRelationship

public void removeDbRelationship(DbRelationship dbRel)
Removes the relationship dbRel from the list of relationships.


clearDbRelationships

public void clearDbRelationships()

isSourceIndependentFromTargetChange

public boolean isSourceIndependentFromTargetChange()
Returns a boolean indicating whether modifying a target of such relationship in any way will not change the underlying table row of the source.

Since:
1.1

isToDependentEntity

public boolean isToDependentEntity()
Returns true if underlying DbRelationships point to dependent entity.


isToPK

public boolean isToPK()
Returns true if the underlying DbRelationships point to a at least one of the columns of the target entity.

Since:
1.1

isFlattened

public boolean isFlattened()
Returns true if the relationship is a "flattened" relationship. A relationship is considered "flattened" if it maps to more than one DbRelationship. Such chain of DbRelationships is also called "relationship path". All flattened relationships are at least readable, but only those formed across a many-many join table (with no custom attributes other than foreign keys) can be automatically written.

Returns:
flag indicating if the relationship is flattened or not.
See Also:
isReadOnly()

isReadOnly

public boolean isReadOnly()
Returns true if the relationship is flattened, but is not of the single case that can have automatic write support. Otherwise, it returns false.

Returns:
flag indicating if the relationship is read only or not

isToMany

public boolean isToMany()
Description copied from class: Relationship
Returns a boolean value that determines relationship multiplicity. This defines semantics of the connection between two nodes described by the source and target entities. E.g. to-many relationship between two Persistent object classes means that a source object would have a collection of target objects. This is a read-only property.

Overrides:
isToMany in class Relationship

getDeleteRule

public int getDeleteRule()
Returns the deleteRule. The delete rule is a constant from the DeleteRule class, and specifies what should happen to the destination object when the source object is deleted.

Returns:
int a constant from DeleteRule
See Also:
setDeleteRule(int)

setDeleteRule

public void setDeleteRule(int value)
Sets the delete rule of the relationship.

Parameters:
value - New delete rule. Must be one of the constants defined in DeleteRule class.
Throws:
java.lang.IllegalArgumentException - if the value is not a valid delete rule.
See Also:
DeleteRule

dbRelationshipDidChange

public void dbRelationshipDidChange(RelationshipEvent event)

isUsedForLocking

public boolean isUsedForLocking()
Returns whether this attribute should be used for locking.

Since:
1.1

setUsedForLocking

public void setUsedForLocking(boolean usedForLocking)
Sets whether this attribute should be used for locking.

Since:
1.1

getDbRelationshipPath

public java.lang.String getDbRelationshipPath()
Returns a dot-separated path over mapped DbRelationships.

Since:
1.1

getReverseDbRelationshipPath

public java.lang.String getReverseDbRelationshipPath()
                                              throws ExpressionException
Returns a reversed dbRelationship path.

Throws:
ExpressionException
Since:
1.2

setDbRelationshipPath

public void setDbRelationshipPath(java.lang.String relationshipPath)
Sets mapped DbRelationships as a dot-separated path.


toString

public java.lang.String toString()
Description copied from class: Relationship
Overrides Object.toString() to return informative description.

Overrides:
toString in class Relationship

getClientRelationship

public ObjRelationship getClientRelationship()
Returns an ObjAttribute stripped of any server-side information, such as DbAttribute mapping.

Since:
1.2


Copyright © 2001-2006 Apache.org All Rights Reserved.