summaryrefslogtreecommitdiffstats
path: root/common/facade.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/facade.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/facade.cpp')
-rw-r--r--common/facade.cpp22
1 files changed, 8 insertions, 14 deletions
diff --git a/common/facade.cpp b/common/facade.cpp
index 72f7414..3ec58e3 100644
--- a/common/facade.cpp
+++ b/common/facade.cpp
@@ -31,13 +31,9 @@
31using namespace Sink; 31using namespace Sink;
32 32
33template <class DomainType> 33template <class DomainType>
34GenericFacade<DomainType>::GenericFacade( 34GenericFacade<DomainType>::GenericFacade(const ResourceContext &context)
35 const QByteArray &resourceIdentifier, const DomainTypeAdaptorFactoryInterface::Ptr &adaptorFactory, const QSharedPointer<Sink::ResourceAccessInterface> resourceAccess) 35 : Sink::StoreFacade<DomainType>(), mResourceContext(context), mResourceAccess(mResourceContext.resourceAccess())
36 : Sink::StoreFacade<DomainType>(), mResourceAccess(resourceAccess), mDomainTypeAdaptorFactory(adaptorFactory), mResourceInstanceIdentifier(resourceIdentifier)
37{ 36{
38 if (!mResourceAccess) {
39 mResourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier, ResourceConfig::getResourceType(resourceIdentifier));
40 }
41} 37}
42 38
43template <class DomainType> 39template <class DomainType>
@@ -55,25 +51,23 @@ QByteArray GenericFacade<DomainType>::bufferTypeForDomainType()
55template <class DomainType> 51template <class DomainType>
56KAsync::Job<void> GenericFacade<DomainType>::create(const DomainType &domainObject) 52KAsync::Job<void> GenericFacade<DomainType>::create(const DomainType &domainObject)
57{ 53{
58 if (!mDomainTypeAdaptorFactory) { 54 flatbuffers::FlatBufferBuilder entityFbb;
55 if (!mResourceContext.adaptorFactory<DomainType>().createBuffer(domainObject, entityFbb)) {
59 SinkWarning() << "No domain type adaptor factory available"; 56 SinkWarning() << "No domain type adaptor factory available";
60 return KAsync::error<void>(); 57 return KAsync::error<void>();
61 } 58 }
62 flatbuffers::FlatBufferBuilder entityFbb;
63 mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb);
64 return mResourceAccess->sendCreateCommand(domainObject.identifier(), bufferTypeForDomainType(), BufferUtils::extractBuffer(entityFbb)); 59 return mResourceAccess->sendCreateCommand(domainObject.identifier(), bufferTypeForDomainType(), BufferUtils::extractBuffer(entityFbb));
65} 60}
66 61
67template <class DomainType> 62template <class DomainType>
68KAsync::Job<void> GenericFacade<DomainType>::modify(const DomainType &domainObject) 63KAsync::Job<void> GenericFacade<DomainType>::modify(const DomainType &domainObject)
69{ 64{
70 if (!mDomainTypeAdaptorFactory) { 65 SinkTrace() << "Modifying entity: " << domainObject.identifier() << domainObject.changedProperties();
66 flatbuffers::FlatBufferBuilder entityFbb;
67 if (!mResourceContext.adaptorFactory<DomainType>().createBuffer(domainObject, entityFbb)) {
71 SinkWarning() << "No domain type adaptor factory available"; 68 SinkWarning() << "No domain type adaptor factory available";
72 return KAsync::error<void>(); 69 return KAsync::error<void>();
73 } 70 }
74 SinkTrace() << "Modifying entity: " << domainObject.identifier() << domainObject.changedProperties();
75 flatbuffers::FlatBufferBuilder entityFbb;
76 mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb);
77 return mResourceAccess->sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), BufferUtils::extractBuffer(entityFbb), domainObject.changedProperties()); 71 return mResourceAccess->sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), BufferUtils::extractBuffer(entityFbb), domainObject.changedProperties());
78} 72}
79 73
@@ -87,7 +81,7 @@ template <class DomainType>
87QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> GenericFacade<DomainType>::load(const Sink::Query &query) 81QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> GenericFacade<DomainType>::load(const Sink::Query &query)
88{ 82{
89 // The runner lives for the lifetime of the query 83 // The runner lives for the lifetime of the query
90 auto runner = new QueryRunner<DomainType>(query, mResourceAccess, mResourceInstanceIdentifier, mDomainTypeAdaptorFactory, bufferTypeForDomainType()); 84 auto runner = new QueryRunner<DomainType>(query, mResourceContext, bufferTypeForDomainType());
91 runner->setResultTransformation(mResultTransformation); 85 runner->setResultTransformation(mResultTransformation);
92 return qMakePair(KAsync::null<void>(), runner->emitter()); 86 return qMakePair(KAsync::null<void>(), runner->emitter());
93} 87}