Record Class SeqNoPrimaryTerm

java.lang.Object
java.lang.Record
org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm

public record SeqNoPrimaryTerm(long sequenceNumber, long primaryTerm) extends Record

A container for seq_no and primary_term values. When an entity class contains a field of this type, it will be automatically filled with SeqNoPrimaryTerm instance on read operations (like get or search), and also, when the SeqNoPrimaryTerm is not null and filled with seq_no and primary_term, they will be sent to Elasticsearch when indexing such an entity.

This allows to implement optimistic locking pattern for full-update scenario, when an entity is first read from Elasticsearch and then gets reindexed with new _content. Index operations will throw an OptimisticLockingFailureException if the seq_no + primary_term pair already has different values for the given document. See Elasticsearch documentation for more information: https://www.elastic.co/guide/en/elasticsearch/reference/current/optimistic-concurrency-control.html

A property of this type is implicitly @Transient and never gets included into a mapping at Elasticsearch side.

A SeqNoPrimaryTerm instance cannot contain an invalid or unassigned seq_no or primary_term.

Since:
4.0
Author:
Roman Puchkovskiy
  • Constructor Summary

    Constructors
    Constructor
    Description
    SeqNoPrimaryTerm(long sequenceNumber, long primaryTerm)
    Creates an instance of SeqNoPrimaryTerm with the given seq_no and primary_term.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    long
    Returns the value of the primaryTerm record component.
    long
    Returns the value of the sequenceNumber record component.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SeqNoPrimaryTerm

      public SeqNoPrimaryTerm(long sequenceNumber, long primaryTerm)
      Creates an instance of SeqNoPrimaryTerm with the given seq_no and primary_term. The passed values are validated: sequenceNumber must be non-negative, primaryTerm must be positive. If validation fails, an IllegalArgumentException is thrown.
      Parameters:
      sequenceNumber - seq_no, must not be negative
      primaryTerm - primary_term, must be positive
      Throws:
      IllegalArgumentException - if seq_no or primary_term is not valid
  • Method Details

    • toString

      public 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. All components in this record class 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.
    • sequenceNumber

      public long sequenceNumber()
      Returns the value of the sequenceNumber record component.
      Returns:
      the value of the sequenceNumber record component
    • primaryTerm

      public long primaryTerm()
      Returns the value of the primaryTerm record component.
      Returns:
      the value of the primaryTerm record component