feature: add upcasting functionality for DomainEvent and AggregateState classes#79
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request adds upcasting functionality for DomainEvent and AggregateState classes by introducing an annotation, processor methods, and corresponding adapter implementations. Key changes include:
- Introduction of the @UpcastingHandler annotation.
- Implementation of upcasting processing logic in AggregateBeanFactoryPostProcessor.
- Addition of UpcastingHandlerFunction and its adapters for both domain events and aggregate states, along with related updates to SchemaType and type definitions.
Reviewed Changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| main/api/src/main/java/org/elasticsoftware/akces/annotations/UpcastingHandler.java | New annotation to mark upcasting handler methods. |
| main/runtime/src/main/java/org/elasticsoftware/akces/beans/AggregateBeanFactoryPostProcessor.java | Added logic to detect and process upcasting handlers. |
| main/api/src/main/java/org/elasticsoftware/akces/aggregate/UpcastingHandlerFunction.java | Defined functional interface for upcasting handlers. |
| main/runtime/src/main/java/org/elasticsoftware/akces/beans/{DomainEventUpcastingHandlerFunctionAdapter,AggregateStateUpcastingHandlerFunctionAdapter}.java | New adapters implementing upcasting handler functions. |
| Other files | Converted various reflection-based invocations to use MethodHandles and updated SchemaType implementations to support generic types. |
Comments suppressed due to low confidence (3)
main/runtime/src/main/java/org/elasticsoftware/akces/beans/AggregateBeanFactoryPostProcessor.java:273
- [nitpick] Consider extracting the construction of dynamic bean names (e.g., using prefixes like 'duh_' for domain event upcasting) into a helper method or constants to improve clarity and maintainability.
String beanName = aggregateBeanName + "_duh_" + upcastingHandlerMethod.getName() + "_" + inputEventInfo.type() + "_" + inputEventInfo.version() + "_to_" + outputEventInfo.version();
main/runtime/src/main/java/org/elasticsoftware/akces/beans/CommandHandlerFunctionAdapter.java:72
- If the aggregate's method signature does not exactly match the expected signature, the call to findVirtual may throw a WrongMethodTypeException. Consider verifying the method signature or providing a more descriptive error message to aid in debugging.
adapterMethodHandle = MethodHandles.lookup().findVirtual(aggregate.getClass(), adapterMethodName, MethodType.methodType(Stream.class, commandClass, stateClass));
main/runtime/src/main/java/org/elasticsoftware/akces/beans/DomainEventUpcastingHandlerFunctionAdapter.java:87
- Using MethodHandles.lookup() directly may result in IllegalAccessException if the target method is not public. Consider ensuring the method’s accessibility or using MethodHandles.privateLookupIn to avoid access issues.
methodHandle = MethodHandles.lookup().findVirtual(aggregate.getClass(), adapterMethodName, MethodType.methodType(outputEventClass, inputEventClass));
There was a problem hiding this comment.
Pull Request Overview
This PR introduces upcasting functionality for both DomainEvent and AggregateState classes to support schema evolution within aggregates. Key changes include:
- New interfaces and annotations (ProtocolRecordType, UpcastingHandlerFunction, UpcastingHandler) to define and mark upcasting handlers.
- Integration of upcasting handler processing in the AggregateBeanFactoryPostProcessor to register corresponding bean definitions.
- Updates to runtime adapters, annotations, and test configurations to support upcasting and enhance type safety.
Reviewed Changes
Copilot reviewed 52 out of 52 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| main/api/src/main/java/org/elasticsoftware/akces/aggregate/ProtocolRecordType.java | Added a generic interface to represent protocol record types. |
| main/api/src/main/java/org/elasticsoftware/akces/aggregate/UpcastingHandlerFunction.java | Introduced functional interface for upcasting logic with default implementations. |
| main/api/src/main/java/org/elasticsoftware/akces/annotations/UpcastingHandler.java | Added annotation to mark upcasting handler methods. |
| main/runtime/src/main/java/org/elasticsoftware/akces/beans/AggregateBeanFactoryPostProcessor.java | Extended to process and register upcasting handlers with appropriate bean definitions. |
| main/query-support/src/test/java/org/elasticsoftware/akces/query/database/DatabaseModelRuntimeTests.java, main/query-support/src/test/java/org/elasticsoftware/akces/query/models/QueryModelRuntimeTests.java, main/client/src/test/java/org/elasticsoftware/akces/client/AkcesClientTests.java |
Updated test configurations with additional environment variable for schema registry compatibility. |
| main/runtime/src/main/java/org/elasticsoftware/akces/beans/AggregateStateUpcastingHandlerFunctionAdapter.java | Added adapter to support aggregate state upcasting using method handles. |
| main/api/src/main/java/org/elasticsoftware/akces/annotations/{AggregateStateInfo.java, DomainEventInfo.java, CommandInfo.java} | Updated annotations with explicit target definitions and renamed properties where needed. |
| main/api/src/main/java/org/elasticsoftware/akces/aggregate/{SchemaType.java, CommandType.java, DomainEventType.java} | Made SchemaType and event/command types generic to improve type safety. |
| main/runtime/src/main/java/org/elasticsoftware/akces/aggregate/AggregateRuntime.java | Updated getAggregateClass() signature to use generics. |
| main/runtime/src/main/java/org/elasticsoftware/akces/beans/{CommandHandlerFunctionAdapter.java, DatabaseModelEventHandlerFunctionAdapter.java} | Refactored to use method handles for dynamic method invocation. |
Comments suppressed due to low confidence (2)
main/runtime/src/main/java/org/elasticsoftware/akces/beans/CommandHandlerFunctionAdapter.java:43
- [nitpick] Consider removing the commented-out declaration of 'adapterMethod' to keep the code clean and reduce confusion.
//private Method adapterMethod;
main/runtime/src/main/java/org/elasticsoftware/akces/beans/AggregateBeanFactoryPostProcessor.java:273
- [nitpick] The bean name generation logic for upcasting handlers is duplicated for domain events and aggregate states; consider extracting this logic into a helper method for improved maintainability.
String beanName = aggregateBeanName + "_duh_" + upcastingHandlerMethod.getName() + "_" + inputEventInfo.type() + "_" + inputEventInfo.version() + "_to_" + outputEventInfo.version();
There was a problem hiding this comment.
Pull Request Overview
This PR introduces upcasting functionality for DomainEvent and AggregateState classes by adding new annotations and functional interfaces to support type conversion and schema information. Key changes include:
- Adding new annotations (UpcastingHandler, AggregateStateInfo, DomainEventInfo, CommandInfo) to enrich metadata.
- Introducing ProtocolRecordType and UpcastingHandlerFunction interfaces for upcasting logic, and adapting existing event handler adapters to use MethodHandles.
- Refactoring aggregate and command schemas to use generic types through updates to SchemaType, CommandType, and DomainEventType, along with test configuration adjustments.
Reviewed Changes
Copilot reviewed 76 out of 76 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| main/api/src/main/java/org/elasticsoftware/akces/annotations/UpcastingHandler.java | New annotation to mark upcasting handler methods. |
| main/api/src/main/java/org/elasticsoftware/akces/aggregate/ProtocolRecordType.java | New interface for protocol record type metadata. |
| main/api/src/main/java/org/elasticsoftware/akces/aggregate/UpcastingHandlerFunction.java | New functional interface for performing upcasting with default methods requiring override. |
| main/query-support/.../DatabaseModelRuntimeTests.java & AkcesClientTests.java | Test adjustments to include new schema registry compatibility settings. |
| main/api/src/main/java/org/elasticsoftware/akces/annotations/AggregateStateInfo.java, DomainEventInfo.java, CommandInfo.java | Added @target annotations to ensure proper annotation usage. |
| main/api/src/main/java/org/elasticsoftware/akces/aggregate/SchemaType.java, AggregateStateType.java, CommandType.java, DomainEventType.java | Refactored to utilize generics by extending ProtocolRecordType. |
| main/api/src/main/java/org/elasticsoftware/akces/annotations/AggregateInfo.java | Renamed 'version' to 'stateVersion' to better describe aggregate state versioning. |
| main/query-support/.../QueryModelEventHandlerFunctionAdapter.java & DatabaseModelEventHandlerFunctionAdapter.java | Updated adapter implementations to use MethodHandles instead of reflection. |
| main/api/src/main/java/org/elasticsoftware/akces/commands/CommandBusHolder.java | Added a suppression for rawtypes warning. |
| main/query-support/.../QueryModelRuntimeFactory.java, AkcesQueryModelController.java, DefaultJdbcModel.java, DatabaseModelTestConfiguration.java | Minor code cleanups and lambda refactoring for improved clarity. |
Comments suppressed due to low confidence (2)
main/api/src/main/java/org/elasticsoftware/akces/aggregate/UpcastingHandlerFunction.java:21
- [nitpick] The generic type parameters (T, R, TR, RR) are not self-explanatory; consider using more descriptive names to improve clarity and maintainability.
public interface UpcastingHandlerFunction<T , R , TR extends ProtocolRecordType<T>, RR extends ProtocolRecordType<R>> {
main/api/src/main/java/org/elasticsoftware/akces/annotations/AggregateInfo.java:35
- Renaming 'version' to 'stateVersion' enhances clarity regarding aggregate state versioning; ensure all related references are updated accordingly.
int stateVersion() default 1;
No description provided.