java.lang.Object
org.fuin.cqrs4j.Cqrs4JUtils
Provides some helper methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionClasses used for JAX-B serialization.static final StringResult code forverifyParamEntityIdPathEqualsCmdEntityIdPath(AggregateCommand, EntityId...)failures.static final StringSome constraints were violated.static final StringPrefix for unique short identifiers. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidWaits until a lock is available and executes the code after it was acquired.static voidTries to acquire a lock and runs the code.static <ID extends org.fuin.ddd4j.ddd.EntityId>
Result<?>verifyParamEntityIdPathEqualsCmdEntityIdPath(@NotNull AggregateCommand<?, ?> cmd, @NotNull ID... entityIds) Verifies that an aggregate identifier from a parameter is equal to the aggregate identifier from the command.static Result<?>verifyPrecondition(@NotNull jakarta.validation.Validator validator, @NotNull Object obj) Verifies a precondition.
-
Field Details
-
JAXB_CLASSES
Classes used for JAX-B serialization. -
PRECONDITION_VIOLATED
Some constraints were violated.- See Also:
-
PARAM_ENTITY_PATH_NOT_EQUAL_CMD_ENTITY_PATH
Result code forverifyParamEntityIdPathEqualsCmdEntityIdPath(AggregateCommand, EntityId...)failures.- See Also:
-
SHORT_ID_PREFIX
Prefix for unique short identifiers.- See Also:
-
-
Method Details
-
tryLocked
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
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.
-