|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.axonframework.eventstore.jpa.JpaEventStore
public class JpaEventStore
An EventStore implementation that uses JPA to store DomainEvents in a database. The actual DomainEvent is stored as a serialized blob of bytes. Other columns are used to store meta-data that allow quick finding of DomainEvents for a specific aggregate in the correct order.
This EventStore supports snapshots pruning, which can enabled by configuring amaximum number of snapshots to archive
. By default snapshot pruning is configured to archive only snapshot per aggregate.
The serializer used to serialize the events is configurable. By default, the XStreamSerializer
is used.
Constructor Summary | |
---|---|
JpaEventStore(EntityManagerProvider entityManagerProvider)
Initialize a JpaEventStore using an XStreamSerializer , which
serializes events as XML and the default Event Entry store. |
|
JpaEventStore(EntityManagerProvider entityManagerProvider,
EventEntryStore eventEntryStore)
Initialize a JpaEventStore using the given eventEntryStore and an XStreamSerializer , which serializes events as XML. |
|
JpaEventStore(EntityManagerProvider entityManagerProvider,
Serializer serializer)
Initialize a JpaEventStore which serializes events using the given eventSerializer and stores the
events in the database using the default EventEntryStore. |
|
JpaEventStore(EntityManagerProvider entityManagerProvider,
Serializer serializer,
EventEntryStore eventEntryStore)
Initialize a JpaEventStore which serializes events using the given eventSerializer and stores the
events in the database using the given eventEntryStore . |
Method Summary | |
---|---|
void |
appendEvents(String type,
DomainEventStream events)
Append the events in the given stream to the event store. |
void |
appendSnapshotEvent(String type,
DomainEventMessage snapshotEvent)
Append the given snapshotEvent to the snapshot event log for the given type type . |
CriteriaBuilder |
newCriteriaBuilder()
Returns a CriteriaBuilder that allows the construction of criteria for this EventStore implementation |
DomainEventStream |
readEvents(String type,
Object identifier)
Read the events of the aggregate identified by the given type and identifier that allow the current aggregate state to be rebuilt. |
DomainEventStream |
readEvents(String type,
Object identifier,
long firstSequenceNumber)
Returns a Stream containing events for the aggregate identified by the given type and identifier , starting at the event with the given firstSequenceNumber (included). |
DomainEventStream |
readEvents(String type,
Object identifier,
long firstSequenceNumber,
long lastSequenceNumber)
Returns a Stream containing events for the aggregate identified by the given type and identifier , starting at the event with the given firstSequenceNumber (included) up to and including the
event with given lastSequenceNumber . |
void |
setBatchSize(int batchSize)
Sets the number of events that should be read at each database access. |
void |
setDataSource(DataSource dataSource)
Registers the data source that allows the EventStore to detect the database type and define the error codes that represent concurrent access failures. |
void |
setMaxSnapshotsArchived(int maxSnapshotsArchived)
Sets the maximum number of snapshots to archive for an aggregate. |
void |
setPersistenceExceptionResolver(PersistenceExceptionResolver persistenceExceptionResolver)
Sets the persistenceExceptionResolver that will help detect concurrency exceptions from the backing database. |
void |
setUpcasterChain(UpcasterChain upcasterChain)
Sets the UpcasterChain which allow older revisions of serialized objects to be deserialized. |
void |
visitEvents(Criteria criteria,
EventVisitor visitor)
Loads all events available in the event store that match the given criteria and calls EventVisitor.doWithEvent(org.axonframework.domain.DomainEventMessage) for each event found. |
void |
visitEvents(EventVisitor visitor)
Loads all events available in the event store and calls EventVisitor.doWithEvent(org.axonframework.domain.DomainEventMessage)
for each event found. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JpaEventStore(EntityManagerProvider entityManagerProvider)
XStreamSerializer
, which
serializes events as XML and the default Event Entry store.
The JPA Persistence context is required to contain two entities: DomainEventEntry
and SnapshotEventEntry
.
entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this EventStorepublic JpaEventStore(EntityManagerProvider entityManagerProvider, EventEntryStore eventEntryStore)
eventEntryStore
and an XStreamSerializer
, which serializes events as XML.
entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this EventStoreeventEntryStore
- The instance providing persistence logic for Domain Event entriespublic JpaEventStore(EntityManagerProvider entityManagerProvider, Serializer serializer)
eventSerializer
and stores the
events in the database using the default EventEntryStore.
Note: the SerializedType of Message Meta Data is not stored in the DefaultEventEntryStore. Upon retrieval,
it is set to the default value (name = "org.axonframework.domain.MetaData", revision = null). See SerializedMetaData.isSerializedMetaData(org.axonframework.serializer.SerializedObject)
entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this EventStoreserializer
- The serializer to (de)serialize domain events with.public JpaEventStore(EntityManagerProvider entityManagerProvider, Serializer serializer, EventEntryStore eventEntryStore)
eventSerializer
and stores the
events in the database using the given eventEntryStore
.
entityManagerProvider
- The EntityManagerProvider providing the EntityManager instance for this EventStoreserializer
- The serializer to (de)serialize domain events with.eventEntryStore
- The instance providing persistence logic for Domain Event entriesMethod Detail |
---|
public void appendEvents(String type, DomainEventStream events)
stream
to the event store.
appendEvents
in interface EventStore
type
- The type descriptor of the object to storeevents
- The event stream containing the events to storepublic DomainEventStream readEvents(String type, Object identifier)
readEvents
in interface EventStore
type
- The type descriptor of the object to retrieveidentifier
- The unique aggregate identifier of the events to load
public DomainEventStream readEvents(String type, Object identifier, long firstSequenceNumber)
PartialStreamSupport
type
and identifier
, starting at the event with the given firstSequenceNumber
(included).
The returned stream will not contain any snapshot events.
readEvents
in interface PartialStreamSupport
type
- The type identifier of the aggregateidentifier
- The identifier of the aggregatefirstSequenceNumber
- The sequence number of the first event to find
public DomainEventStream readEvents(String type, Object identifier, long firstSequenceNumber, long lastSequenceNumber)
PartialStreamSupport
type
and identifier
, starting at the event with the given firstSequenceNumber
(included) up to and including the
event with given lastSequenceNumber
.
If no event with given lastSequenceNumber
exists, the returned stream will simply read until the end of
the aggregate's events.
The returned stream will not contain any snapshot events.
readEvents
in interface PartialStreamSupport
type
- The type identifier of the aggregateidentifier
- The identifier of the aggregatefirstSequenceNumber
- The sequence number of the first event to findlastSequenceNumber
- The sequence number of the last event in the stream
public void appendSnapshotEvent(String type, DomainEventMessage snapshotEvent)
snapshotEvent
to the snapshot event log for the given type type
. The
sequence number of the snapshotEvent
must be equal to the sequence number of the last regular
domain
event that is included in the snapshot.
Implementations may choose to prune snapshots upon appending a new snapshot, in order to minimize storage space.
Upon appending a snapshot, this particular EventStore implementation also prunes snapshots which are considered
redundant because they fall outside of the range of maximum snapshots to archive.
appendSnapshotEvent
in interface SnapshotEventStore
type
- The type of aggregate the event belongs tosnapshotEvent
- The event summarizing one or more domain events for a specific aggregate.public void visitEvents(EventVisitor visitor)
EventStoreManagement
EventVisitor.doWithEvent(org.axonframework.domain.DomainEventMessage)
for each event found. Events of a single aggregate are guaranteed to be ordered by their sequence number.
Implementations are encouraged, though not required, to supply events in the absolute chronological order.
Processing stops when the visitor throws an exception.
visitEvents
in interface EventStoreManagement
visitor
- The visitor the receives each loaded eventpublic void visitEvents(Criteria criteria, EventVisitor visitor)
EventStoreManagement
criteria
and calls EventVisitor.doWithEvent(org.axonframework.domain.DomainEventMessage)
for each event found. Events of a single
aggregate are guaranteed to be ordered by their sequence number.
Implementations are encouraged, though not required, to supply events in the absolute chronological order.
Processing stops when the visitor throws an exception.
visitEvents
in interface EventStoreManagement
criteria
- The criteria describing the events to selectvisitor
- The visitor the receives each loaded eventEventStoreManagement.newCriteriaBuilder()
public CriteriaBuilder newCriteriaBuilder()
EventStoreManagement
newCriteriaBuilder
in interface EventStoreManagement
EventStoreManagement.visitEvents(Criteria, org.axonframework.eventstore.EventVisitor)
public void setDataSource(DataSource dataSource) throws SQLException
setPersistenceExceptionResolver(PersistenceExceptionResolver)
,
but rather as a shorthand alternative for most common database types.
dataSource
- A data source providing access to the backing database
SQLException
- If an error occurs while accessing the dataSourcepublic void setPersistenceExceptionResolver(PersistenceExceptionResolver persistenceExceptionResolver)
persistenceExceptionResolver
- the persistenceExceptionResolver that will help detect concurrency
exceptionspublic void setBatchSize(int batchSize)
batchSize
- the number of events to read on each database access. Default to 100.public void setUpcasterChain(UpcasterChain upcasterChain)
UpcasterAware
setUpcasterChain
in interface UpcasterAware
upcasterChain
- the upcaster chain providing the upcasting capabilitiespublic void setMaxSnapshotsArchived(int maxSnapshotsArchived)
maxSnapshotsArchived
- The maximum number of snapshots to archive for an aggregate. A value less than 1
disables pruning of snapshots.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |