aggregate.substring(0, 1).toLowerCase() + aggregate.substring(1) + "AggregateFactory"; if (beanFactory.containsBean(repositoryName)) { aggregateConf.configureRepository(c -> beanFactory.getBean(repositoryName, Repository.class)); } else { registry.registerBeanDefinition(repositoryName, aggregateConf.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .parameterResolverFactory(c.parameterResolverFactory()) aggregateConf.configureRepository( c -> beanFactory.getBean(aggregateAnnotation.repository(), Repository.class));
return configurer.configureRepository( c -> { EntityManagerProvider entityManagerProvider = c.getComponent(
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager provided by given {@code entityManagerProvider}. The given {@code aggregateType} * is expected to be a proper JPA Entity. * * @param aggregateType The type of Aggregate to configure * @param entityManagerProvider The provider for Axon to retrieve the EntityManager from * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build() ); }
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager provided by given {@code entityManagerProvider}. The given {@code aggregateType} * is expected to be a proper JPA Entity. * * @param aggregateType The type of Aggregate to configure * @param entityManagerProvider The provider for Axon to retrieve the EntityManager from * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> new GenericJpaRepository<>(entityManagerProvider, configurer.metaModel.get(), c.eventBus(), (RepositoryProvider) c::repository)); }
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager obtained from the main configuration. The given {@code aggregateType} * is expected to be a proper JPA Entity. * <p> * The EntityManagerProvider is expected to have been registered with the Configurer (which would be the case when * using {@link DefaultConfigurer#jpaConfiguration(EntityManagerProvider)}. If that is not the case, consider using * {@link #jpaMappedConfiguration(Class, EntityManagerProvider)} instead. * * @param aggregateType The type of Aggregate to configure * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> new GenericJpaRepository<>(c.getComponent(EntityManagerProvider.class, () -> { throw new AxonConfigurationException(format( "JPA has not been correctly configured for aggregate [%s]. Either provide an EntityManagerProvider, or use DefaultConfigurer.jpaConfiguration(...) to define one for the entire configuration.", aggregateType.getSimpleName())); }), configurer.metaModel.get(), c.eventBus(), (RepositoryProvider) c::repository)); }
return configurer.configureRepository( c -> { EntityManagerProvider entityManagerProvider = c.getComponent(
/** * Creates a Configuration for an aggregate of given {@code aggregateType}, which is mapped to a relational * database using an EntityManager provided by given {@code entityManagerProvider}. The given {@code aggregateType} * is expected to be a proper JPA Entity. * * @param aggregateType The type of Aggregate to configure * @param entityManagerProvider The provider for Axon to retrieve the EntityManager from * @param <A> The type of Aggregate to configure * @return An AggregateConfigurer instance for further configuration of the Aggregate */ public static <A> AggregateConfigurer<A> jpaMappedConfiguration(Class<A> aggregateType, EntityManagerProvider entityManagerProvider) { AggregateConfigurer<A> configurer = new AggregateConfigurer<>(aggregateType); return configurer.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build() ); }