Class 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>
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:
-
By defining a static method in the entity class annotated with
EventCriteriaBuilderwhich returns anEventCriteriaand accepts theidas a parameter. This method should be static and return anEventCriteria. Multiple methods can be defined with different id types, and the first matching method will be used. You can also inject components from theConfigurationas parameters to the method. -
If no matching
EventCriteriaBuilderis found, theEventSourcedEntity.tagKey()will be used as the tag key, and theObject.toString()of the id will be used as value. -
If the
EventSourcedEntity.tagKey()is empty, theClass.getSimpleName()of the entity will be used as tag key, and theObject.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 Summary
ConstructorsConstructorDescriptionAnnotationBasedEventCriteriaResolver(Class<E> entityType, Class<ID> idType, Configuration configuration) Initialize the resolver for the givenentityType. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.resolve(Object id, ProcessingContext context) Resolves the givenidentifierto anEventCriteria.
-
Constructor Details
-
AnnotationBasedEventCriteriaResolver
public AnnotationBasedEventCriteriaResolver(@Nonnull Class<E> entityType, @Nonnull Class<ID> idType, @Nonnull Configuration configuration) Initialize the resolver for the givenentityType. The entity type should be annotated withEventSourcedEntity, or this resolver will throw anIllegalArgumentException.Will check for methods annotated with
EventCriteriaBuilderand store them in a map for later use. If one of the methods is invalid as defined in the Javadoc ofEventCriteriaBuilder, anIllegalArgumentExceptionwill 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
Description copied from interface:CriteriaResolverResolves the givenidentifierto anEventCriteria.- Specified by:
resolvein interfaceCriteriaResolver<E>- Parameters:
id- The instance to resolve to anEventCriteria.context- TheProcessingContextin which the criteria is being resolved.- Returns:
- The given
identifierresolved to anEventCriteria.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods 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
DescribableComponentimplementation 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 thedescribeTomethod, 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:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-