Class DbRelationship
java.lang.Object
org.apache.cayenne.map.Relationship<DbEntity, DbAttribute, DbRelationship>
org.apache.cayenne.map.DbRelationship
- All Implemented Interfaces:
ProjectNode, XMLSerializable
public class DbRelationship
extends Relationship<DbEntity, DbAttribute, DbRelationship>
implements ProjectNode
A DbRelationship is a descriptor of a database inter-table relationship based
on one or more primary key/foreign key pairs.
-
Field Summary
FieldsFields inherited from class Relationship
name, runtime, sourceEntity, targetEntityName, toMany -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TacceptVisitor(ProjectNodeVisitor<T> visitor) voidAdds a join.Creates a new relationship with the same set of joins, but going in the opposite direction.voidencodeAsXML(XMLEncoder encoder, ProjectNodeVisitor<?> delegate) Prints itself as XML to the provided XMLEncoder.getJoins()Returns a list of joins.Returns DbRelationship that is the opposite of this DbRelationship.Returns a Collection of source attributes.Returns a Collection of target attributes.Returns a target of this relationship.booleanisFromFK()Returns true if this relationship's source owns the foreign key side of the relationship.booleanReturnstrueif relationship from source to target points to dependent primary key.booleanisToPK()Returns true if every join of this relationship points to a PK column of the target entity.booleanvoidvoidremoveJoin(DbJoin join) voidsetJoins(Collection<DbJoin> newJoins) voidsetToDependentPK(boolean toDependentPK) voidsetToMany(boolean toMany) Sets relationship multiplicity.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.toString()Overrides Object.toString() to return informative description.Methods inherited from class Relationship
getName, getSourceEntity, getTargetEntityName, isRuntime, isToMany, setName, setRuntime, setSourceEntity, setTargetEntityName, setTargetEntityName
-
Field Details
-
joins
-
toDependentPK
protected boolean toDependentPK
-
-
Constructor Details
-
DbRelationship
public DbRelationship() -
DbRelationship
-
-
Method Details
-
acceptVisitor
- Specified by:
acceptVisitorin interfaceProjectNode- Since:
- 3.1
-
encodeAsXML
Prints itself as XML to the provided XMLEncoder.- Specified by:
encodeAsXMLin interfaceXMLSerializable- Since:
- 1.1
-
getTargetEntity
Returns 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 classRelationship<DbEntity, DbAttribute, DbRelationship>
-
getTargetAttributes
Returns a Collection of target attributes.- Since:
- 1.1
-
getSourceAttributes
Returns a Collection of source attributes.- Since:
- 1.1
-
createReverseRelationship
Creates a new relationship with the same set of joins, but going in the opposite direction.- Since:
- 1.0.5
-
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.- Specified by:
getReverseRelationshipin classRelationship<DbEntity, DbAttribute, DbRelationship>
-
isToPK
public boolean isToPK()Returns true if every join of this relationship points to a PK column of the target entity. This is a structural fact about the joins; whether the source row actually holds the FK isisFromFK().- Since:
- 1.1
-
isFromFK
public boolean isFromFK()Returns true if this relationship's source owns the foreign key side of the relationship. I.e., the source join columns are all foreign keys.- Since:
- 5.0
-
isToDependentPK
public 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. -
setToDependentPK
public void setToDependentPK(boolean toDependentPK) -
isValidForDepPk
public boolean isValidForDepPk()- Since:
- 1.1
-
getJoins
-
addJoin
-
removeJoin
-
removeAllJoins
public void removeAllJoins() -
setJoins
-
targetPkSnapshotWithSrcSnapshot
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. -
setToMany
public void setToMany(boolean toMany) Sets relationship multiplicity. -
toString
Description copied from class:RelationshipOverrides Object.toString() to return informative description.- Overrides:
toStringin classRelationship<DbEntity, DbAttribute, DbRelationship>
-
getSourceEntityName
-