aggregateConf.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .parameterResolverFactory(c.parameterResolverFactory()) .handlerDefinition(c.handlerDefinition(aggregateType)) .lockFactory(c.getComponent( LockFactory.class, () -> NullLockFactory.INSTANCE )) .entityManagerProvider(c.getComponent( EntityManagerProvider.class, () -> beanFactory.getBean(EntityManagerProvider.class) )) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build());
}); return GenericJpaRepository.builder(aggregateType) .aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build(); });
}); return GenericJpaRepository.builder(aggregateType) .aggregateModel(configurer.metaModel.get()) .entityManagerProvider(entityManagerProvider) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build(); });
/** * Instantiate a Builder to be able to create a {@link GenericJpaRepository} for aggregate type {@code T}. * <p> * The {@link LockFactory} is defaulted to an {@link NullLockFactory}, thus providing no additional locking, and * the {@code identifierConverter} to {@link Function#identity()}. * A goal of this Builder goal is to create an {@link AggregateModel} specifying generic {@code T} as the aggregate * type to be stored. All aggregates in this repository must be {@code instanceOf} this aggregate type. To * instantiate this AggregateModel, either an {@link AggregateModel} can be provided directly or an * {@code aggregateType} of type {@link Class} can be used. The latter will internally resolve to an AggregateModel. * Thus, either the AggregateModel <b>or</b> the {@code aggregateType} should be provided. * <p> * Additionally, the {@link EntityManagerProvider} and {@link EventBus} are <b>hard requirements</b> and as such * should be provided. * * @param <T> The type of aggregate to build the repository for * @param aggregateType The type of aggregate to build the repository for * @return a Builder to be able to create a {@link GenericJpaRepository} */ public static <T> Builder<T> builder(Class<T> aggregateType) { return new Builder<>(aggregateType); }
/** * 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() ); }
/** * Instantiate a Builder to be able to create a {@link GenericJpaRepository} for aggregate type {@code T}. * <p> * The {@link LockFactory} is defaulted to an {@link NullLockFactory}, thus providing no additional locking, and * the {@code identifierConverter} to {@link Function#identity()}. * A goal of this Builder goal is to create an {@link AggregateModel} specifying generic {@code T} as the aggregate * type to be stored. All aggregates in this repository must be {@code instanceOf} this aggregate type. To * instantiate this AggregateModel, either an {@link AggregateModel} can be provided directly or an * {@code aggregateType} of type {@link Class} can be used. The latter will internally resolve to an AggregateModel. * Thus, either the AggregateModel <b>or</b> the {@code aggregateType} should be provided. * <p> * Additionally, the {@link EntityManagerProvider} and {@link EventBus} are <b>hard requirements</b> and as such * should be provided. * * @param <T> The type of aggregate to build the repository for * @param aggregateType The type of aggregate to build the repository for * @return a Builder to be able to create a {@link GenericJpaRepository} */ public static <T> Builder<T> builder(Class<T> aggregateType) { return new Builder<>(aggregateType); }
/** * 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() ); }
@Bean("simpleRepository") public Repository<JpaAggregate> simpleRepository(EntityManagerProvider entityManagerProvider, EventBus eventBus) { return GenericJpaRepository.builder(JpaAggregate.class) .entityManagerProvider(entityManagerProvider) .eventBus(eventBus) .build(); } }