Class EventStore
java.lang.Object
com.reallifedeveloper.common.application.eventstore.EventStore
- Author:
- RealLifeDeveloper
-
Constructor Summary
ConstructorsConstructorDescriptionEventStore(ObjectSerializer<String> serializer, StoredEventRepository repository) Creates a newEventStorewith the given serializer and repository. -
Method Summary
Modifier and TypeMethodDescriptionadd(DomainEvent event) Adds a newStoredEventrepresenting the givenDomainEventto the event store.allEventsBetween(long firstStoredEventId, long lastStoredEventId) Gives allStoredEventswith IDs greater than or equal tofirstStoredEventIdand less than or equals tolastStoredEventId, i.e., all events that occurred between the events with the given IDs, inclusive.allEventsSince(long storedEventId) Gives allStoredEventswith IDs greater thanstoredEventId, i.e., all events that occurred after the event with the given ID.longGives the ID of the most recently addedStoredEvents.<T extends DomainEvent>
TtoDomainEvent(StoredEvent storedEvent) Converts aStoredEventback to its originalDomainEvent.
-
Constructor Details
-
EventStore
Creates a newEventStorewith the given serializer and repository.- Parameters:
serializer- theDomainEventSerializerto use to serialize and deserializeDomainEventsrepository- theStoredEventRepositoryto use to work with persistedStoredEvents
-
-
Method Details
-
add
Adds a newStoredEventrepresenting the givenDomainEventto the event store.- Parameters:
event- theDomainEventto add- Returns:
- the saved
StoredEventrepresentingevent
-
allEventsSince
Gives allStoredEventswith IDs greater thanstoredEventId, i.e., all events that occurred after the event with the given ID.- Parameters:
storedEventId- return all events with IDs greater than this- Returns:
- a list of
StoredEventswith IDs greater than or equal tofirstStoredEventId
-
allEventsBetween
Gives allStoredEventswith IDs greater than or equal tofirstStoredEventIdand less than or equals tolastStoredEventId, i.e., all events that occurred between the events with the given IDs, inclusive.- Parameters:
firstStoredEventId- ID of the firstStoredEventto retrievelastStoredEventId- ID of the lastStoredEventto retrieve- Returns:
- a list of all
StoredEventswith IDs betweenfirstStoredEventIdandlastStoredEventId, inclusive
-
toDomainEvent
Converts aStoredEventback to its originalDomainEvent.This is only guaranteed to work if the same kind of
EventStore, using the same type ofDomainEventSerializer, was used to add theDomainEvent.- Type Parameters:
T- the type ofDomainEventto return- Parameters:
storedEvent- theStoredEventto convert- Returns:
- the original
DomainEventrepresented bystoredEvent - Throws:
IllegalArgumentException- ifstoredEventisnullIllegalStateException- if loading of the classTfailed
-
lastStoredEventId
public long lastStoredEventId()Gives the ID of the most recently addedStoredEvents.- Returns:
- the ID of the most recently added
StoredEvent
-