org.axonframework.mongo3.eventstore
Class DocumentPerCommitStorageStrategy

java.lang.Object
  extended by org.axonframework.mongo3.eventstore.DocumentPerCommitStorageStrategy
All Implemented Interfaces:
StorageStrategy

public class DocumentPerCommitStorageStrategy
extends Object
implements StorageStrategy

Implementation of the StorageStrategy that stores each commit as a single document. The document contains an array containing each separate event.

The structure is as follows:

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

Since:
2.0
Author:
Allard Buijze

Constructor Summary
DocumentPerCommitStorageStrategy()
           
 
Method Summary
 List<org.bson.Document> createDocuments(String type, Serializer eventSerializer, List<DomainEventMessage> messages)
          Generates the DBObject instances that need to be stored for a commit.
 void ensureIndexes(com.mongodb.client.MongoCollection eventsCollection, com.mongodb.client.MongoCollection snapshotsCollection)
          Ensure that the correct indexes are in place.
 List<DomainEventMessage> extractEventMessages(org.bson.Document entry, Object aggregateIdentifier, Serializer serializer, UpcasterChain upcasterChain, boolean skipUnknownTypes)
          Extracts the individual Event Messages from the given entry.
 com.mongodb.client.MongoCursor<org.bson.Document> findEvents(com.mongodb.client.MongoCollection<org.bson.Document> collection, MongoCriteria criteria)
          Find all events that match the given criteria in the given collection
 com.mongodb.client.MongoCursor<org.bson.Document> findEvents(com.mongodb.client.MongoCollection collection, String aggregateType, String aggregateIdentifier, long firstSequenceNumber)
          Provides a cursor for access to all events for an aggregate with given aggregateType and aggregateIdentifier, with a sequence number equal or higher than the given firstSequenceNumber.
 com.mongodb.client.MongoCursor<org.bson.Document> findLastSnapshot(com.mongodb.client.MongoCollection collection, String aggregateType, String aggregateIdentifier)
          Finds the entry containing the last snapshot event for an aggregate with given aggregateType and aggregateIdentifier in the given collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DocumentPerCommitStorageStrategy

public DocumentPerCommitStorageStrategy()
Method Detail

createDocuments

public List<org.bson.Document> createDocuments(String type,
                                               Serializer eventSerializer,
                                               List<DomainEventMessage> messages)
Description copied from interface: StorageStrategy
Generates the DBObject instances that need to be stored for a commit.

Specified by:
createDocuments in interface StorageStrategy
Parameters:
type - The aggregate's type identifier
eventSerializer - The serializer to serialize events with
messages - The messages contained in this commit
Returns:
an array of DBObject, representing the documents to store

findEvents

public com.mongodb.client.MongoCursor<org.bson.Document> findEvents(com.mongodb.client.MongoCollection collection,
                                                                    String aggregateType,
                                                                    String aggregateIdentifier,
                                                                    long firstSequenceNumber)
Description copied from interface: StorageStrategy
Provides a cursor for access to all events for an aggregate with given aggregateType and aggregateIdentifier, with a sequence number equal or higher than the given firstSequenceNumber. The returned documents should be ordered chronologically (typically by using the sequence number).

Each DBObject document returned as result of this cursor will be passed to StorageStrategy.extractEventMessages(org.bson.Document, java.lang.Object, org.axonframework.serializer.Serializer, org.axonframework.upcasting.UpcasterChain, boolean) in order to retrieve individual DomainEventMessages.

Specified by:
findEvents in interface StorageStrategy
Parameters:
collection - The collection to search for events
aggregateType - The type identifier of the aggregate to query
aggregateIdentifier - The identifier of the aggregate to query
firstSequenceNumber - The sequence number of the first event to return
Returns:
a Query object that represent a query for events of an aggregate

findEvents

public com.mongodb.client.MongoCursor<org.bson.Document> findEvents(com.mongodb.client.MongoCollection<org.bson.Document> collection,
                                                                    MongoCriteria criteria)
Description copied from interface: StorageStrategy
Find all events that match the given criteria in the given collection

Specified by:
findEvents in interface StorageStrategy
Parameters:
collection - The collection to search for events
criteria - The criteria to match against the events
Returns:
a cursor for the documents representing matched events

extractEventMessages

public List<DomainEventMessage> extractEventMessages(org.bson.Document entry,
                                                     Object aggregateIdentifier,
                                                     Serializer serializer,
                                                     UpcasterChain upcasterChain,
                                                     boolean skipUnknownTypes)
Description copied from interface: StorageStrategy
Extracts the individual Event Messages from the given entry. The aggregateIdentifier is passed to allow messages to contain the actual object, instead of its serialized form. The serializer and upcasterChain should be used to deserialize and upcast messages before returning them.

Specified by:
extractEventMessages in interface StorageStrategy
Parameters:
entry - The entry containing information of a stored commit
aggregateIdentifier - The aggregate identifier used to query events
serializer - The serializer to deserialize events with
upcasterChain - The upcaster chain to upcast stored events with
skipUnknownTypes - Whether unknown event types should be skipped
Returns:
a list of DomainEventMessage contained in the entry

ensureIndexes

public void ensureIndexes(com.mongodb.client.MongoCollection eventsCollection,
                          com.mongodb.client.MongoCollection snapshotsCollection)
Description copied from interface: StorageStrategy
Ensure that the correct indexes are in place.

Specified by:
ensureIndexes in interface StorageStrategy
Parameters:
eventsCollection - The collection containing the documents representing commits and events.
snapshotsCollection - The collection containing the document representing snapshots

findLastSnapshot

public com.mongodb.client.MongoCursor<org.bson.Document> findLastSnapshot(com.mongodb.client.MongoCollection collection,
                                                                          String aggregateType,
                                                                          String aggregateIdentifier)
Description copied from interface: StorageStrategy
Finds the entry containing the last snapshot event for an aggregate with given aggregateType and aggregateIdentifier in the given collection. For each result returned by the Cursor, an invocation to StorageStrategy.extractEventMessages(org.bson.Document, java.lang.Object, org.axonframework.serializer.Serializer, org.axonframework.upcasting.UpcasterChain, boolean) will be used to extract the actual DomainEventMessages.

Specified by:
findLastSnapshot in interface StorageStrategy
Parameters:
collection - The collection to find the last snapshot event in
aggregateType - The type identifier of the aggregate to find a snapshot for
aggregateIdentifier - The identifier of the aggregate to find a snapshot for
Returns:
a cursor providing access to the entries found


Copyright © 2010-2016. All Rights Reserved.