Package org.apache.cayenne.map
Class DbRelationship
java.lang.Object
org.apache.cayenne.map.Relationship
org.apache.cayenne.map.DbRelationship
- All Implemented Interfaces:
- Serializable,- ConfigurationNode,- CayenneMapEntry,- XMLSerializable
public class DbRelationship extends Relationship implements ConfigurationNode
A DbRelationship is a descriptor of a database inter-table relationship based
 on one or more primary key/foreign key pairs.
- See Also:
- Serialized Form
- 
Field SummaryFields Modifier and Type Field Description protected List<DbJoin>joinsprotected booleantoDependentPKFields inherited from class org.apache.cayenne.map.Relationshipname, runtime, sourceEntity, targetEntityName, toMany
- 
Constructor SummaryConstructors Constructor Description DbRelationship()DbRelationship(String name)
- 
Method SummaryModifier and Type Method Description <T> TacceptVisitor(ConfigurationNodeVisitor<T> visitor)voidaddJoin(DbJoin join)Adds a join.DbRelationshipcreateReverseRelationship()Creates a new relationship with the same set of joins, but going in the opposite direction.voidencodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate)Prints itself as XML to the provided XMLEncoder.List<DbJoin>getJoins()Returns a list of joins.DbRelationshipgetReverseRelationship()Returns DbRelationship that is the opposite of this DbRelationship.Collection<DbAttribute>getSourceAttributes()Returns a Collection of source attributes.DbEntitygetSourceEntity()Returns relationship source entity.StringgetSourceEntityName()Collection<DbAttribute>getTargetAttributes()Returns a Collection of target attributes.DbEntitygetTargetEntity()Returns a target of this relationship.booleanisFromPK()booleanisMandatory()Returns if relationship is mandatorybooleanisSourceIndependentFromTargetChange()Returns a boolean indicating whether modifying a target of such relationship in any way will not change the underlying table row of the source.booleanisToDependentPK()Returnstrueif relationship from source to target points to dependent primary key.booleanisToMasterPK()Returnstrueif a methodisToDependentPKof reverse relationship of this relationship returnstrue.booleanisToPK()Returns true if the relationship points to at least one of the PK columns of the target entity.booleanisValidForDepPk()voidremoveAllJoins()voidremoveJoin(DbJoin join)voidsetJoins(Collection<DbJoin> newJoins)voidsetToDependentPK(boolean toDependentPK)voidsetToMany(boolean toMany)Sets relationship multiplicity.Map<String,Object>srcFkSnapshotWithTargetSnapshot(Map<String,Object> targetSnapshot)Creates a snapshot of foreign key attributes of a source object of this relationship based on a snapshot of a target.Map<String,Object>srcPkSnapshotWithTargetSnapshot(Map<String,Object> targetSnapshot)Creates a snapshot of primary key attributes of a source object of this relationship based on a snapshot of a target.Map<String,Object>targetPkSnapshotWithSrcSnapshot(Map<String,Object> srcSnapshot)Creates a snapshot of primary key attributes of a target object of this relationship based on a snapshot of a source.StringtoString()Overrides Object.toString() to return informative description.Methods inherited from class org.apache.cayenne.map.RelationshipgetName, getParent, getTargetEntityName, isRuntime, isToMany, setName, setParent, setRuntime, setSourceEntity, setTargetEntityName, setTargetEntityName
- 
Field Details- 
joins
- 
toDependentPKprotected boolean toDependentPK
 
- 
- 
Constructor Details- 
DbRelationshippublic DbRelationship()
- 
DbRelationship
 
- 
- 
Method Details- 
getSourceEntityDescription copied from class:RelationshipReturns relationship source entity.- Overrides:
- getSourceEntityin class- Relationship
 
- 
acceptVisitor- Specified by:
- acceptVisitorin interface- ConfigurationNode
- Since:
- 3.1
 
- 
encodeAsXMLPrints itself as XML to the provided XMLEncoder.- Specified by:
- encodeAsXMLin interface- XMLSerializable
- Since:
- 1.1
 
- 
getTargetEntityReturns a target of this relationship. If relationship is not attached to a DbEntity, and DbEntity doesn't have a namespace, and exception is thrown.- Specified by:
- getTargetEntityin class- Relationship
 
- 
getTargetAttributesReturns a Collection of target attributes.- Since:
- 1.1
 
- 
getSourceAttributesReturns a Collection of source attributes.- Since:
- 1.1
 
- 
createReverseRelationshipCreates a new relationship with the same set of joins, but going in the opposite direction.- Since:
- 1.0.5
 
- 
getReverseRelationshipReturns 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.- Specified by:
- getReverseRelationshipin class- Relationship
 
- 
isToPKpublic boolean isToPK()Returns true if the relationship points to at least one of the PK columns of the target entity.- Since:
- 1.1
 
- 
isFromPKpublic boolean isFromPK()- Since:
- 3.0
 
- 
isToMasterPKpublic boolean isToMasterPK()Returnstrueif a methodisToDependentPKof reverse relationship of this relationship returnstrue.
- 
isSourceIndependentFromTargetChangepublic 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:
- 4.0
 
- 
isToDependentPKpublic boolean isToDependentPK()Returnstrueif 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.
- 
setToDependentPKpublic void setToDependentPK(boolean toDependentPK)
- 
isValidForDepPkpublic boolean isValidForDepPk()- Since:
- 1.1
 
- 
getJoinsReturns a list of joins. List is returned by reference, so any modifications of the list will affect this relationship.
- 
addJoinAdds a join.- Since:
- 1.1
 
- 
removeJoin
- 
removeAllJoinspublic void removeAllJoins()
- 
setJoins
- 
targetPkSnapshotWithSrcSnapshotCreates 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.
- 
srcFkSnapshotWithTargetSnapshotCreates 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".
- 
srcPkSnapshotWithTargetSnapshotCreates 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".
- 
setToManypublic void setToMany(boolean toMany)Sets relationship multiplicity.
- 
isMandatorypublic boolean isMandatory()Description copied from class:RelationshipReturns if relationship is mandatory- Specified by:
- isMandatoryin class- Relationship
 
- 
toStringDescription copied from class:RelationshipOverrides Object.toString() to return informative description.- Overrides:
- toStringin class- Relationship
 
- 
getSourceEntityName
 
-