org.axonframework.eventstore.mongo
Class MongoEventStore

java.lang.Object
  extended by org.axonframework.eventstore.mongo.MongoEventStore
All Implemented Interfaces:
EventStore, EventStoreManagement, SnapshotEventStore, UpcasterAware

public class MongoEventStore
extends Object
implements SnapshotEventStore, EventStoreManagement, UpcasterAware

Implementation of the EventStore based on a MongoDB instance or replica set. Sharding and pairing are not explicitly supported.

This event store implementation needs a serializer as well as a MongoTemplate to interact with the mongo database.

Warning: This implementation is still in progress and may be subject to alterations. The implementation works, but has not been optimized to fully leverage MongoDB's features, yet.

Since:
2.0 (in incubator since 0.7)
Author:
Jettro Coenradie

Constructor Summary
MongoEventStore(MongoTemplate mongo)
          Constructor that uses the default Serializer.
MongoEventStore(MongoTemplate mongoTemplate, Serializer eventSerializer, StorageStrategy storageStrategy)
          Initialize the mongo event store with given mongoTemplate, eventSerializer and storageStrategy.
MongoEventStore(MongoTemplate mongoTemplate, StorageStrategy storageStrategy)
          Constructor that accepts a MongoTemplate and a custom StorageStrategy.
MongoEventStore(Serializer eventSerializer, MongoTemplate mongo)
          Constructor that accepts a Serializer and the MongoTemplate.
 
Method Summary
 void appendEvents(String type, DomainEventStream events)
           
 void appendSnapshotEvent(String type, DomainEventMessage snapshotEvent)
           
 void ensureIndexes()
          Make sure an index is created on the collection that stores domain events.
 MongoCriteriaBuilder newCriteriaBuilder()
           
 DomainEventStream readEvents(String type, Object identifier)
           
 void setUpcasterChain(UpcasterChain upcasterChain)
           
 void visitEvents(Criteria criteria, EventVisitor visitor)
           
 void visitEvents(EventVisitor visitor)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MongoEventStore

public MongoEventStore(Serializer eventSerializer,
                       MongoTemplate mongo)
Constructor that accepts a Serializer and the MongoTemplate. A Document-Per-Event storage strategy is used, causing each event to be stored in a separate Mongo Document.

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).

Parameters:
eventSerializer - Your own Serializer
mongo - Mongo instance to obtain the database and the collections.

MongoEventStore

public MongoEventStore(MongoTemplate mongo)
Constructor that uses the default Serializer. A Document-Per-Event storage strategy is used, causing each event to be stored in a separate Mongo Document.

Parameters:
mongo - MongoTemplate instance to obtain the database and the collections.

MongoEventStore

public MongoEventStore(MongoTemplate mongoTemplate,
                       StorageStrategy storageStrategy)
Constructor that accepts a MongoTemplate and a custom StorageStrategy.

Parameters:
mongoTemplate - The template giving access to the required collections
storageStrategy - The strategy for storing and retrieving events from the collections

MongoEventStore

public MongoEventStore(MongoTemplate mongoTemplate,
                       Serializer eventSerializer,
                       StorageStrategy storageStrategy)
Initialize the mongo event store with given mongoTemplate, eventSerializer and storageStrategy.

Parameters:
mongoTemplate - The template giving access to the required collections
eventSerializer - The serializer to serialize events with
storageStrategy - The strategy for storing and retrieving events from the collections
Method Detail

ensureIndexes

@PostConstruct
public void ensureIndexes()
Make sure an index is created on the collection that stores domain events.


appendEvents

public void appendEvents(String type,
                         DomainEventStream events)
Specified by:
appendEvents in interface EventStore

readEvents

public DomainEventStream readEvents(String type,
                                    Object identifier)
Specified by:
readEvents in interface EventStore

appendSnapshotEvent

public void appendSnapshotEvent(String type,
                                DomainEventMessage snapshotEvent)
Specified by:
appendSnapshotEvent in interface SnapshotEventStore

visitEvents

public void visitEvents(EventVisitor visitor)
Specified by:
visitEvents in interface EventStoreManagement

visitEvents

public void visitEvents(Criteria criteria,
                        EventVisitor visitor)
Specified by:
visitEvents in interface EventStoreManagement

newCriteriaBuilder

public MongoCriteriaBuilder newCriteriaBuilder()
Specified by:
newCriteriaBuilder in interface EventStoreManagement

setUpcasterChain

public void setUpcasterChain(UpcasterChain upcasterChain)
Specified by:
setUpcasterChain in interface UpcasterAware


Copyright © 2010-2013. All Rights Reserved.