Class EventStoreRepository<ID extends org.fuin.ddd4j.core.AggregateRootId,AGGREGATE extends org.fuin.ddd4j.core.AggregateRoot<ID>>

java.lang.Object
org.fuin.ddd4j.esc.EventStoreRepository<ID,AGGREGATE>
Type Parameters:
ID - Type of the aggregate root identifier.
AGGREGATE - Type of the aggregate root.
All Implemented Interfaces:
org.fuin.ddd4j.core.Repository<ID,AGGREGATE>

public abstract class EventStoreRepository<ID extends org.fuin.ddd4j.core.AggregateRootId,AGGREGATE extends org.fuin.ddd4j.core.AggregateRoot<ID>> extends Object implements org.fuin.ddd4j.core.Repository<ID,AGGREGATE>
Event store based repository.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    EventStoreRepository(@NotNull org.fuin.esc.api.EventStore eventStore)
    Constructor with all mandatory data.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(AGGREGATE aggregate)
     
    void
    add(AGGREGATE aggregate, String metaType, Object metaData)
     
    protected boolean
    conflictsResolved(List<org.fuin.ddd4j.core.DomainEvent<?>> uncommittedChanges, List<org.fuin.ddd4j.core.DomainEvent<?>> unseenEvents)
    Checks if the uncommitted changes conflicts with unseen changes from the event store and tries to solve the problem.
    final void
    delete(ID aggregateId, int expectedVersion)
     
    protected @NotNull org.fuin.ddd4j.core.AggregateCache<AGGREGATE>
    Returns the aggregate cache.
    protected final @NotNull org.fuin.esc.api.EventStore
    Returns the underlying event store.
    protected abstract @NotNull String
    Returns the parameter name for the unique identifier.
    protected int
    Returns the number of tries that should be done to resolve a version conflict.
    int
    Returns the number of events to read in a slice.
    final AGGREGATE
    read(ID aggregateId)
     
    final AGGREGATE
    read(ID aggregateId, int version)
     
    final void
    update(AGGREGATE aggregate)
     
    final void
    update(AGGREGATE aggregate, String metaType, Object metaData)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.fuin.ddd4j.core.Repository

    create, getAggregateClass, getAggregateType
  • Constructor Details

    • EventStoreRepository

      protected EventStoreRepository(@NotNull @NotNull org.fuin.esc.api.EventStore eventStore)
      Constructor with all mandatory data.
      Parameters:
      eventStore - Event store.
  • Method Details

    • read

      public final AGGREGATE read(ID aggregateId) throws org.fuin.ddd4j.core.AggregateNotFoundException, org.fuin.ddd4j.core.AggregateDeletedException
      Specified by:
      read in interface org.fuin.ddd4j.core.Repository<ID extends org.fuin.ddd4j.core.AggregateRootId,AGGREGATE extends org.fuin.ddd4j.core.AggregateRoot<ID>>
      Throws:
      org.fuin.ddd4j.core.AggregateNotFoundException
      org.fuin.ddd4j.core.AggregateDeletedException
    • read

      public final AGGREGATE read(ID aggregateId, int version) throws org.fuin.ddd4j.core.AggregateNotFoundException, org.fuin.ddd4j.core.AggregateDeletedException, org.fuin.ddd4j.core.AggregateVersionNotFoundException
      Specified by:
      read in interface org.fuin.ddd4j.core.Repository<ID extends org.fuin.ddd4j.core.AggregateRootId,AGGREGATE extends org.fuin.ddd4j.core.AggregateRoot<ID>>
      Throws:
      org.fuin.ddd4j.core.AggregateNotFoundException
      org.fuin.ddd4j.core.AggregateDeletedException
      org.fuin.ddd4j.core.AggregateVersionNotFoundException
    • update

      public final void update(AGGREGATE aggregate) throws org.fuin.ddd4j.core.AggregateVersionConflictException, org.fuin.ddd4j.core.AggregateNotFoundException, org.fuin.ddd4j.core.AggregateDeletedException
      Specified by:
      update in interface org.fuin.ddd4j.core.Repository<ID extends org.fuin.ddd4j.core.AggregateRootId,AGGREGATE extends org.fuin.ddd4j.core.AggregateRoot<ID>>
      Throws:
      org.fuin.ddd4j.core.AggregateVersionConflictException
      org.fuin.ddd4j.core.AggregateNotFoundException
      org.fuin.ddd4j.core.AggregateDeletedException
    • update

      public final void update(AGGREGATE aggregate, String metaType, Object metaData) throws org.fuin.ddd4j.core.AggregateVersionConflictException, org.fuin.ddd4j.core.AggregateNotFoundException, org.fuin.ddd4j.core.AggregateDeletedException
      Specified by:
      update in interface org.fuin.ddd4j.core.Repository<ID extends org.fuin.ddd4j.core.AggregateRootId,AGGREGATE extends org.fuin.ddd4j.core.AggregateRoot<ID>>
      Throws:
      org.fuin.ddd4j.core.AggregateVersionConflictException
      org.fuin.ddd4j.core.AggregateNotFoundException
      org.fuin.ddd4j.core.AggregateDeletedException
    • add

      public void add(AGGREGATE aggregate) throws org.fuin.ddd4j.core.AggregateAlreadyExistsException, org.fuin.ddd4j.core.AggregateDeletedException
      Specified by:
      add in interface org.fuin.ddd4j.core.Repository<ID extends org.fuin.ddd4j.core.AggregateRootId,AGGREGATE extends org.fuin.ddd4j.core.AggregateRoot<ID>>
      Throws:
      org.fuin.ddd4j.core.AggregateAlreadyExistsException
      org.fuin.ddd4j.core.AggregateDeletedException
    • add

      public void add(AGGREGATE aggregate, String metaType, Object metaData) throws org.fuin.ddd4j.core.AggregateAlreadyExistsException, org.fuin.ddd4j.core.AggregateDeletedException
      Specified by:
      add in interface org.fuin.ddd4j.core.Repository<ID extends org.fuin.ddd4j.core.AggregateRootId,AGGREGATE extends org.fuin.ddd4j.core.AggregateRoot<ID>>
      Throws:
      org.fuin.ddd4j.core.AggregateAlreadyExistsException
      org.fuin.ddd4j.core.AggregateDeletedException
    • delete

      public final void delete(ID aggregateId, int expectedVersion) throws org.fuin.ddd4j.core.AggregateVersionConflictException
      Specified by:
      delete in interface org.fuin.ddd4j.core.Repository<ID extends org.fuin.ddd4j.core.AggregateRootId,AGGREGATE extends org.fuin.ddd4j.core.AggregateRoot<ID>>
      Throws:
      org.fuin.ddd4j.core.AggregateVersionConflictException
    • conflictsResolved

      protected boolean conflictsResolved(List<org.fuin.ddd4j.core.DomainEvent<?>> uncommittedChanges, List<org.fuin.ddd4j.core.DomainEvent<?>> unseenEvents)
      Checks if the uncommitted changes conflicts with unseen changes from the event store and tries to solve the problem. This method may be overwritten by concrete implementation. Returns FALSE as default if not overwritten in subclasses.
      Parameters:
      uncommittedChanges - Uncommitted changes.
      unseenEvents - Unseen changes from the event store.
      Returns:
      TRUE if there are no conflicting changes, else FALSE (conflict couldn't be resolved).
    • getMaxTryCount

      protected int getMaxTryCount()
      Returns the number of tries that should be done to resolve a version conflict. This method may be overwritten by concrete implementation. Returns 3 as default if not overwritten in subclasses.
      Returns:
      Number of tries.
    • getAggregateCache

      @NotNull protected @NotNull org.fuin.ddd4j.core.AggregateCache<AGGREGATE> getAggregateCache()
      Returns the aggregate cache. This method may be overwritten by concrete implementation. Returns no cache as default if not overwritten in subclasses.
      Returns:
      Cache.
    • getReadPageSize

      public int getReadPageSize()
      Returns the number of events to read in a slice. This method may be overwritten by concrete implementation. Returns 100 as default if not overwritten in subclasses.
      Returns:
      Page size.
    • getEventStore

      @NotNull protected final @NotNull org.fuin.esc.api.EventStore getEventStore()
      Returns the underlying event store.
      Returns:
      Event store implementation.
    • getIdParamName

      @NotNull protected abstract @NotNull String getIdParamName()
      Returns the parameter name for the unique identifier.
      Returns:
      Name to be used as parameter.