summaryrefslogtreecommitdiffstats
path: root/common/domain/event.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-16 14:55:20 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-21 09:02:21 +0200
commit237b9ae4113e7a9f489632296941becb71afdb45 (patch)
tree01cde58f495944f01cad9d282391d4efd2897141 /common/domain/event.cpp
parent95d11bf0be98a4e3c08502fe23417b800233ce14 (diff)
downloadsink-237b9ae4113e7a9f489632296941becb71afdb45.tar.gz
sink-237b9ae4113e7a9f489632296941becb71afdb45.zip
Refactor how the storage is used.
This is the initial refactoring to improve how we deal with the storage. It does a couple of things: * Rename Sink::Storage to Sink::Storage::DataStore to free up the Sink::Storage namespace * Introduce a Sink::ResourceContext to have a single object that can be passed around containing everything that is necessary to operate on a resource. This is a lot better than the multiple separate parameters that we used to pass around all over the place, while still allowing for dependency injection for tests. * Tie storage access together using the new EntityStore that directly works with ApplicationDomainTypes. This gives us a central place where main storage, indexes and buffer adaptors are tied together, which will also give us a place to implement external indexes, such as a fulltextindex using xapian. * Use ApplicationDomainTypes as the default way to pass around entities. Instead of using various ways to pass around entities (buffers, buffer adaptors, ApplicationDomainTypes), only use a single way. The old approach was confusing, and was only done as: * optimization; really shouldn't be necessary and otherwise I'm sure we can find better ways to optimize ApplicationDomainType itself. * a way to account for entities that have multiple buffers, a concept that I no longer deem relevant. While this commit does the bulk of the work to get there, the following commits will refactor more stuff to get things back to normal.
Diffstat (limited to 'common/domain/event.cpp')
-rw-r--r--common/domain/event.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/common/domain/event.cpp b/common/domain/event.cpp
index f3abd62..d801592 100644
--- a/common/domain/event.cpp
+++ b/common/domain/event.cpp
@@ -42,23 +42,28 @@ static QMutex sMutex;
42 42
43using namespace Sink::ApplicationDomain; 43using namespace Sink::ApplicationDomain;
44 44
45void TypeImplementation<Event>::configureIndex(TypeIndex &index)
46{
47 index.addProperty<QByteArray>(Event::Uid::name);
48}
49
45static TypeIndex &getIndex() 50static TypeIndex &getIndex()
46{ 51{
47 QMutexLocker locker(&sMutex); 52 QMutexLocker locker(&sMutex);
48 static TypeIndex *index = 0; 53 static TypeIndex *index = 0;
49 if (!index) { 54 if (!index) {
50 index = new TypeIndex("event"); 55 index = new TypeIndex("event");
51 index->addProperty<QByteArray>("uid"); 56 TypeImplementation<Event>::configureIndex(*index);
52 } 57 }
53 return *index; 58 return *index;
54} 59}
55 60
56void TypeImplementation<Event>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 61void TypeImplementation<Event>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction)
57{ 62{
58 return getIndex().add(identifier, bufferAdaptor, transaction); 63 return getIndex().add(identifier, bufferAdaptor, transaction);
59} 64}
60 65
61void TypeImplementation<Event>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 66void TypeImplementation<Event>::removeIndex(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction)
62{ 67{
63 return getIndex().remove(identifier, bufferAdaptor, transaction); 68 return getIndex().remove(identifier, bufferAdaptor, transaction);
64} 69}
@@ -83,10 +88,10 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Event>::BufferBuilder> > T
83 return propertyMapper; 88 return propertyMapper;
84} 89}
85 90
86DataStoreQuery::Ptr TypeImplementation<Event>::prepareQuery(const Sink::Query &query, Sink::Storage::Transaction &transaction) 91DataStoreQuery::Ptr TypeImplementation<Event>::prepareQuery(const Sink::Query &query, Sink::Storage::EntityStore::Ptr store)
87{ 92{
88 auto mapper = initializeReadPropertyMapper(); 93 auto mapper = initializeReadPropertyMapper();
89 return DataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName<Event>(), transaction, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) { 94 return DataStoreQuery::Ptr::create(query, ApplicationDomain::getTypeName<Event>(), store, getIndex(), [mapper](const Sink::Entity &entity, const QByteArray &property) {
90 95
91 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local()); 96 const auto localBuffer = Sink::EntityBuffer::readBuffer<Buffer>(entity.local());
92 return mapper->getProperty(property, localBuffer); 97 return mapper->getProperty(property, localBuffer);