Class DocumentHandlerDecorator

java.lang.Object
io.fluxzero.sdk.tracking.handling.DocumentHandlerDecorator
All Implemented Interfaces:
HandlerDecorator

public class DocumentHandlerDecorator extends Object implements HandlerDecorator
A HandlerDecorator that intercepts handler methods annotated with HandleDocument and synchronizes their return values with a DocumentStore.

This decorator ensures that searchable document views (e.g. projections or read models) are automatically updated when a message is handled. If the handler method returns an object of the same type as the incoming message payload (and is non-passive), the decorator will:

  • Index the return value into the configured document store, if non-null and its Revision is newer than the original version (before upcasting).
  • Delete the corresponding document if the return value is null.
Materialized Model Graph handlers use a separate result contract: returning their complete typed Graph may migrate only the derived graph document and never invokes this ordinary document update path.

The collection name is derived from the message topic. Timestamps for indexing can be determined in two ways:

  • If SearchParameters are available, they are used to extract timestamps.
  • Otherwise, the message metadata keys "$start" and "$end" are used (if present).

Example Usage

@HandleDocument
UserProfile update(UserProfile document) {
    return document.toBuilder().status(active).build(); //gives every existing user a status of active
}
See Also: