Record Class TransactionResult

java.lang.Object
java.lang.Record
com.loomcache.server.transaction.TransactionResult
Record Components:
succeeded - true if all conditions were met and THEN operations executed, false if any condition failed and ELSE operations executed
responses - unmodifiable list of responses from executed operations (never null)

public record TransactionResult(boolean succeeded, List<String> responses) extends Record
Result of executing an atomic transaction.

Semantics: Indicates whether the transaction succeeded (all conditions met and THEN branch executed) or failed (any condition failed and ELSE branch executed), along with the results of the executed operations.

Immutability: This record is immutable. The responses list is unmodifiable, preventing accidental mutations after transaction execution.

Use Cases:

  • Check succeeded() to determine if conditions were met
  • Retrieve responses() to get operation results (GET operations, etc.)
  • Use for audit logging and transaction replay
Since:
1.0
  • Constructor Details

    • TransactionResult

      public TransactionResult(boolean succeeded, List<String> responses)
      Compact constructor for validation.

      Ensures responses is not null and converts it to an unmodifiable list.

      Throws:
      NullPointerException - if responses is null
  • Method Details

    • success

      public static TransactionResult success(List<String> responses)
      Creates a successful transaction result with the given responses.
      Parameters:
      responses - the responses from the executed THEN operations (must not be null)
      Returns:
      a successful TransactionResult (never null)
      Throws:
      NullPointerException - if responses is null
    • failure

      public static TransactionResult failure(List<String> responses)
      Creates a failed transaction result with the given responses.
      Parameters:
      responses - the responses from the executed ELSE operations (must not be null)
      Returns:
      a failed TransactionResult (never null)
      Throws:
      NullPointerException - if responses is null
    • success

      public static TransactionResult success()
      Creates a successful transaction result with no responses.
      Returns:
      a successful TransactionResult with an empty responses list (never null)
    • failure

      public static TransactionResult failure()
      Creates a failed transaction result with no responses.
      Returns:
      a failed TransactionResult with an empty responses list (never null)
    • 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 the compare method from their corresponding wrapper classes.
      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.
    • succeeded

      public boolean succeeded()
      Returns the value of the succeeded record component.
      Returns:
      the value of the succeeded record component
    • responses

      public List<String> responses()
      Returns the value of the responses record component.
      Returns:
      the value of the responses record component