Class ConvertCommandHandlerConstructorToStaticMethod
- All Implemented Interfaces:
Cloneable
@CommandHandler constructors into static handle
methods, the AF5 idiom for "creational" command handlers.
In AF4, an aggregate's create-command was typically dispatched into a constructor annotated
with @CommandHandler. AF5 narrows the @CommandHandler target to
METHOD / ANNOTATION_TYPE only, so a literal AF4-style constructor handler
fails to compile. The AF5-equivalent shape (see @EntityCreator javadoc, "Immutable
entity" example) is a static method on the entity that publishes the creation event;
the entity itself is then created by an @EntityCreator factory invoked when the
event is sourced.
The transformation applied per matching constructor:
@CommandHandler @CommandHandler
public Payment(PreparePaymentCommand cmd, → public static void handle(PreparePaymentCommand cmd,
EventAppender appender) { EventAppender appender) {
appender.append(...); appender.append(...);
} }
Both AF4 (org.axonframework.commandhandling.CommandHandler) and AF5
(org.axonframework.messaging.commandhandling.annotation.CommandHandler) FQNs are
matched, so the recipe is order-independent with respect to the package-rename recipes in
Axon4ToAxon5Messaging.
For mutable entities whose @EntityCreator can construct the instance without an
event payload (e.g. a no-arg constructor or one that only takes @InjectEntityId),
the entity exists when the create-command arrives and an instance method would also work;
this recipe always emits a static method because that shape is correct for both the
mutable and the immutable entity patterns.
- Since:
- 5.1.1
- Author:
- Mateusz Nowak
-
Nested Class Summary
Nested classes/interfaces inherited from class org.openrewrite.Recipe
org.openrewrite.Recipe.Builder, org.openrewrite.Recipe.DelegatingRecipe -
Field Summary
Fields inherited from class org.openrewrite.Recipe
contributors, examples, PANIC -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.openrewrite.TreeVisitor<?, org.openrewrite.ExecutionContext> Methods inherited from class org.openrewrite.Recipe
addDataTable, builder, buildRecipeList, causesAnotherCycle, clone, createRecipeDescriptor, equals, getContributors, getDataTableDescriptors, getDescriptor, getEstimatedEffortPerOccurrence, getExamples, getInstanceName, getInstanceNameSuffix, getJacksonPolymorphicTypeTag, getMaintainers, getName, getRecipeList, getTags, hashCode, maxCycles, noop, onComplete, run, run, run, setContributors, setExamples, validate, validate, validateAll, validateAll, withOptions
-
Constructor Details
-
ConvertCommandHandlerConstructorToStaticMethod
public ConvertCommandHandlerConstructorToStaticMethod()
-
-
Method Details
-
getDisplayName
- Specified by:
getDisplayNamein classorg.openrewrite.Recipe
-
getDescription
- Specified by:
getDescriptionin classorg.openrewrite.Recipe
-
getVisitor
public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()- Overrides:
getVisitorin classorg.openrewrite.Recipe
-