本文整理汇总了Java中org.axonframework.eventsourcing.EventSourcingRepository类的典型用法代码示例。如果您正苦于以下问题:Java EventSourcingRepository类的具体用法?Java EventSourcingRepository怎么用?Java EventSourcingRepository使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventSourcingRepository类属于org.axonframework.eventsourcing包,在下文中一共展示了EventSourcingRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("sampleContext.xml");
commandGateway = applicationContext.getBean(CommandGateway.class);
repository = (EventSourcingRepository<ToDoItem>) applicationContext.getBean("toDoRepository");
try {
ToDoItemDemoRunner runner = new ToDoItemDemoRunner();
runner.run();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
TimeUnit.SECONDS.sleep(1l);
System.exit(0);
}
}
示例2: registerAggregateFactories
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> void registerAggregateFactories(
final RegistrableAggregateSnaphotter snapshotter) {
Set<Annotation> qualifiers = ImmutableSet.copyOf(getQualifiers());
for (AggregateRootInfo aggregateRoot : aggregateRootsInfo) {
if (aggregateRoot.matchQualifiers(QualifierType.SNAPSHOTTER, qualifiers)) {
Set<Annotation> factoryQualifiers = aggregateRoot
.getQualifiers(QualifierType.REPOSITORY);
Type type = TypeUtils.parameterize(EventSourcingRepository.class,
aggregateRoot.getType());
EventSourcingRepository<T> repository = (EventSourcingRepository<T>) CdiUtils
.getReference(getBeanManager(), type, factoryQualifiers);
if (repository != null) {
snapshotter.registerAggregateFactory(repository.getAggregateFactory());
}
new EventCountSnapshotTriggerDefinition(snapshotter, 10);
}
}
}
示例3: registerRepositories
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@SuppressWarnings({ "unchecked" })
protected <T> void registerRepositories(X commandBus) {
final Set<Annotation> qualifiers = ImmutableSet.copyOf(getQualifiers());
for (AggregateRootInfo aggregateRootInfo : aggregateRootsInfo) {
if (aggregateRootInfo.matchQualifiers(QualifierType.COMMAND_BUS, qualifiers)) {
Class<T> aggregateType = (Class<T>) aggregateRootInfo.getType();
ParameterizedType repositoryType = TypeUtils.parameterize(EventSourcingRepository.class,
aggregateType);
EventSourcingRepository<T> repository = (EventSourcingRepository<T>) CdiUtils.getReference(
getBeanManager(), repositoryType, aggregateRootInfo.getQualifiers(QualifierType.REPOSITORY));
AggregateAnnotationCommandHandler<?> aggregateAnnotationCommandHandler = new AggregateAnnotationCommandHandler<>(aggregateType,
repository);
aggregateAnnotationCommandHandler.subscribe(commandBus);
if (commandBus instanceof DisruptorCommandBus) {
((DisruptorCommandBus) commandBus).createRepository(repository.getAggregateFactory());
}
}
}
}
示例4: createInjector
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
private Injector createInjector() {
return Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
// Event store
CommandBus commandBus = new SimpleCommandBus();
CommandGateway commandGateway = new DefaultCommandGateway(commandBus);
EventStore eventStore = new FileSystemEventStore(new SimpleEventFileResolver(eventStoreFolder));
EventBus eventBus = new SimpleEventBus();
EventSourcingRepository repository = new EventSourcingRepository(Rating.class, eventStore);
repository.setEventBus(eventBus);
// Event store handlers
AggregateAnnotationCommandHandler.subscribe(Rating.class, repository, commandBus);
AnnotationEventListenerAdapter.subscribe(new RatingEventHandler(), eventBus);
// Load twist config
TwistProvider twistProvider = new TwistProvider(twistsDataFile);
// Twist rating
TwistRating twistRating = new TwistRatingEventStore(commandGateway, twistProvider);
// Bootstrap aggregates
twistProvider.getTwists().stream().forEach(twist -> {
commandGateway.send(new CreateTwistCommand(twist.id));
});
// Set up bindings
bind(TwistRating.class).toInstance(twistRating);
bind(TwistProvider.class).toInstance(twistProvider);
Logger.info("Injector configured");
}
});
}
示例5: orderEventSourcingRepository
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@Bean
EventSourcingRepository<OrderAggregate> orderEventSourcingRepository() {
EventSourcingRepository<OrderAggregate> repo = new EventSourcingRepository<OrderAggregate>(
OrderAggregate.class, eventStore());
repo.setEventBus(eventBus());
return repo;
}
示例6: repositoryFor
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
private <R extends EventSourcedAggregateRoot>
EventSourcingRepository<R> repositoryFor(
final Class<R> beanType) {
final EventSourcingRepository<R> repository
= new EventSourcingRepository<>(beanType, eventStore);
repository.setEventBus(eventBus);
subscribe(beanType, repository, commandBus);
return repository;
}
示例7: respository
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@Bean(name = "testAggregateEventsourcingRepository")
@Autowired
public EventSourcingRepository<MyTestAggregate> respository(final EventStore eventStore, final EventBus eventBus, final Cache cache) {
final CachingEventSourcingRepository<MyTestAggregate> repository = new CachingEventSourcingRepository<>(new GenericAggregateFactory<>(MyTestAggregate.class), eventStore);
repository.setCache(cache);
repository.setEventBus(eventBus);
return repository;
}
示例8: respository
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@Bean(name = "testAggregateEventsourcingRepository")
@Autowired
public EventSourcingRepository<MyTestAggregate> respository(final EventStore eventStore, final EventBus eventBus) {
final EventSourcingRepository<MyTestAggregate> repository = new EventSourcingRepository<>(MyTestAggregate.class, eventStore);
repository.setEventBus(eventBus);
return repository;
}
示例9: productAggregateCommandHandler
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
/**
* This method registers your Aggregate Root as a @CommandHandler
*
* @return
*/
@Bean
AggregateAnnotationCommandHandler<ProductAggregate> productAggregateCommandHandler(EventSourcingRepository<ProductAggregate> eventSourcingRepository, CommandBus commandBus) {
AggregateAnnotationCommandHandler<ProductAggregate> handler = new AggregateAnnotationCommandHandler<ProductAggregate>(
ProductAggregate.class,
eventSourcingRepository,
commandBus);
return handler;
}
示例10: libraryRepository
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@Bean
public EventSourcingRepository<Library> libraryRepository() {
DefaultMongoTemplate template = new DefaultMongoTemplate(axonconf.mongo);
MongoEventStore eventStore = new MongoEventStore(template
);
EventSourcingRepository<Library> repository = new EventSourcingRepository<Library>(
Library.class, eventStore);
repository.setEventBus(axonconf.eventBus());
return repository;
}
示例11: loadAggregate
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
private static void loadAggregate(EventSourcingRepository repository, String toDoItemId) {
System.out.println("\n------------------- LOADING AGGREGATE -----------------------");
System.out.println("Loading 'ToDoItem' with Id: " + toDoItemId);
System.out.println("Events being re-applied...");
UnitOfWork unitOfWork = new DefaultUnitOfWorkFactory().createUnitOfWork();
ToDoItem item = (ToDoItem) repository.load(toDoItemId);
unitOfWork.commit();
System.out.println("Loaded...");
System.out.println(
"ToDoItem (" + item.getId() + ") " + "'" + item.getDescription() + "' " + "Complete?: "
+ item.isComplete());
System.out.println("---------------------- AGGREGATE LOADED -----------------------\n");
}
示例12: postProcessAfterInitialization
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (EventSourcedAggregateRoot.class.isAssignableFrom(bean.getClass())) {
AggregateRoot aggregateRoot = (AggregateRoot) bean;
EventSourcingRepository repository = new EventSourcingRepository(bean.getClass(), eventStore);
repository.setEventBus(eventBus);
beanFactory.registerSingleton(beanName + "Repository", repository);
AggregateAnnotationCommandHandler.subscribe(aggregateRoot.getClass(), repository, commandBus);
}
return bean;
}
示例13: autoEventSourcingRepositoryCreated
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@Test
public void autoEventSourcingRepositoryCreated(){
this.context.register(AxonAutoConfiguration.class);
this.context.register(DummyAggregateRoot.class);
this.context.refresh();
assertNotNull(this.context.getBean(EventSourcingRepository.class));
}
示例14: createRepositoryBean
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Bean<EventSourcingRepository<T>> createRepositoryBean(
final BeanManager bm, final AggregateRootInfo aggregateRootInfo) {
BeanBuilder<T> aggregateRootBean = new BeanBuilder<T>(bm)
.readFromType((AnnotatedType<T>) aggregateRootInfo.getAnnotatedType(bm));
ParameterizedType type = TypeUtils.parameterize(EventSourcingRepository.class,
aggregateRootInfo.getType());
BeanBuilder<EventSourcingRepository<T>> builder = new BeanBuilder<EventSourcingRepository<T>>(
bm)
.beanClass(EventSourcingRepository.class)
.qualifiers(CdiUtils.normalizedQualifiers(
aggregateRootInfo.getQualifiers(QualifierType.REPOSITORY)))
.alternative(aggregateRootBean.isAlternative())
.nullable(aggregateRootBean.isNullable())
.types(CdiUtils.typeClosure(type))
.scope(aggregateRootBean.getScope())
.stereotypes(aggregateRootBean.getStereotypes())
.beanLifecycle(
new RepositoryContextualLifecycle<T, EventSourcingRepository<T>>(bm,
aggregateRootInfo));
if (!Strings.isNullOrEmpty(aggregateRootBean.getName())) {
builder.name(aggregateRootBean.getName() + "Repository");
}
return builder.create();
}
示例15: create
import org.axonframework.eventsourcing.EventSourcingRepository; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public R create(final Bean<R> bean, final CreationalContext<R> creationalContext) {
R repository = (R) new EventSourcingRepository<T>(aggregateFactory(),
eventStore(),
snapshotTriggerDefinition());
return repository;
}