Class TableUpdater<S>

Object
akka.javasdk.view.TableUpdater<S>
Type Parameters:
S - The type of each row in the table updated by this updater.

public abstract class TableUpdater<S> extends Object
Responsible for consuming events from a source and emit updates to one view table. Event subject (entity id for entities, cloud event subject for events from a topic) maps one to one with a row in the table.

Concrete subclasses should be public static inner classes of the view they update a table for. A public no-parameter constructor must exist and is used to create instances used.

For a single table view the table name can be inferred from queries, but for a multi table view each class must be annotated with Table identifying which table they update.

Concrete class must be annotated with one of the Consume annotations.

  • Constructor Details

    • TableUpdater

      public TableUpdater()
  • Method Details

    • updateContext

      protected final UpdateContext updateContext()
      Additional context and metadata for an update handler.

      It will throw an exception if accessed from constructor.

    • rowState

      protected final S rowState()
      Returns the current state of the row for the subject that is being updated.

      Note that modifying the row object directly will not update it in storage. To save the row, one must call {effects().updateRow()}.

      This method can only be called when handling an update. Calling it outside a method (eg: in the constructor) will raise a IllegalStateException exception.

      Throws:
      IllegalStateException - if accessed outside a handler method
    • effects

      protected final TableUpdater.Effect.Builder<S> effects()
    • emptyRow

      public S emptyRow()
      The default implementation of this method returns null. It can be overridden to return a more sensible initial state.
      Returns:
      an empty row object or null to hand to the process method when an event for a previously unknown subject id is seen.