Class AggregateConfigurer<A>
- Type Parameters:
A- the type of Aggregate configured
- All Implemented Interfaces:
AggregateConfiguration<A>,ModuleConfiguration
- Since:
- 3.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAggregateConfigurer(Class<A> aggregate) Creates a default configuration as described indefaultConfiguration(Class). -
Method Summary
Modifier and TypeMethodDescriptionReturns theAggregateFactorydefined in this configuration.Returns the type of Aggregate defined in this configuration.configureAggregateFactory(Function<Configuration, AggregateFactory<A>> aggregateFactoryBuilder) Defines the factory to use to create new Aggregates instances of the type under configuration.configureCache(Function<Configuration, Cache> cache) Configures the Cache to use for the repository created for this Aggregate type.configureCommandHandler(Function<Configuration, AggregateAnnotationCommandHandler<A>> aggregateCommandHandlerBuilder) Defines the AggregateAnnotationCommandHandler instance to use.configureCommandTargetResolver(Function<Configuration, CommandTargetResolver> commandTargetResolverBuilder) Defines the CommandTargetResolver to use for the Aggregate type under configuration.configureCreationPolicyAggregateFactory(Function<Configuration, CreationPolicyAggregateFactory<A>> creationPolicyAggregateFactoryBuilder) Defines the factory to create new aggregate instances of the type under configuration when initializing those instances from non-constructor command handlers annotated withCreationPolicy.configureEventStreamFilter(Function<Configuration, Predicate<? super DomainEventMessage<?>>> filterBuilder) Configures an event stream filter for the EventSourcingRepository for the Aggregate type under configuration.configureFilterEventsByType(Function<Configuration, Boolean> filterConfigurationPredicate) Configures a function that determines whether or not the EventSourcingRepository for the Aggregate type under configuration should filter out events with non-matching types.configureLockFactory(Function<Configuration, LockFactory> lockFactory) Defines theLockFactoryto use in theRepositoryfor the aggregate under configuration.configureRepository(Function<Configuration, Repository<A>> repositoryBuilder) Defines the repository to use to load and store Aggregates of this type.configureSnapshotFilter(Function<Configuration, SnapshotFilter> snapshotFilter) Configure aSnapshotFilterfor the Aggregate type under configuration.configureSnapshotTrigger(Function<Configuration, SnapshotTriggerDefinition> snapshotTriggerDefinition) Configures snapshotting for the Aggregate type under configuration.Configures a WeakReferenceCache to be used for the repository created for this Aggregate type.Returns theCreationPolicyAggregateFactorydefined in this configuration.static <A> AggregateConfigurer<A> defaultConfiguration(Class<A> aggregateType) Creates a default Configuration for an aggregate of the givenaggregateType.voidinitialize(Configuration config) Initialize the module configuration using the given globalconfig.static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType) Creates a Configuration for an aggregate of givenaggregateType, which is mapped to a relational database using an EntityManager obtained from the main configuration.static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) Creates a Configuration for an aggregate of givenaggregateType, which is mapped to a relational database using an EntityManager provided by givenentityManagerProvider.Returns the repository defined to load instances of the Aggregate type defined in this configuration.Returns theSnapshotFilterdefined in this configuration.final AggregateConfigurer<A> withSubtypes(Class<? extends A>... subtypes) Registers subtypes of this aggregate to support aggregate polymorphism.withSubtypes(Collection<Class<? extends A>> subtypes) Registers subtypes of this aggregate to support aggregate polymorphism.
-
Constructor Details
-
AggregateConfigurer
Creates a default configuration as described indefaultConfiguration(Class). This constructor is available for subclasses that provide additional configuration possibilities.- Parameters:
aggregate- The type of aggregate to configure
-
-
Method Details
-
defaultConfiguration
Creates a default Configuration for an aggregate of the givenaggregateType. This required either a Repository to be configured usingconfigureRepository(Function), or that the Global Configuration contains an Event Store and the Aggregate support Event Sourcing.- Type Parameters:
A- The type of Aggregate to configure- Parameters:
aggregateType- The type of Aggregate to configure- Returns:
- An AggregateConfigurer instance for further configuration of the Aggregate
-
jpaMappedConfiguration
Creates a Configuration for an aggregate of givenaggregateType, which is mapped to a relational database using an EntityManager obtained from the main configuration. The givenaggregateTypeis expected to be a proper JPA Entity.The EntityManagerProvider is expected to have been registered with the Configurer (which would be the case when using
DefaultConfigurer.jpaConfiguration(EntityManagerProvider). If that is not the case, consider usingjpaMappedConfiguration(Class, EntityManagerProvider)instead.- Type Parameters:
A- The type of Aggregate to configure- Parameters:
aggregateType- The type of Aggregate to configure- Returns:
- An AggregateConfigurer instance for further configuration of the Aggregate
-
jpaMappedConfiguration
public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) Creates a Configuration for an aggregate of givenaggregateType, which is mapped to a relational database using an EntityManager provided by givenentityManagerProvider. The givenaggregateTypeis expected to be a proper JPA Entity.- Type Parameters:
A- The type of Aggregate to configure- Parameters:
aggregateType- The type of Aggregate to configureentityManagerProvider- The provider for Axon to retrieve the EntityManager from- Returns:
- An AggregateConfigurer instance for further configuration of the Aggregate
-
configureRepository
public AggregateConfigurer<A> configureRepository(Function<Configuration, Repository<A>> repositoryBuilder) Defines the repository to use to load and store Aggregates of this type. The builder function receives the global configuration object from which it can retrieve components the repository depends on.- Parameters:
repositoryBuilder- The builder function for the repository- Returns:
- this configurer instance for chaining
-
configureAggregateFactory
public AggregateConfigurer<A> configureAggregateFactory(Function<Configuration, AggregateFactory<A>> aggregateFactoryBuilder) Defines the factory to use to create new Aggregates instances of the type under configuration.- Parameters:
aggregateFactoryBuilder- The builder function for the AggregateFactory- Returns:
- this configurer instance for chaining
-
configureCreationPolicyAggregateFactory
public AggregateConfigurer<A> configureCreationPolicyAggregateFactory(Function<Configuration, CreationPolicyAggregateFactory<A>> creationPolicyAggregateFactoryBuilder) Defines the factory to create new aggregate instances of the type under configuration when initializing those instances from non-constructor command handlers annotated withCreationPolicy.When
subtypesare provided, the givenCreationPolicyAggregateFactoryis used for every implementation of the aggregate under construction.- Parameters:
creationPolicyAggregateFactoryBuilder- The builder function for theCreationPolicyAggregateFactory.- Returns:
- This configurer instance for chaining.
-
configureLockFactory
Defines theLockFactoryto use in theRepositoryfor the aggregate under configuration. Defaults to thePessimisticLockFactoryfor theEventSourcingRepositoryandNullLockFactoryfor aGenericJpaRepository.- Parameters:
lockFactory- aFunctionbuilding theLockFactoryto use based on theConfiguration- Returns:
- this configurer instance for chaining
-
configureCommandHandler
public AggregateConfigurer<A> configureCommandHandler(Function<Configuration, AggregateAnnotationCommandHandler<A>> aggregateCommandHandlerBuilder) Defines the AggregateAnnotationCommandHandler instance to use.- Parameters:
aggregateCommandHandlerBuilder- The builder function for the AggregateCommandHandler- Returns:
- this configurer instance for chaining
-
configureCommandTargetResolver
public AggregateConfigurer<A> configureCommandTargetResolver(Function<Configuration, CommandTargetResolver> commandTargetResolverBuilder) Defines the CommandTargetResolver to use for the Aggregate type under configuration. The CommandTargetResolver defines which Aggregate instance must be loaded to handle a specific Command.- Parameters:
commandTargetResolverBuilder- the builder function for the CommandTargetResolver.- Returns:
- this configurer instance for chaining
-
configureSnapshotTrigger
public AggregateConfigurer<A> configureSnapshotTrigger(Function<Configuration, SnapshotTriggerDefinition> snapshotTriggerDefinition) Configures snapshotting for the Aggregate type under configuration.Note that this configuration is ignored if a custom repository instance is configured.
- Parameters:
snapshotTriggerDefinition- The function creating the SnapshotTriggerDefinition- Returns:
- this configurer instance for chaining
-
configureSnapshotFilter
public AggregateConfigurer<A> configureSnapshotFilter(Function<Configuration, SnapshotFilter> snapshotFilter) Configure aSnapshotFilterfor the Aggregate type under configuration. Note thatSnapshotFilterinstances will be combined and should returntrueif they handle a snapshot they wish to ignore.- Parameters:
snapshotFilter- the function creating theSnapshotFilter- Returns:
- this configurer instance for chaining
-
configureEventStreamFilter
public AggregateConfigurer<A> configureEventStreamFilter(Function<Configuration, Predicate<? super DomainEventMessage<?>>> filterBuilder) Configures an event stream filter for the EventSourcingRepository for the Aggregate type under configuration. By default, no filter is applied to the event stream.Note that this configuration is ignored if a custom repository instance is configured.
- Parameters:
filterBuilder- The function creating the filter.- Returns:
- this configurer instance for chaining
- See Also:
-
configureCache
Configures the Cache to use for the repository created for this Aggregate type. Note that this setting is ignored when explicitly configuring a Repository usingconfigureRepository(Function).- Parameters:
cache- the function that defines the Cache to use- Returns:
- this configurer instance for chaining
-
configureWeakReferenceCache
Configures a WeakReferenceCache to be used for the repository created for this Aggregate type. Note that this setting is ignored when explicitly configuring a Repository usingconfigureRepository(Function).- Returns:
- this configurer instance for chaining
-
configureFilterEventsByType
public AggregateConfigurer<A> configureFilterEventsByType(Function<Configuration, Boolean> filterConfigurationPredicate) Configures a function that determines whether or not the EventSourcingRepository for the Aggregate type under configuration should filter out events with non-matching types. This may be used to support installations where multiple Aggregate types share overlapping Aggregate IDs.Note that this configuration is ignored if a custom repository instance is configured, and that
configureEventStreamFilter(Function)overrides this.- Parameters:
filterConfigurationPredicate- The function determining whether or not to filter events by Aggregate type.- Returns:
- this configurer instance for chaining
- See Also:
-
initialize
Description copied from interface:ModuleConfigurationInitialize the module configuration using the given globalconfig. Any specific start up or shut down processes should be added here by using the providedconfigand invokeLifecycleOperations.onStart(int, LifecycleHandler)andLifecycleOperations.onShutdown(int, LifecycleHandler)respectively.- Specified by:
initializein interfaceModuleConfiguration- Parameters:
config- the global configuration, providing access to generic components
-
repository
Description copied from interface:AggregateConfigurationReturns the repository defined to load instances of the Aggregate type defined in this configuration.- Specified by:
repositoryin interfaceAggregateConfiguration<A>- Returns:
- the repository to load aggregates
-
aggregateType
Description copied from interface:AggregateConfigurationReturns the type of Aggregate defined in this configuration.- Specified by:
aggregateTypein interfaceAggregateConfiguration<A>- Returns:
- the type of Aggregate defined in this configuration
-
aggregateFactory
Description copied from interface:AggregateConfigurationReturns theAggregateFactorydefined in this configuration.- Specified by:
aggregateFactoryin interfaceAggregateConfiguration<A>- Returns:
- the
AggregateFactorydefined in this configuration.
-
snapshotFilter
Description copied from interface:AggregateConfigurationReturns theSnapshotFilterdefined in this configuration.- Specified by:
snapshotFilterin interfaceAggregateConfiguration<A>- Returns:
- the
SnapshotFilterdefined in this configuration
-
withSubtypes
Registers subtypes of this aggregate to support aggregate polymorphism. Command Handlers defined on this subtypes will be considered part of this aggregate's handlers.- Parameters:
subtypes- subtypes in this polymorphic hierarchy- Returns:
- this configurer for fluent interfacing
-
withSubtypes
Registers subtypes of this aggregate to support aggregate polymorphism. Command Handlers defined on this subtypes will be considered part of this aggregate's handlers.- Parameters:
subtypes- subtypes in this polymorphic hierarchy- Returns:
- this configurer for fluent interfacing
-
creationPolicyAggregateFactory
Returns theCreationPolicyAggregateFactorydefined in this configuration.- Returns:
- the
CreationPolicyAggregateFactorydefined in this configuration.
-