Package org.apache.cayenne.map

# 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:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected List<DbJoin>`
  `joins`
  `protected boolean`
  `toDependentPK`

  ### Fields inherited from class org.apache.cayenne.map.Relationship

  `name, runtime, sourceEntity, targetEntityName, toMany`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DbRelationship()`
  `DbRelationship(String name)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `<T> T`
  `acceptVisitor(ConfigurationNodeVisitor<T> visitor)`
  `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, ConfigurationNodeVisitor delegate)`
  Prints itself as XML to the provided XMLEncoder.
  `List<DbJoin>`
  `getJoins()`
  Returns a list of joins.
  `DbRelationship`
  `getReverseRelationship()`
  Returns DbRelationship that is the opposite of this DbRelationship.
  `Collection<DbAttribute>`
  `getSourceAttributes()`
  Returns a Collection of source attributes.
  `String`
  `getSourceEntityName()`
  `Collection<DbAttribute>`
  `getTargetAttributes()`
  Returns a Collection of target attributes.
  `DbEntity`
  `getTargetEntity()`
  Returns a target of this relationship.
  `boolean`
  `isFromPK()`
  `boolean`
  `isMandatory()`
  Returns if relationship is mandatory
  `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`
  `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(Collection<DbJoin> newJoins)`
  `void`
  `setToDependentPK(boolean toDependentPK)`
  `void`
  `setToMany(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.
  `String`
  `toString()`
  Overrides Object.toString() to return informative description.

  ### Methods inherited from class org.apache.cayenne.map.Relationship

  `getName, getParent, getSourceEntity, getTargetEntityName, isRuntime, isToMany, setName, setParent, setRuntime, setSourceEntity, setTargetEntityName, setTargetEntityName`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### joins

    protected List<DbJoin> joins

  - ### toDependentPK

    protected boolean toDependentPK

- ## Constructor Details

  - ### DbRelationship

    public DbRelationship()

  - ### DbRelationship

    public DbRelationship(String name)

- ## Method Details

  - ### acceptVisitor

    public <T> T acceptVisitor(ConfigurationNodeVisitor<T> visitor)
    Specified by:
      `acceptVisitor` in interface `ConfigurationNode`
    Since:
      3.1

  - ### encodeAsXML

    public void encodeAsXML(XMLEncoder encoder, ConfigurationNodeVisitor delegate)
    Prints itself as XML to the provided XMLEncoder.
    Specified by:
      `encodeAsXML` in interface `XMLSerializable`
    Since:
      1.1

  - ### getTargetEntity

    public DbEntity 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:
      `getTargetEntity` in class `Relationship<DbEntity,DbAttribute,DbRelationship>`

  - ### getTargetAttributes

    public Collection<DbAttribute> getTargetAttributes()
    Returns a Collection of target attributes.
    Since:
      1.1

  - ### getSourceAttributes

    public Collection<DbAttribute> 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.
    Specified by:
      `getReverseRelationship` in class `Relationship<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()
    Returns `true` if a method `isToDependentPK` of reverse relationship of this relationship returns `true`.

  - ### 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()
    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 List<DbJoin> 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(Collection<DbJoin> newJoins)

  - ### targetPkSnapshotWithSrcSnapshot

    public 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. 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 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. Only "to-one" relationships are supported. Throws CayenneRuntimeException if relationship is "to many".

  - ### srcPkSnapshotWithTargetSnapshot

    public 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. 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: `Relationship`
    Returns if relationship is mandatory
    Specified by:
      `isMandatory` in class `Relationship<DbEntity,DbAttribute,DbRelationship>`

  - ### toString

    public String toString()
    Description copied from class: `Relationship`
    Overrides Object.toString() to return informative description.
    Overrides:
      `toString` in class `Relationship<DbEntity,DbAttribute,DbRelationship>`

  - ### getSourceEntityName

    public String getSourceEntityName()