eventuate-client-java/src/main/java/io/eventuate/sync/AggregateRepository.java
/**
   * Update the specified aggregate by processing a command and saving events
   *
   * @param entityId        the id of the aggregate to update
   * @param commandProvider the provider of the command to process
   * @param updateOptions   options for updating
   * @return the updated and persisted aggregate
   */
Update the specified aggregate by processing a command and saving events
@param entityId        the id of the aggregate to update
@param commandProvider the provider of the command to process
@param updateOptions   options for updating
@return the updated and persisted aggregate
Update the specified aggregate by processing a command and saving events @param entityId the id of the aggregate to update @param commandProvider the provider of the command to process @param updateOptions options for updating @return the updated and persisted aggregate
public EntityWithIdAndVersion<T> updateWithProvidedCommand(final String entityId, final Function<T, Optional<CT>> commandProvider, Optional<UpdateOptions> updateOptions) {
    return withRetry(() -> {
      EntityWithMetadata<T> tEntityWithMetadata;
      try {
        tEntityWithMetadata = aggregateStore.find(clasz, entityId, updateOptions.map(uo -> new FindOptions().withTriggeringEvent(uo.getTriggeringEvent())));
      } catch (DuplicateTriggeringEventException dtee) {
        return aggregateStore.find(clasz, entityId, Optional.empty()).toEntityWithIdAndVersion();
      }
      EntityWithMetadata<T> entityWithMetaData = tEntityWithMetadata;
      final T aggregate = entityWithMetaData.getEntity();
      List<Event> events = commandProvider.apply(aggregate).map(aggregate::processCommand).orElse(Collections.emptyList());
      if (events.isEmpty()) {
        return entityWithMetaData.toEntityWithIdAndVersion();
      } else {
        try {
          EntityIdAndVersion entityIdAndVersion = aggregateStore.update(clasz, entityWithMetaData.getEntityIdAndVersion(), events, updateOptions);
          Aggregates.applyEventsToMutableAggregate(aggregate, events);
          return new EntityWithIdAndVersion<T>(entityIdAndVersion, aggregate);
        } catch (DuplicateTriggeringEventException dtee) {
          return new EntityWithIdAndVersion<T>(entityWithMetaData.getEntityIdAndVersion(), aggregate);
        }
      }
    });
  }
public EntityWithIdAndVersion < T > updateWithProvidedCommand ( final String entityId , final Function < T , Optional < CT > > commandProvider , Optional < UpdateOptions > updateOptions ) { return withRetry ( ( ) -> { EntityWithMetadata < T > tEntityWithMetadata ; try { tEntityWithMetadata = aggregateStore . find ( clasz , entityId , updateOptions . map ( uo -> new FindOptions ( ) . withTriggeringEvent ( uo . getTriggeringEvent ( ) ) ) ) ; } catch ( DuplicateTriggeringEventException dtee ) { return aggregateStore . find ( clasz , entityId , Optional . empty ( ) ) . toEntityWithIdAndVersion ( ) ; } EntityWithMetadata < T > entityWithMetaData = tEntityWithMetadata ; final T aggregate = entityWithMetaData . getEntity ( ) ; List < Event > events = commandProvider . apply ( aggregate ) . map ( aggregate :: processCommand ) . orElse ( Collections . emptyList ( ) ) ; if ( events . isEmpty ( ) ) { return entityWithMetaData . toEntityWithIdAndVersion ( ) ; } else { try { EntityIdAndVersion entityIdAndVersion = aggregateStore . update ( clasz , entityWithMetaData . getEntityIdAndVersion ( ) , events , updateOptions ) ; Aggregates . applyEventsToMutableAggregate ( aggregate , events ) ; return new EntityWithIdAndVersion < T > ( entityIdAndVersion , aggregate ) ; } catch ( DuplicateTriggeringEventException dtee ) { return new EntityWithIdAndVersion < T > ( entityWithMetaData . getEntityIdAndVersion ( ) , aggregate ) ; } } } ) ; }
Update the specified aggregate by processing a command and saving events
 @param entityId        the id of the aggregate to update
 @param commandProvider the provider of the command to process
 @param updateOptions   options for updating
 @return the updated and persisted aggregate
Update the specified aggregate by processing a command and saving events @param entityId the id of the aggregate to update @param commandProvider the provider of the command to process @param updateOptions options for updating @return the updated and persisted aggregate