Record Class Relationship

java.lang.Object
java.lang.Record
com.darkcollective.relix.symbol.graph.Relationship
Record Components:
name - the relationship name; never blank
inverseName - the optional name of the reverse traversal
symmetric - whether this self-referential relationship is symmetric
source - the source endpoint
target - the target endpoint; its column list has the same length as the source's (validated at assembly with a positioned diagnostic, not here)
origin - how this edge entered the graph

public record Relationship(String name, Optional<String> inverseName, boolean symmetric, Endpoint source, Endpoint target, EdgeOrigin origin) extends Record
A named relationship edge of the SchemaGraph.

Edges are named because names are what make ambiguity speakable: with two foreign keys from issues into users, "assignee or reporter?" is a question a user can answer where "path A or path B?" is not. An asymmetric edge may also name its reverse traversal (inverseName — "Reports To" for a "Manages" edge); presence of an inverse name is how the representation records that the two directions are distinct roles.

symmetric applies to self-referential edges only (product cross-sells, friend graphs) and records that the relationship has no direction at the data level — a fact the engine cannot derive and would otherwise guess wrong when traversing. It is mutually exclusive with an inverse name (a symmetric edge has no distinct roles to name).

Neither name nor symmetry affects walkability: every edge is traversable in both directions for path-search purposes, because a join is symmetric regardless of which side owns the foreign key.

  • Constructor Details

    • Relationship

      public Relationship(String name, Optional<String> inverseName, boolean symmetric, Endpoint source, Endpoint target, EdgeOrigin origin)
      Creates an instance of a Relationship record class.
      Parameters:
      name - the value for the name record component
      inverseName - the value for the inverseName record component
      symmetric - the value for the symmetric record component
      source - the value for the source record component
      target - the value for the target record component
      origin - the value for the origin record component
  • Method Details

    • edgeIdentity

      public String edgeIdentity()
      This edge's identity as a join, ignoring what it is called and which way round it was written: the two endpoints, each a relation and its lower-cased columns, in a fixed order.

      Two relationships with the same identity join the same rows. That is the sameness a caller holding several edges needs: an edge learned from a query and a declared one over the same columns are the same edge under two names, and A.x = B.y is the same edge as B.y = A.x.

      Returns:
      the identity; never null
      Since:
      1.0
    • selfReferential

      public boolean selfReferential()
      Returns true if this edge connects a relation to itself.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • inverseName

      public Optional<String> inverseName()
      Returns the value of the inverseName record component.
      Returns:
      the value of the inverseName record component
    • symmetric

      public boolean symmetric()
      Returns the value of the symmetric record component.
      Returns:
      the value of the symmetric record component
    • source

      public Endpoint source()
      Returns the value of the source record component.
      Returns:
      the value of the source record component
    • target

      public Endpoint target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • origin

      public EdgeOrigin origin()
      Returns the value of the origin record component.
      Returns:
      the value of the origin record component