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

java.lang.Object
  extended by org.axonframework.eventstore.jpa.DefaultEventEntryStore<T>
Type Parameters:
T - The type of data used by this EventEntryStore.
All Implemented Interfaces:
EventEntryStore<T>

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

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

This implementation requires that the aforementioned instances are available in the current persistence context.

Note: the SerializedType of Message Meta Data is not stored in this EventEntryStore. Upon retrieval, it is set to the default value (name = "org.axonframework.domain.MetaData", revision = null). See SerializedMetaData.isSerializedMetaData(org.axonframework.serializer.SerializedObject)

Since:
1.2
Author:
Allard Buijze

Constructor Summary
DefaultEventEntryStore()
          Initialize the Event Entry Store, storing timestamps in the system timezone and storing serialized data as byte arrays.
DefaultEventEntryStore(boolean forceUtcTimestamp)
          Initializes the EventEntryStore, storing serialized data as byte arrays, with the possibility to force timestamps to be stored in UTC timezone.
DefaultEventEntryStore(EventEntryFactory<T> eventEntryFactory)
          Initializes the EventEntryStore, using the given eventEntryFactory to provide instances of the JPA entities to use for persistence.
 
Method Summary
protected  Object createDomainEventEntry(String aggregateType, DomainEventMessage event, SerializedObject<T> serializedPayload, SerializedObject<T> serializedMetaData)
          Allows for customization of the DomainEventEntry to store.
protected  Object createSnapshotEventEntry(String aggregateType, DomainEventMessage snapshotEvent, SerializedObject<T> serializedPayload, SerializedObject<T> serializedMetaData)
          Allows for customization of the SnapshotEventEntry to store.
protected  String domainEventEntryEntityName()
          The name of the DomainEventEntry entity to use when querying for domain events.
 Iterator<SerializedDomainEventData<T>> fetchAggregateStream(String aggregateType, Object identifier, long firstSequenceNumber, int batchSize, javax.persistence.EntityManager entityManager)
          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, Map<String,Object> parameters, int batchSize, javax.persistence.EntityManager entityManager)
          Creates an iterator that iterates through the Events that conform to the given JPA whereClause.
 Class<T> getDataType()
          Returns the type used to store serialized payloads.
 SimpleSerializedDomainEventData loadLastSnapshotEvent(String aggregateType, Object identifier, javax.persistence.EntityManager entityManager)
          Load the last known snapshot event for aggregate of given type with given identifier using given entityManager.
 void persistEvent(String aggregateType, DomainEventMessage event, SerializedObject<T> serializedPayload, SerializedObject<T> serializedMetaData, javax.persistence.EntityManager entityManager)
          Persists the given event which has been serialized into serializedEvent in the backing data store using given entityManager.
 void persistSnapshot(String aggregateType, DomainEventMessage snapshotEvent, SerializedObject<T> serializedPayload, SerializedObject<T> serializedMetaData, javax.persistence.EntityManager entityManager)
          Persists the given event which has been serialized into serializedEvent in the backing data store using given entityManager.
 void pruneSnapshots(String type, DomainEventMessage mostRecentSnapshotEvent, int maxSnapshotsArchived, javax.persistence.EntityManager entityManager)
          Removes old snapshots from the storage for an aggregate of given type that generated the given mostRecentSnapshotEvent.
protected  String snapshotEventEntryEntityName()
          The name of the SnapshotEventEntry entity to use when querying for snapshot events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultEventEntryStore

public DefaultEventEntryStore()
Initialize the Event Entry Store, storing timestamps in the system timezone and storing serialized data as byte arrays.

See Also:
DefaultEventEntryStore(boolean)

DefaultEventEntryStore

public DefaultEventEntryStore(boolean forceUtcTimestamp)
Initializes the EventEntryStore, storing serialized data as byte arrays, with the possibility to force timestamps to be stored in UTC timezone. Although it is strongly recommended to set this value to true, it defaults to false, for backwards compatibility reasons.

Providing false will store the timestamps in the system timezone.

Parameters:
forceUtcTimestamp - whether to store dates in UTC format.

DefaultEventEntryStore

public DefaultEventEntryStore(EventEntryFactory<T> eventEntryFactory)
Initializes the EventEntryStore, using the given eventEntryFactory to provide instances of the JPA entities to use for persistence.

Parameters:
eventEntryFactory - the factory providing the Entity instances to persist
Method Detail

persistEvent

public void persistEvent(String aggregateType,
                         DomainEventMessage event,
                         SerializedObject<T> serializedPayload,
                         SerializedObject<T> serializedMetaData,
                         javax.persistence.EntityManager entityManager)
Description copied from interface: EventEntryStore
Persists the given event which has been serialized into serializedEvent in the backing data store using given entityManager.

These events should be returned by the fetchAggregateStream(...) methods.

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
entityManager - The entity manager providing access to the data store

loadLastSnapshotEvent

