org.axonframework.eventstore.mongo
Class MongoEventStore

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

public class MongoEventStore
extends Object
implements SnapshotEventStore, EventStoreManagement

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

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:
0.7
Author:
Jettro Coenradie

Constructor Summary
MongoEventStore(EventSerializer eventSerializer, com.mongodb.Mongo mongo)
          Deprecated. Use MongoEventStore(org.axonframework.serializer.Serializer, com.mongodb.Mongo) instead.
MongoEventStore(com.mongodb.Mongo mongo)
          Constructor that uses the default EventSerializer.
MongoEventStore(Serializer<? super DomainEvent> eventSerializer, com.mongodb.Mongo mongo)
          Constructor that accepts an EventSerializer, the MongoTemplate and a string containing the testContext.
 
Method Summary
 void appendEvents(String type, DomainEventStream events)
           
 void appendSnapshotEvent(String type, DomainEvent snapshotEvent)
           
 void ensureIndexes()
          Make sure an index is created on the collection that stores domain events.
 DomainEventStream readEvents(String type, AggregateIdentifier identifier)
           
 void setDatabaseName(String databaseName)
          Sets the name of the database in which the event store should create the event collections.
 void setDomainEventsCollectionName(String domainEventsCollectionName)
          Sets the name of the collection where this event store should store domain events.
 void setSnapshotEventsCollectionName(String snapshotEventsCollectionName)
          Sets the name of the collection where this event store should store snapshot events.
 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

@Deprecated
public MongoEventStore(EventSerializer eventSerializer,
                                  com.mongodb.Mongo mongo)
Deprecated. Use MongoEventStore(org.axonframework.serializer.Serializer, com.mongodb.Mongo) instead.

Constructor that accepts an EventSerializer, the MongoTemplate and a string containing the testContext. The TestContext can be Null. Provide true in case of the test context.

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

MongoEventStore

public MongoEventStore(Serializer<? super DomainEvent> eventSerializer,
                       com.mongodb.Mongo mongo)
Constructor that accepts an EventSerializer, the MongoTemplate and a string containing the testContext. The TestContext can be Null. Provide true in case of the test context.

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

MongoEventStore

public MongoEventStore(com.mongodb.Mongo mongo)
Constructor that uses the default EventSerializer.

Parameters:
mongo - Mongo instance to obtain the database and 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,
                                    AggregateIdentifier identifier)
Specified by:
readEvents in interface EventStore

appendSnapshotEvent

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

visitEvents

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

setDatabaseName

public void setDatabaseName(String databaseName)
Sets the name of the database in which the event store should create the event collections. Defaults to "axonframework". If no database with the given name exists, it is created.

Parameters:
databaseName - the name of the database where events should be stored

setDomainEventsCollectionName

public void setDomainEventsCollectionName(String domainEventsCollectionName)
Sets the name of the collection where this event store should store domain events. Defaults to "domainevents".

Note that you should not given this collection the same name as the snapshot events collection.

Parameters:
domainEventsCollectionName - The name of the collection that stores domain events.

setSnapshotEventsCollectionName

public void setSnapshotEventsCollectionName(String snapshotEventsCollectionName)
Sets the name of the collection where this event store should store snapshot events. Defaults to "snapshotevents".

Note that you should not given this collection the same name as the domain events collection.

Parameters:
snapshotEventsCollectionName - The name of the collection that stores snapshot events.


Copyright © 2011. All Rights Reserved.