Class Cqrs4JUtils

java.lang.Object
org.fuin.cqrs4j.Cqrs4JUtils

public final class Cqrs4JUtils extends Object
Provides some helper methods.
  • Field Details

  • Method Details

    • tryLocked

      public static void tryLocked(@NotNull @NotNull Semaphore lock, @NotNull @NotNull Runnable code)
      Tries to acquire a lock and runs the code. If no lock can be acquired, the method terminates immediately without executing anything.
      Parameters:
      lock - Semaphore to use.
      code - Code to run.
    • runLocked

      public static void runLocked(@NotNull @NotNull Semaphore lock, @NotNull @NotNull Runnable code)
      Waits until a lock is available and executes the code after it was acquired.
      Parameters:
      lock - Semaphore to use.
      code - Code to run.
    • verifyPrecondition

      public static Result<?> verifyPrecondition(@NotNull @NotNull jakarta.validation.Validator validator, @NotNull @NotNull Object obj)
      Verifies a precondition. In case of constraint violations, the error is logged and an error result is returned.
      Parameters:
      validator - Validator to use.
      obj - Object to validate. A null value is considered to be an error.
      Returns:
      Error result or null if validation was successful.
    • verifyParamEntityIdPathEqualsCmdEntityIdPath

      @SafeVarargs public static <ID extends org.fuin.ddd4j.ddd.EntityId> Result<?> verifyParamEntityIdPathEqualsCmdEntityIdPath(@NotNull @NotNull AggregateCommand<?,?> cmd, @NotNull @NotNull ID... entityIds)
      Verifies that an aggregate identifier from a parameter is equal to the aggregate identifier from the command. This is helpful, if for example the URL contains the name of the aggregate, followed by an aggregate identifier.
      Example: POST /customer/f832a5a4-dd80-49df-856a-7274de82cd6b/create
      The ID from the URL must match the aggregate ID that is passed via the command in the body.
      Type Parameters:
      ID - Type of the aggregate root identifier.
      Parameters:
      cmd - Command that has the entity identifier path to compare with.
      entityIds - Identifiers to compare with.
      Returns:
      Error result or null if validation was successful.