org.apache.cayenne.map
Class DbRelationship

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

public class DbRelationship
extends Relationship

A DbRelationship is a descriptor of a database inter-table relationship based on one or more primary key/foreign key pairs.

Author:
Misha Shengaout, Andrei Adamchik
See Also:
Serialized Form

Field Summary
protected  java.util.List joins
           
static EventSubject PROPERTY_DID_CHANGE
           
protected  boolean toDependentPK
           
 
Fields inherited from class org.apache.cayenne.map.Relationship
name, sourceEntity, targetEntityName, toMany
 
Constructor Summary
DbRelationship()
           
DbRelationship(java.lang.String name)
           
 
Method Summary
 void addJoin(DbJoin join)
          Adds a join.
 DbRelationship createReverseRelationship()
          Creates a new relationship with the same set of joins, but going in the opposite direction.
 void encodeAsXML(XMLEncoder encoder)
          Prints itself as XML to the provided XMLEncoder.
protected  void firePropertyDidChange()
           
 java.util.List getJoins()
          Returns a list of joins.
 DbRelationship getReverseRelationship()
          Returns DbRelationship that is the opposite of this DbRelationship.
 java.util.Collection getSourceAttributes()
          Returns a Collection of source attributes.
 java.util.Collection getTargetAttributes()
          Returns a Collection of target attributes.
 Entity getTargetEntity()
          Returns a target of this relationship.
 boolean isToDependentPK()
          Returns true if relationship from source to target points to dependent primary key.
 boolean isToMasterPK()
          Returns true if a method isToDependentPK of reverse relationship of this relationship returns true.
 boolean isToPK()
          Returns true if the relationship points to at least one of the PK columns of the target entity.
 boolean isValidForDepPk()
           
 void removeAllJoins()
           
 void removeJoin(DbJoin join)
           
 void setJoins(java.util.Collection newJoins)
           
 void setToDependentPK(boolean toDependentPK)
           
 void setToMany(boolean toMany)
          Sets relationship multiplicity.
 java.util.Map srcFkSnapshotWithTargetSnapshot(java.util.Map targetSnapshot)
          Creates a snapshot of foreign key attributes of a source object of this relationship based on a snapshot of a target.
 java.util.Map srcPkSnapshotWithTargetSnapshot(java.util.Map targetSnapshot)
          Creates a snapshot of primary key attributes of a source object of this relationship based on a snapshot of a target.
 java.util.Map targetPkSnapshotWithSrcSnapshot(java.util.Map srcSnapshot)
          Creates a snapshot of primary key attributes of a target object of this relationship based on a snapshot of a source.
 
Methods inherited from class org.apache.cayenne.map.Relationship
getName, getParent, getSourceEntity, getTargetEntityName, isToMany, setName, setParent, setSourceEntity, setTargetEntity, setTargetEntityName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_DID_CHANGE

public static final EventSubject PROPERTY_DID_CHANGE

joins

protected java.util.List joins

toDependentPK

protected boolean toDependentPK
Constructor Detail

DbRelationship

public DbRelationship()

DbRelationship

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

encodeAsXML

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

Since:
1.1

getTargetEntity

public Entity getTargetEntity()
Returns a target of this relationship. If relationship is not attached to a DbEntity, and DbEntity doesn't have a namcespace, and exception is thrown.

Specified by:
getTargetEntity in class Relationship

getTargetAttributes

public java.util.Collection getTargetAttributes()
Returns a Collection of target attributes.

Since:
1.1

getSourceAttributes

public java.util.Collection getSourceAttributes()
Returns a Collection of source attributes.

Since:
1.1

createReverseRelationship

public DbRelationship createReverseRelationship()
Creates a new relationship with the same set of joins, but going in the opposite direction.

Since:
1.0.5

getReverseRelationship

public DbRelationship getReverseRelationship()
Returns DbRelationship that is the opposite of this DbRelationship. This means a relationship from this target entity to this source entity with the same join semantics. Returns null if no such relationship exists.


isToPK

public boolean isToPK()
Returns true if the relationship points to at least one of the PK columns of the target entity.

Since:
1.1

isToMasterPK

public boolean isToMasterPK()
Returns true if a method isToDependentPK of reverse relationship of this relationship returns true.


isToDependentPK

public boolean isToDependentPK()
Returns true if relationship from source to target points to dependent primary key. Dependent PK is a primary key column of the destination table that is also a FK to the source column.


setToDependentPK

public void setToDependentPK(boolean toDependentPK)

isValidForDepPk

public boolean isValidForDepPk()
Since:
1.1

getJoins

public java.util.List getJoins()
Returns a list of joins. List is returned by reference, so any modifications of the list will affect this relationship.


addJoin

public void addJoin(DbJoin join)
Adds a join.

Since:
1.1

removeJoin

public void removeJoin(DbJoin join)

removeAllJoins

public void removeAllJoins()

setJoins

public void setJoins(java.util.Collection newJoins)

targetPkSnapshotWithSrcSnapshot

public java.util.Map targetPkSnapshotWithSrcSnapshot(java.util.Map srcSnapshot)
Creates a snapshot of primary key attributes of a target object of this relationship based on a snapshot of a source. Only "to-one" relationships are supported. Returns null if relationship does not point to an object. Throws CayenneRuntimeException if relationship is "to many" or if snapshot is missing id components.


srcFkSnapshotWithTargetSnapshot

public java.util.Map srcFkSnapshotWithTargetSnapshot(java.util.Map targetSnapshot)
Creates a snapshot of foreign key attributes of a source object of this relationship based on a snapshot of a target. Only "to-one" relationships are supported. Throws CayenneRuntimeException if relationship is "to many".


srcPkSnapshotWithTargetSnapshot

public java.util.Map srcPkSnapshotWithTargetSnapshot(java.util.Map targetSnapshot)
Creates a snapshot of primary key attributes of a source object of this relationship based on a snapshot of a target. Only "to-many" relationships are supported. Throws CayenneRuntimeException if relationship is "to one".


setToMany

public void setToMany(boolean toMany)
Sets relationship multiplicity.


firePropertyDidChange

protected void firePropertyDidChange()


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