org.axonframework.eventstore.jdbc
Class DefaultEventEntryStore<T>

java.lang.Object
  extended by org.axonframework.eventstore.jdbc.DefaultEventEntryStore<T>
Type Parameters:
T - The type used when storing serialized data
All Implemented Interfaces:
EventEntryStore<T>

public class DefaultEventEntryStore<T>
extends Object
implements EventEntryStore<T>

Implementation of the EventEntryStore that stores events in DomainEventEntry table and snapshot events in SnapshotEventEntry table.

Since:
2.2
Author:
Allard Buijze, Kristian Rosenvold, Knut-Olav Hoven

Constructor Summary
DefaultEventEntryStore(ConnectionProvider connectionProvider)
          Initialize the EventEntryStore using a Generic SQL Schema, and given connectionProvider to obtain connections.
DefaultEventEntryStore(ConnectionProvider connectionProvider, EventSqlSchema<T> sqlSchema)
          Initialize the EventEntryStore, fetching connections from the given connectionProvider and executing SQL statements using given sqlSchema.
DefaultEventEntryStore(DataSource dataSource, EventSqlSchema<T> sqlSchema)
          Initialize the EventEntryStore, fetching connections from the given dataSource and executing SQL statements using given sqlSchema.
 
Method Summary
 void createSchema()
          Performs the DDL queries to create the schema necessary for this EventEntryStore implementation.
 Iterator<SerializedDomainEventData<T>> fetchAggregateStream(String aggregateType, Object identifier, long firstSequenceNumber, int fetchSize)
          Creates an iterator that iterates through the events for an aggregate of given type and given identifier starting at given firstSequenceNumber.
 Iterator<SerializedDomainEventData<T>> fetchFiltered(String whereClause, List<Object> parameters, int batchSize)
          Creates an iterator that iterates through the Events that conform to the given sql whereClause.
 Class<T> getDataType()
          Returns the type used to store serialized payloads.
 SerializedDomainEventData<T> loadLastSnapshotEvent(String aggregateType, Object identifier)
          Load the last known snapshot event for aggregate of given type with given identifier.
 void persistEvent(String aggregateType, DomainEventMessage event, SerializedObject<T> serializedPayload, SerializedObject<T> serializedMetaData)
          Stores the given event (serialized as serializedPayload and serializedMetaData in the Event Store.
 void persistSnapshot(String aggregateType, DomainEventMessage snapshotEvent, SerializedObject<T> serializedPayload, SerializedObject<T> serializedMetaData)
          Persists the given event which has been serialized into serializedEvent.
 void pruneSnapshots(String type, DomainEventMessage mostRecentSnapshotEvent, int maxSnapshotsArchived)
          Removes old snapshots from the storage for an aggregate of given type that generated the given mostRecentSnapshotEvent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultEventEntryStore

public DefaultEventEntryStore(DataSource dataSource,
                              EventSqlSchema<T> sqlSchema)
Initialize the EventEntryStore, fetching connections from the given dataSource and executing SQL statements using given sqlSchema.

Parameters:
dataSource - The data source used to create connections
sqlSchema - The SQL Definitions

DefaultEventEntryStore

public DefaultEventEntryStore(ConnectionProvider connectionProvider,
                              EventSqlSchema<T> sqlSchema)
Initialize the EventEntryStore, fetching connections from the given connectionProvider and executing SQL statements using given sqlSchema.

Parameters:
connectionProvider - Used to obtain connections
sqlSchema - The SQL Definitions

DefaultEventEntryStore

public DefaultEventEntryStore(ConnectionProvider connectionProvider)
Initialize the EventEntryStore using a Generic SQL Schema, and given connectionProvider to obtain connections.

Parameters:
connectionProvider - Used to obtain connections
Method Detail

loadLastSnapshotEvent

public SerializedDomainEventData<T> loadLastSnapshotEvent(String aggregateType,
                                                          Object identifier)
Description copied from interface: EventEntryStore
Load the last known snapshot event for aggregate of given type with given identifier.

Specified by:
loadLastSnapshotEvent in interface EventEntryStore<T>
Parameters:
aggregateType - The type identifier of the aggregate that generated the event
identifier - The identifier of the aggregate to load the snapshot for
Returns:
the serialized representation of the last known snapshot event

fetchFiltered

public Iterator<SerializedDomainEventData<T>> fetchFiltered(String whereClause,
                                                            List<Object> parameters,
                                                            int batchSize)
Description copied from interface: EventEntryStore
Creates an iterator that iterates through the Events that conform to the given sql whereClause. When the implementation uses batched fetching, it should use given batchSize. The given parameters provide the values for the placeholders used in the where clause.

The "WHERE" keyword must not be included in the whereClause. If the clause is null or an empty String, no filters are applied, and an iterator is returned that scans all events in the event store.

The iterator should return events in the order they were added to the event store. In either case, it must ensure that events originating from the same aggregate are always returned with the lowest sequence number first.

Specified by:
fetchFiltered in interface EventEntryStore<T>
Parameters:
whereClause - The JPA clause to be included after the WHERE keyword
parameters - A map containing all the parameter values for parameter keys included in the where clause
batchSize - The total number of events to return in this batch
Returns:
a List of serialized representations of Events included in this batch

persistSnapshot

public void persistSnapshot(String aggregateType,
                            DomainEventMessage snapshotEvent,
                            SerializedObject<T> serializedPayload,
                            SerializedObject<T> serializedMetaData)
Description copied from interface: EventEntryStore
Persists the given event which has been serialized into serializedEvent.

These snapshot events should be returned by the loadLastSnapshotEvent(...) methods.

Specified by:
persistSnapshot in interface EventEntryStore<T>
Parameters:
aggregateType - The type identifier of the aggregate that generated the event
snapshotEvent - The actual snapshot event instance. May be used to extract relevant meta data
serializedPayload - The serialized payload of the event
serializedMetaData - The serialized MetaData of the event

persistEvent

public void persistEvent(String aggregateType,
                         DomainEventMessage event,
                         SerializedObject<T> serializedPayload,
                         SerializedObject<T> serializedMetaData)
Description copied from interface: EventEntryStore
Stores the given event (serialized as serializedPayload and serializedMetaData in the Event Store.

Specified by:
persistEvent in interface EventEntryStore<T>
Parameters:
aggregateType - The type identifier of the aggregate that generated the event
event - The actual event instance. May be used to extract relevant meta data
serializedPayload - The serialized payload of the event
serializedMetaData - The serialized MetaData of the event

pruneSnapshots

public void pruneSnapshots(String type,
                           DomainEventMessage mostRecentSnapshotEvent,
                           int maxSnapshotsArchived)
Description copied from interface: EventEntryStore
Removes old snapshots from the storage for an aggregate of given type that generated the given mostRecentSnapshotEvent. A number of maxSnapshotsArchived is expected to remain in the archive after pruning, unless that number of snapshots has not been created yet.

Specified by:
pruneSnapshots in interface EventEntryStore<T>
Parameters:
type - the type of the aggregate for which to prune snapshots
mostRecentSnapshotEvent - the last appended snapshot event
maxSnapshotsArchived - the number of snapshots that may remain archived

getDataType

public Class<T> getDataType()
Description copied from interface: EventEntryStore
Returns the type used to store serialized payloads.

Specified by:
getDataType in interface EventEntryStore<T>
Returns:
the type used to store serialized payloads

fetchAggregateStream

public Iterator<SerializedDomainEventData<T>> fetchAggregateStream(String aggregateType,
                                                                   Object identifier,
                                                                   long firstSequenceNumber,
                                                                   int fetchSize)
Description copied from interface: EventEntryStore
Creates an iterator that iterates through the events for an aggregate of given type and given identifier starting at given firstSequenceNumber. When using batched fetching, the given batchSize should be used.

Note that the result is expected to be ordered by sequence number, with the lowest number first.

Specified by:
fetchAggregateStream in interface EventEntryStore<T>
Parameters:
aggregateType - The type identifier of the aggregate that generated the event
identifier - The identifier of the aggregate to load the snapshot for
firstSequenceNumber - The sequence number of the first event to include in the batch
fetchSize - The number of entries to include in the batch (if available)
Returns:
a List of serialized representations of Events included in this batch

createSchema

public void createSchema()
                  throws SQLException
Performs the DDL queries to create the schema necessary for this EventEntryStore implementation.

Throws:
SQLException - when an error occurs executing SQL statements


Copyright © 2010-2016. All Rights Reserved.