public OperationHandlerOperation( final OperationHandler<TState, TParams, TEvent> handler, final boolean requiresState, final boolean requiresArguments, final ExpectedVersion expectedVersion) { this(handler, requiresState, requiresArguments, expectedVersion, false); }
/** * Creates an update operation, optionally requiring an existing aggregate. * * @param handler The handler to invoke with the current state to apply updates. * @param autoCreate If true, the handler will be invoked with a null state in the case where no * current aggregate exists. If false, the command will fail without the * handler being invoked if the aggregate is not already present. * @return An operation representing the supplied logic, with metadata. */ public static <TState, TParams, TEvent> Operation<TState, TParams, TEvent> updateOf( final ParameterizedUpdateHandlerAggregate<TState, TParams, TEvent> handler, final boolean autoCreate) { ExpectedVersion expectedVersion = autoCreate ? ExpectedVersion.any() : ExpectedVersion.anyExisting(); return new OperationHandlerOperation<>( handler, true, true, expectedVersion, true); }
/** * Creates an update operation, optionally requiring an existing aggregate. * * @param handler The handler to invoke with the current state to apply updates. * @param autoCreate If true, the handler will be invoked with a null state in the case where no * current aggregate exists. If false, the command will fail without the * handler being invoked if the aggregate is not already present. * @return An operation representing the supplied logic, with metadata. */ public static <TState, TEvent> Operation<TState, Object, TEvent> updateOf( final UpdateHandler<TState, TEvent> handler, final boolean autoCreate) { ExpectedVersion expectedVersion = autoCreate ? ExpectedVersion.any() : ExpectedVersion.anyExisting(); return new OperationHandlerOperation<>( handler, true, false, expectedVersion, true); }
public OperationHandlerOperation( final OperationHandler<TState, TParams, TEvent> handler, final boolean requiresState, final boolean requiresArguments, final ExpectedVersion expectedVersion) { this(handler, requiresState, requiresArguments, expectedVersion, false); }
/** * Creates an update operation, optionally requiring an existing aggregate. * * @param handler The handler to invoke with the current state to apply updates. * @param autoCreate If true, the handler will be invoked with a null state in the case where no * current aggregate exists. If false, the command will fail without the * handler being invoked if the aggregate is not already present. * @return An operation representing the supplied logic, with metadata. */ public static <TState, TParams, TEvent> Operation<TState, TParams, TEvent> updateOf( final ParameterizedPojoUpdateHandler<TState, TParams, TEvent> handler, final boolean autoCreate) { ExpectedVersion expectedVersion = autoCreate ? ExpectedVersion.any() : ExpectedVersion.anyExisting(); return new OperationHandlerOperation<>( handler, true, true, expectedVersion, true); }
private int getStreamVersionInternal(final String streamName) { StreamEventsSlice streamEventsSlice = completeReadFuture( eventStore.readStreamEventsBackward( streamName, -1, 1, false), ExpectedVersion.any()); return streamEventsSlice.lastEventNumber; }
/** * Creates an update operation, optionally requiring an existing aggregate. * * @param handler The handler to invoke with the current state to apply updates. * @param autoCreate If true, the handler will be invoked with a null state in the case where no * current aggregate exists. If false, the command will fail without the * handler being invoked if the aggregate is not already present. * @return An operation representing the supplied logic, with metadata. */ public static <TState, TParams, TEvent> Operation<TState, TParams, TEvent> updateOf( final ParameterizedUpdateHandler<TState, TParams, TEvent> handler, final boolean autoCreate) { ExpectedVersion expectedVersion = autoCreate ? ExpectedVersion.any() : ExpectedVersion.anyExisting(); return new OperationHandlerOperation<>( handler, true, true, expectedVersion, true); }
/** * Creates an update operation, optionally requiring an existing aggregate. * * @param handler The handler to invoke with the current state to apply updates. * @param autoCreate If true, the handler will be invoked with a null state in the case where no * current aggregate exists. If false, the command will fail without the * handler being invoked if the aggregate is not already present. * @return An operation representing the supplied logic, with metadata. */ public static <TState, TEvent> Operation<TState, Object, TEvent> updateOf( final PojoUpdateHandler<TState, TEvent> handler, final boolean autoCreate) { ExpectedVersion expectedVersion = autoCreate ? ExpectedVersion.any() : ExpectedVersion.anyExisting(); return new OperationHandlerOperation<>( handler, true, false, expectedVersion, true); }
/** * Creates an update operation, optionally requiring an existing aggregate. * * @param handler The handler to invoke with the current state to apply updates. * @param autoCreate If true, the handler will be invoked with a null state in the case where no * current aggregate exists. If false, the command will fail without the * handler being invoked if the aggregate is not already present. * @return An operation representing the supplied logic, with metadata. */ public static <TState, TParams, TEvent> Operation<TState, TParams, TEvent> updateOf( final ParameterizedUpdateHandlerSingle<TState, TParams, TEvent> handler, final boolean autoCreate) { ExpectedVersion expectedVersion = autoCreate ? ExpectedVersion.any() : ExpectedVersion.anyExisting(); return new OperationHandlerOperation<>( handler, true, true, expectedVersion, true); }
private void append(final TestEventType type) { EventData<TestEventType> events = eventData(type); repository.append(streamId, Collections.singletonList(events), ExpectedVersion.any()); }
@Test public void mergeAnyAndAnyExisting() { assertMerge(any(), anyExisting(), anyExisting()); }
private void append(final TestEventType type) { EventData<TestEventType> events = eventData(type); repository.append(streamId, Collections.singletonList(events), ExpectedVersion.any()); }
@Test public void updatePassesOnEventsToEventRepository() { List<TestEvent> events = Arrays.asList(new TestEvent("test1"), new TestEvent("test2")); when(eventRepository.append(any(), anyList(), any())).thenReturn(42); repository.append(AGGREGATE_ID_1, events, ExpectedVersion.any()); ArgumentCaptor<List<EventData<TestEvent>>> passedEvents = ArgumentCaptor.forClass((Class) List.class); verify(eventRepository).append(eq(AGGREGATE_ID_1), passedEvents.capture(), any()); Assert.assertThat( passedEvents .getValue() .stream() .map(EventData::getEvent) .collect(Collectors.toList()), org.hamcrest.Matchers.contains(events.toArray())); }
public static ExpectedVersion merge( final ExpectedVersion baseVersion, final ExpectedVersion newVersion) { if (baseVersion != null && newVersion != null) { if (baseVersion.getType().compareTo(newVersion.getType()) > 0) { return mergeOrdered(newVersion, baseVersion); } else { return mergeOrdered(baseVersion, newVersion); } } else if (baseVersion != null) { return baseVersion; } else if (newVersion != null) { return newVersion; } else { return ExpectedVersion.any(); } }
public static ExpectedVersion merge( final ExpectedVersion baseVersion, final ExpectedVersion newVersion) { if (baseVersion != null && newVersion != null) { if (baseVersion.getType().compareTo(newVersion.getType()) > 0) { return mergeOrdered(newVersion, baseVersion); } else { return mergeOrdered(baseVersion, newVersion); } } else if (baseVersion != null) { return baseVersion; } else if (newVersion != null) { return newVersion; } else { return ExpectedVersion.any(); } }
@Test public void mergeAnyAndNotCreated() { assertMerge(any(), notCreated(), notCreated()); }
@Test public void mergeAnyAndExactly() { assertMerge(any(), exactly(3), exactly(3)); }
@Test @SuppressWarnings("unchecked") public void aggregateReadWhenStateRequired() { Operation operation = new OperationHandlerOperation( (x, y) -> ImmutableList.of(new TestEvent("test")), true, false, ExpectedVersion.any()); DefaultCommand command = new DefaultCommand(repository, operation); when(repository.load(any())) .thenReturn(DefaultImmutableAggregate.fromExisting( mock(AggregateProjection.class), AGGREGATE_ID, 42, new TestState("test"))); command.setAggregateId(AGGREGATE_ID); command.run(); verify(repository).load(AGGREGATE_ID); }