Class RelationshipBase<S extends NodeBase<?>,E extends NodeBase<?>,SELF extends RelationshipBase<S,E,SELF>>

java.lang.Object
org.neo4j.cypherdsl.core.RelationshipBase<S,E,SELF>
Type Parameters:
S - The type at the start of the relationship
E - The type at the pointy end of the relationship
SELF - The type of the persistent relationship itself
All Implemented Interfaces:
Visitable, ExposesPatternLengthAccessors<Relationship>, ExposesProperties<Relationship>, ExposesRelationships<RelationshipChain>, IdentifiableElement, Named, PatternElement, PropertyContainer, Relationship, RelationshipPattern

@API(status=STABLE, since="2021.1.0") public abstract class RelationshipBase<S extends NodeBase<?>,E extends NodeBase<?>,SELF extends RelationshipBase<S,E,SELF>> extends Object implements Relationship
This is the base class for all relationships. It can be used with generics, specifying valid start and end nodes. This is useful when using it as a base class for a static meta model.
Since:
2021.1.0
Author:
Michael J. Simons
  • Constructor Details

    • RelationshipBase

      protected RelationshipBase(S start, String type, E end, String... additionalTypes)
      Always creates a relationship from start to end (left to right).
      Parameters:
      start - start node
      type - type of the relationship
      end - end node
      additionalTypes - additional types to add to the relationship
    • RelationshipBase

      protected RelationshipBase(SymbolicName symbolicName, Node start, String type, Properties properties, Node end, String... additionalTypes)
      Always creates a relationship from start to end (left to right).
      Parameters:
      symbolicName - an optional symbolic name
      start - start node
      type - type of the relationship
      properties - The properties for the relationship
      end - end node
      additionalTypes - Additional types to be added to the relationship, only meaningfull when the object is used for querying, when used in a CREATE or MERGE clause the runtime will throw an exception.
    • RelationshipBase

      protected RelationshipBase(SymbolicName symbolicName, String type, Node start, Properties properties, Node end)
      Always creates a relationship from start to end (left to right).
      Parameters:
      symbolicName - an optional symbolic name
      type - type of the relationship
      start - start node
      properties - The properties for the relationship
      end - end node
  • Method Details

    • named

      @NotNull public final SELF named(String newSymbolicName)
      Description copied from interface: Relationship
      Creates a copy of this relationship with a new symbolic name.
      Specified by:
      named in interface Relationship
      Specified by:
      named in interface RelationshipPattern
      Parameters:
      newSymbolicName - the new symbolic name.
      Returns:
      The new relationship.
    • named

      @NotNull public abstract SELF named(SymbolicName newSymbolicName)
      This method needs to be implemented to provide new, type safe instances of this relationship.
      Specified by:
      named in interface Relationship
      Specified by:
      named in interface RelationshipPattern
      Parameters:
      newSymbolicName - the new symbolic name.
      Returns:
      A new relationship
    • withProperties

      @NotNull public final SELF withProperties(Object... keysAndValues)
      Description copied from interface: ExposesProperties
      Creates a copy of this property container with additional properties. Creates a property container without properties when no properties are passed to this method.
      Specified by:
      withProperties in interface ExposesProperties<S extends NodeBase<?>>
      Parameters:
      keysAndValues - A list of key and values. Must be an even number, with alternating String and Expression.
      Returns:
      The new property container.
    • withProperties

      @NotNull public final SELF withProperties(Map<String,Object> newProperties)
      Description copied from interface: ExposesProperties
      Creates a copy of this property container with additional properties.
      Specified by:
      withProperties in interface ExposesProperties<S extends NodeBase<?>>
      Parameters:
      newProperties - A map with the new properties
      Returns:
      The new property container.
    • withProperties

      @NotNull public abstract SELF withProperties(MapExpression newProperties)
      This method needs to be implemented to provide new, type safe instances of this relationship.
      Specified by:
      withProperties in interface ExposesProperties<S extends NodeBase<?>>
      Parameters:
      newProperties - the new properties (can be null to remove exiting properties).
      Returns:
      A new relationship
    • getLeft

      @NotNull public final @NotNull Node getLeft()
      Specified by:
      getLeft in interface Relationship
      Returns:
      the left-hand side of this relationship
    • getRight

      @NotNull public final @NotNull Node getRight()
      Specified by:
      getRight in interface Relationship
      Returns:
      the right-hand side of this relationship
    • getQuantifier

      @Nullable public final QuantifiedPathPattern.Quantifier getQuantifier()
      Description copied from interface: Relationship
      Returns the quantifier of this relationship if any.
      Specified by:
      getQuantifier in interface Relationship
      Returns:
      the quantifier of this relationship if any
    • getDetails

      @NotNull public final @NotNull Relationship.Details getDetails()
      Description copied from interface: Relationship
      The details containing the types, properties and cardinality.
      Specified by:
      getDetails in interface Relationship
      Returns:
      A wrapper around the details of this relationship.
    • unbounded

      @NotNull public final @NotNull Relationship unbounded()
      Description copied from interface: ExposesPatternLengthAccessors
      Creates a new relationship pattern with an unbound length minimum length
      Specified by:
      unbounded in interface ExposesPatternLengthAccessors<S extends NodeBase<?>>
      Returns:
      the new relationship
    • min

      @NotNull public final @NotNull Relationship min(Integer minimum)
      Description copied from interface: ExposesPatternLengthAccessors
      Creates a new relationship pattern with a new minimum length
      Specified by:
      min in interface ExposesPatternLengthAccessors<S extends NodeBase<?>>
      Parameters:
      minimum - the new minimum
      Returns:
      the new relationship
    • max

      @NotNull public final @NotNull Relationship max(Integer maximum)
      Description copied from interface: ExposesPatternLengthAccessors
      Creates a new relationship pattern with a new maximum length
      Specified by:
      max in interface ExposesPatternLengthAccessors<S extends NodeBase<?>>
      Parameters:
      maximum - the new maximum
      Returns:
      the new relationship
    • length

      @NotNull public final @NotNull Relationship length(Integer minimum, Integer maximum)
      Description copied from interface: ExposesPatternLengthAccessors
      Creates a new relationship pattern with a new length
      Specified by:
      length in interface ExposesPatternLengthAccessors<S extends NodeBase<?>>
      Parameters:
      minimum - the new minimum
      maximum - the new maximum
      Returns:
      the new relationship
    • inverse

      @NotNull public final @NotNull Relationship inverse()
      Description copied from interface: Relationship
      Creates a new relationship, inverting the direction but keeping the semantics intact ((a) --> (b) becomes (b) <-- (a)). A symbolic name will be removed from this relationship if any, as the it wouldn't be the same pattern to match against.
      Specified by:
      inverse in interface Relationship
      Returns:
      the new relationship
    • getSymbolicName

      @NotNull public final @NotNull Optional<SymbolicName> getSymbolicName()
      Specified by:
      getSymbolicName in interface Named
      Returns:
      An optional symbolic name.
    • getRequiredSymbolicName

      @NotNull public final @NotNull SymbolicName getRequiredSymbolicName()
      Specified by:
      getRequiredSymbolicName in interface Named
      Returns:
      A symbolic name
    • relationshipTo

      @NotNull public final @NotNull RelationshipChain relationshipTo(Node other, String... types)
      Description copied from interface: ExposesRelationships
      Starts building an outgoing relationship to the other node.
      Specified by:
      relationshipTo in interface ExposesRelationships<S extends NodeBase<?>>
      Parameters:
      other - The other end of the outgoing relationship
      types - The types to match
      Returns:
      An ongoing relationship definition, that can be used to specify the type
    • relationshipFrom

      @NotNull public final @NotNull RelationshipChain relationshipFrom(Node other, String... types)
      Description copied from interface: ExposesRelationships
      Starts building an incoming relationship starting at the other node.
      Specified by:
      relationshipFrom in interface ExposesRelationships<S extends NodeBase<?>>
      Parameters:
      other - The source of the incoming relationship
      types - The types to match
      Returns:
      An ongoing relationship definition, that can be used to specify the type
    • relationshipBetween

      @NotNull public final @NotNull RelationshipChain relationshipBetween(Node other, String... types)
      Description copied from interface: ExposesRelationships
      Starts building an undirected relationship between this node and the other.
      Specified by:
      relationshipBetween in interface ExposesRelationships<S extends NodeBase<?>>
      Parameters:
      other - The other end of the relationship
      types - The types to match
      Returns:
      An ongoing relationship definition, that can be used to specify the type
    • asCondition

      @NotNull public final @NotNull Condition asCondition()
      Description copied from interface: RelationshipPattern
      Transform this pattern into a condition. All names of the patterns must be known upfront in the final statement, as PatternExpressions are not allowed to introduce new variables.
      Specified by:
      asCondition in interface RelationshipPattern
      Returns:
      A condition based on this pattern.
    • accept

      public final void accept(Visitor visitor)
      Description copied from interface: Visitable
      Accept a Visitor visiting this Visitable and its nested Visitables if applicable.
      Specified by:
      accept in interface Visitable
      Parameters:
      visitor - the visitor to notify, must not be null.
    • toString

      public String toString()
      Description copied from interface: Visitable
      Most visitables will render themselves into a Cypher fragment preceded with the actual classname. The representation however is not cached - in contrast to the ones for full statements. Using toString is recommended for debugging purposes mainly, and not for production use.

      The concrete classname has been prepended to help debugging and actually to discourage using fragments to build queries without explicitly rendering them, either as statement or going through the renderer on purpose.

      Specified by:
      toString in interface Visitable
      Overrides:
      toString in class Object
      Returns:
      A string representation of this visitable formatted as Classname{cypher=value}
    • where

      @NotNull public @NotNull Relationship where(@Nullable @Nullable Expression predicate)
      Description copied from interface: PatternElement
      Creates a new PatternElement which including an additional filter. Returns this pattern. when predicate is literal null.

      The pattern might be a node pattern or a relationship pattern.

      A WHERE on a pattern is only supported from Neo4j 5.0 onwards.

      Specified by:
      where in interface PatternElement
      Parameters:
      predicate - the predicate to filter on
      Returns:
      a new pattern element or this instance if the predicate to this method was literal null
    • quantifyRelationship

      @NotNull public @NotNull RelationshipPattern quantifyRelationship(@Nullable QuantifiedPathPattern.Quantifier newQuantifier)
      Description copied from interface: RelationshipPattern
      Quantifies the relationship.
      Specified by:
      quantifyRelationship in interface RelationshipPattern
      Parameters:
      newQuantifier - the quantifier to use
      Returns:
      a quantified relationship
    • quantify

      @NotNull public @NotNull QuantifiedPathPattern quantify(@Nullable QuantifiedPathPattern.Quantifier newQuantifier)
      Description copied from interface: RelationshipPattern
      Quantifies the pattern.
      Specified by:
      quantify in interface RelationshipPattern
      Parameters:
      newQuantifier - the quantifier to use
      Returns:
      a quantified path pattern
    • property

      @NotNull public final @NotNull Property property(@NotNull @NotNull String name)
      Description copied from interface: PropertyContainer
      Creates a new Property associated with this property container. This property can be used as a lookup in other expressions. It does not add a value to the property.

      Note: The property container does not track property creation and there is no possibility to enumerate all properties that have been created for this property container.

      Specified by:
      property in interface PropertyContainer
      Parameters:
      name - property name, must not be null or empty.
      Returns:
      a new Property associated with this named container
    • property

      @NotNull public final @NotNull Property property(String... names)
      Specified by:
      property in interface PropertyContainer
      Parameters:
      names - a list of nested property names
      Returns:
      a new Property associated with this named container
      See Also:
    • property

      @NotNull public final @NotNull Property property(Expression lookup)
      Description copied from interface: PropertyContainer
      Creates a new Property associated with this property container. This property can be used as a lookup in other expressions. It does not add a value to the property.

      The new Property object is a dynamic lookup, based on the expression passed to this method. The expression can be example another property, a function result or a Cypher parameter. A property defined in such a way will render as p[expression].

      Note: The property container does not track property creation and there is no possibility to enumerate all properties that have been created for this property container.

      Specified by:
      property in interface PropertyContainer
      Parameters:
      lookup - the expression that is evaluated to lookup this property.
      Returns:
      a new Property associated with this named container
    • mutate

      @NotNull public final @NotNull Operation mutate(Parameter<?> parameter)
      Description copied from interface: PropertyContainer
      Creates an Operation mutating the properties of this container to a new value. The container does not track the operations created with this method.
      Specified by:
      mutate in interface PropertyContainer
      Parameters:
      parameter - the new properties
      Returns:
      A new operation.
    • mutate

      @NotNull public final @NotNull Operation mutate(MapExpression properties)
      Description copied from interface: PropertyContainer
      Creates an Operation mutating the properties of this container to a new value. The container does not track the operations created with this method.
      Specified by:
      mutate in interface PropertyContainer
      Parameters:
      properties - the new properties
      Returns:
      A new operation.
    • set

      @NotNull public final @NotNull Operation set(Parameter<?> parameter)
      Description copied from interface: PropertyContainer
      Creates an SET operation setting the properties of this container to a new value. The container does not track the operations created with this method.
      Specified by:
      set in interface PropertyContainer
      Parameters:
      parameter - the new properties
      Returns:
      A new operation.
    • set

      @NotNull public final @NotNull Operation set(MapExpression properties)
      Description copied from interface: PropertyContainer
      Creates an SET operation setting the properties of this container to a new value. The container does not track the operations created with this method.
      Specified by:
      set in interface PropertyContainer
      Parameters:
      properties - the new properties
      Returns:
      A new operation.
    • project

      @NotNull public final @NotNull MapProjection project(List<Object> entries)
      Description copied from interface: PropertyContainer
      Unwraps the list of entries into an array before creating a projection out of it.
      Specified by:
      project in interface PropertyContainer
      Parameters:
      entries - A list of entries for the projection
      Returns:
      A map projection.
      See Also:
    • project

      @NotNull public final @NotNull MapProjection project(Object... entries)
      Description copied from interface: PropertyContainer
      Creates a map projection based on this container. The container needs a symbolic name for this to work.
      Specified by:
      project in interface PropertyContainer
      Parameters:
      entries - A list of entries for the projection
      Returns:
      A map projection.
      See Also: