Class DbRelationship
java.lang.Object
org.apache.cayenne.map.Relationship<DbEntity, DbAttribute, DbRelationship>
org.apache.cayenne.map.DbRelationship
- All Implemented Interfaces:
Serializable, ConfigurationNode, CayenneMapEntry, XMLSerializable
public class DbRelationship
extends Relationship<DbEntity, DbAttribute, DbRelationship>
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:
-
Field Summary
FieldsFields inherited from class Relationship
name, runtime, sourceEntity, targetEntityName, toMany -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TacceptVisitor(ConfigurationNodeVisitor<T> visitor) voidAdds a join.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.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.booleanisFromPK()booleanReturns if relationship is mandatorybooleanReturns a boolean indicating whether modifying a target of such relationship in any way will not change the underlying table row of the source.booleanReturnstrueif relationship from source to target points to dependent primary key.booleanReturnstrueif 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.booleanvoidvoidremoveJoin(DbJoin join) voidsetJoins(Collection<DbJoin> newJoins) voidsetToDependentPK(boolean toDependentPK) voidsetToMany(boolean toMany) Sets relationship multiplicity.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.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.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, getParent, getSourceEntity, getTargetEntityName, isRuntime, isToMany, setName, setParent, setRuntime, setSourceEntity, setTargetEntityName, setTargetEntityNameModifier and TypeMethodDescriptiongetName()Returns the name property of this object.Returns the parent map.Returns relationship source entity.Returns the name of a target entity.booleanbooleanisToMany()Returns a boolean value that determines relationship multiplicity.voidvoidStores the parent map.voidsetRuntime(boolean synthetic) voidsetSourceEntity(DbEntity sourceEntity) Sets relationship source entity.voidsetTargetEntityName(String targetEntityName) Sets the name of relationship target entity.voidsetTargetEntityName(Entity<DbEntity, DbAttribute, DbRelationship> targetEntity) Sets relationship target entity.
-
Field Details
-
joins
-
toDependentPK
protected boolean toDependentPK
-
-
Constructor Details
-
DbRelationship
public DbRelationship() -
DbRelationship
-
-
Method Details
-
acceptVisitor
- Specified by:
acceptVisitorin interfaceConfigurationNode- 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 the relationship points to at least one of the PK columns of the target entity.- Since:
- 1.1
-
isFromPK
public boolean isFromPK()- Since:
- 3.0
-
isToMasterPK
public boolean isToMasterPK()Returnstrueif a methodisToDependentPKof reverse relationship of this relationship returnstrue. -
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:
- 4.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. -
srcFkSnapshotWithTargetSnapshot
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
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. -
isMandatory
public boolean isMandatory()Description copied from class:RelationshipReturns if relationship is mandatory- Specified by:
isMandatoryin classRelationship<DbEntity, DbAttribute, DbRelationship>
-
toString
Description copied from class:RelationshipOverrides Object.toString() to return informative description.- Overrides:
toStringin classRelationship<DbEntity, DbAttribute, DbRelationship>
-
getSourceEntityName
-