@Override protected void doDeleteWithLock(AnnotatedAggregate<T> aggregate) { EntityManager entityManager = entityManagerProvider.getEntityManager(); entityManager.remove(aggregate.getAggregateRoot()); if (forceFlushOnSave) { entityManager.flush(); } }
@Override protected void doSaveWithLock(AnnotatedAggregate<T> aggregate) { EntityManager entityManager = entityManagerProvider.getEntityManager(); entityManager.persist(aggregate.getAggregateRoot()); if (forceFlushOnSave) { entityManager.flush(); } }
@Test public void testCommandsAreRoutedToCorrectEntity() throws Exception { AggregateModel<Book> bookAggregateModel = AnnotatedAggregateMetaModelFactory.inspectAggregate(Book.class); EventBus mockEventBus = SimpleEventBus.builder().build(); mockEventBus.subscribe(m -> m.forEach(i -> System.out.println(i.getPayloadType().getName()))); AnnotatedAggregate<Book> bookAggregate = AnnotatedAggregate.initialize((Book) null, bookAggregateModel, mockEventBus); bookAggregate.handle(command(new CreateBookCommand("book1"))); bookAggregate.handle(command(new CreatePageCommand("book1"))); bookAggregate.handle(command(new CreateParagraphCommand("book1", 0))); bookAggregate.handle(command(new CreateParagraphCommand("book1", 0))); bookAggregate.handle(command(new UpdateParagraphCommand("book1", 0, 0, "Hello world"))); bookAggregate.handle(command(new UpdateParagraphCommand("book1", 0, 1, "Hello world2"))); assertEquals("Hello world", bookAggregate.getAggregateRoot().getPages().get(0).getParagraphs().get(0).getText()); assertEquals("Hello world2", bookAggregate.getAggregateRoot().getPages().get(0).getParagraphs().get(1).getText()); }
@Override protected void doSaveWithLock(AnnotatedAggregate<T> aggregate) { EntityManager entityManager = entityManagerProvider.getEntityManager(); entityManager.persist(aggregate.getAggregateRoot()); if (forceFlushOnSave) { entityManager.flush(); } }
@Override protected void doDeleteWithLock(AnnotatedAggregate<T> aggregate) { EntityManager entityManager = entityManagerProvider.getEntityManager(); entityManager.remove(aggregate.getAggregateRoot()); if (forceFlushOnSave) { entityManager.flush(); } }