summaryrefslogtreecommitdiffstats
path: root/common/facade.cpp
diff options
context:
space:
mode:
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}