Class AnnotationBasedEventCriteriaResolver<E,ID>

java.lang.Object
org.axonframework.eventsourcing.annotation.AnnotationBasedEventCriteriaResolver<E,ID>
Type Parameters:
E - The type of the entity to create.
ID - The type of the identifier of the entity to create.
All Implemented Interfaces:
DescribableComponent, CriteriaResolver<ID>

public class AnnotationBasedEventCriteriaResolver<E,ID> extends Object implements CriteriaResolver<ID>, DescribableComponent
Annotation-based CriteriaResolver implementation which resolves EventCriteria based on the given id for loading the entity. This is the default when using the EventSourcedEntity annotation.

There are various ways to define how the EventCriteria should be resolved. In order of precedence:

  1. By defining a static method in the entity class annotated with EventCriteriaBuilder which returns an EventCriteria and accepts the id as a parameter. This method should be static and return an EventCriteria. Multiple methods can be defined with different id types, and the first matching method will be used. You can also inject components from the Configuration as parameters to the method.
  2. If no matching EventCriteriaBuilder is found, the EventSourcedEntity.tagKey() will be used as the tag key, and the Object.toString() of the id will be used as value.
  3. If the EventSourcedEntity.tagKey() is empty, the Class.getSimpleName() of the entity will be used as tag key, and the Object.toString() of the id will be used as value.

Different methods can be combined, as can several EventCriteriaBuilder methods be defined as long as they are for different id types. This resolver is the default when using the EventSourcedEntity annotation, but specifying a custom CriteriaResolver will override this behavior.

Since:
5.0.0
Author:
Mitchell Herrijgers
See Also:
  • Constructor Details

    • AnnotationBasedEventCriteriaResolver

      public AnnotationBasedEventCriteriaResolver(@Nonnull Class<E> entityType, @Nonnull Class<ID> idType, @Nonnull Configuration configuration)
      Initialize the resolver for the given entityType. The entity type should be annotated with EventSourcedEntity, or this resolver will throw an IllegalArgumentException.

      Will check for methods annotated with EventCriteriaBuilder and store them in a map for later use. If one of the methods is invalid as defined in the Javadoc of EventCriteriaBuilder, an IllegalArgumentException will be thrown.

      Parameters:
      entityType - The entity type to resolve criteria for.
      idType - The identifier type to resolve criteria for.
      configuration - The configuration to use for resolving the criteria.
  • Method Details

    • resolve

      @Nonnull public EventCriteria resolve(@Nonnull Object id, @Nonnull ProcessingContext context)
      Description copied from interface: CriteriaResolver
      Resolves the given identifier to an EventCriteria.
      Specified by:
      resolve in interface CriteriaResolver<E>
      Parameters:
      id - The instance to resolve to an EventCriteria.
      context - The ProcessingContext in which the criteria is being resolved.
      Returns:
      The given identifier resolved to an EventCriteria.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.