public SimpleSerializedDomainEventData loadLastSnapshotEvent(String aggregateType,
                                                             Object identifier,
                                                             javax.persistence.EntityManager entityManager)
Description copied from interface: EventEntryStore
Load the last known snapshot event for aggregate of given type with given identifier using given entityManager.

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
entityManager - The entity manager providing access to the data store
Returns:
the serialized representation of the last known snapshot event

fetchFiltered

public Iterator<SerializedDomainEventData<T>> fetchFiltered(String whereClause,
                                                            Map<String,Object> parameters,
                                                            int batchSize,
                                                            javax.persistence.EntityManager entityManager)
Description copied from interface: EventEntryStore
Creates an iterator that iterates through the Events that conform to the given JPA 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
entityManager - The entity manager providing access to the data store
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,
                            javax.persistence.EntityManager entityManager)
Description copied from interface: EventEntryStore
Persists the given event which has been serialized into serializedEvent in the backing data store using given entityManager.

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
entityManager - The entity manager providing access to the data store

getDataType

public Class<T> getDataType()
Description copied from interface: EventEntryStore
Returns the type used to store serialized payloads. This data type is an indication to the Event Store implementation to which type events must be serialized.

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

createDomainEventEntry

protected Object createDomainEventEntry(String aggregateType,
                                        DomainEventMessage event,
                                        SerializedObject<T> serializedPayload,
                                        SerializedObject<T> serializedMetaData)
Allows for customization of the DomainEventEntry to store. Subclasses may choose to override this method to use a different entity configuration.

When overriding this method, also make sure the domainEventEntryEntityName() method is overridden to return the correct entity name. Note that it is preferable to provide a custom EventEntryFactory, instead of overriding these methods.

Parameters:
aggregateType - The type identifier of the aggregate
event - The event to be stored
serializedPayload - The serialized payload of the event
serializedMetaData - The serialized meta data of the event
Returns:
a JPA entity, ready to be stored using the entity manager
See Also:
domainEventEntryEntityName(), EventEntryFactory.createDomainEventEntry(String, org.axonframework.domain.DomainEventMessage, org.axonframework.serializer.SerializedObject, org.axonframework.serializer.SerializedObject)

createSnapshotEventEntry

protected Object createSnapshotEventEntry(String aggregateType,
                                          DomainEventMessage snapshotEvent,
                                          SerializedObject<T> serializedPayload,
                                          SerializedObject<T> serializedMetaData)
Allows for customization of the SnapshotEventEntry to store. Subclasses may choose to override this method to use a different entity configuration.

When overriding this method, also make sure the snapshotEventEntryEntityName() method is overridden to return the correct entity name. Note that it is preferable to provide a custom EventEntryFactory, instead of overriding these methods.

Parameters:
aggregateType - The type identifier of the aggregate
snapshotEvent - The snapshot event to be stored
serializedPayload - The serialized payload of the event
serializedMetaData - The serialized meta data of the event
Returns:
a JPA entity, ready to be stored using the entity manager
See Also:
snapshotEventEntryEntityName(), EventEntryFactory.createSnapshotEventEntry(String, org.axonframework.domain.DomainEventMessage, org.axonframework.serializer.SerializedObject, org.axonframework.serializer.SerializedObject)

domainEventEntryEntityName

protected String domainEventEntryEntityName()
The name of the DomainEventEntry entity to use when querying for domain events.

Returns:
The entity name of the DomainEventEntry subclass to use
See Also:
createDomainEventEntry(String, org.axonframework.domain.DomainEventMessage, org.axonframework.serializer.SerializedObject, org.axonframework.serializer.SerializedObject), EventEntryFactory.getDomainEventEntryEntityName()

snapshotEventEntryEntityName

protected String snapshotEventEntryEntityName()
The name of the SnapshotEventEntry entity to use when querying for snapshot events.

Returns:
The entity name of the SnapshotEventEntry subclass to use
See Also:
createSnapshotEventEntry(String, org.axonframework.domain.DomainEventMessage, org.axonframework.serializer.SerializedObject, org.axonframework.serializer.SerializedObject), EventEntryFactory.getSnapshotEventEntryEntityName()

pruneSnapshots

public void pruneSnapshots(String type,
                           DomainEventMessage mostRecentSnapshotEvent,
                           int maxSnapshotsArchived,
                           javax.persistence.EntityManager entityManager)
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. The given entityManager provides access to the data store.

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
entityManager - the entityManager providing access to the data store

fetchAggregateStream

public Iterator<SerializedDomainEventData<T>> fetchAggregateStream(String aggregateType,
                                                                   Object identifier,
                                                                   long firstSequenceNumber,
                                                                   int batchSize,
                                                                   javax.persistence.EntityManager entityManager)
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. The given entityManager provides access to the backing data store.

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
batchSize - The number of entries to include in the batch (if available)
entityManager - The entity manager providing access to the data store
Returns:
a List of serialized representations of Events included in this batch


Copyright © 2010-2016. All Rights Reserved.