diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 9 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 21 | ||||
-rw-r--r-- | common/domain/event.cpp | 2 | ||||
-rw-r--r-- | common/pipeline.cpp | 16 |
4 files changed, 39 insertions, 9 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index fccf082..1649cb4 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -76,13 +76,18 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const | |||
76 | void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) | 76 | void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) |
77 | { | 77 | { |
78 | Q_ASSERT(mAdaptor); | 78 | Q_ASSERT(mAdaptor); |
79 | mChangeSet.insert(key, value); | 79 | mChangeSet.insert(key); |
80 | mAdaptor->setProperty(key, value); | 80 | mAdaptor->setProperty(key, value); |
81 | } | 81 | } |
82 | 82 | ||
83 | void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) | ||
84 | { | ||
85 | mChangeSet = changeset; | ||
86 | } | ||
87 | |||
83 | QByteArrayList ApplicationDomainType::changedProperties() const | 88 | QByteArrayList ApplicationDomainType::changedProperties() const |
84 | { | 89 | { |
85 | return mChangeSet.keys(); | 90 | return mChangeSet.toList(); |
86 | } | 91 | } |
87 | 92 | ||
88 | qint64 ApplicationDomainType::revision() const | 93 | qint64 ApplicationDomainType::revision() const |
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index ca1ec1b..ce35af0 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <QSharedPointer> | 23 | #include <QSharedPointer> |
24 | #include <QVariant> | 24 | #include <QVariant> |
25 | #include <QByteArray> | 25 | #include <QByteArray> |
26 | #include <QDebug> | ||
26 | #include "bufferadaptor.h" | 27 | #include "bufferadaptor.h" |
27 | 28 | ||
28 | namespace Sink { | 29 | namespace Sink { |
@@ -56,16 +57,18 @@ public: | |||
56 | 57 | ||
57 | virtual ~ApplicationDomainType(); | 58 | virtual ~ApplicationDomainType(); |
58 | 59 | ||
59 | virtual QVariant getProperty(const QByteArray &key) const; | 60 | QVariant getProperty(const QByteArray &key) const;; |
60 | virtual void setProperty(const QByteArray &key, const QVariant &value); | 61 | void setProperty(const QByteArray &key, const QVariant &value); |
61 | virtual QByteArrayList changedProperties() const; | 62 | void setChangedProperties(const QSet<QByteArray> &changeset); |
63 | QByteArrayList changedProperties() const; | ||
62 | qint64 revision() const; | 64 | qint64 revision() const; |
63 | QByteArray resourceInstanceIdentifier() const; | 65 | QByteArray resourceInstanceIdentifier() const; |
64 | QByteArray identifier() const; | 66 | QByteArray identifier() const; |
65 | 67 | ||
66 | private: | 68 | private: |
69 | friend QDebug operator<<(QDebug, const ApplicationDomainType &); | ||
67 | QSharedPointer<BufferAdaptor> mAdaptor; | 70 | QSharedPointer<BufferAdaptor> mAdaptor; |
68 | QHash<QByteArray, QVariant> mChangeSet; | 71 | QSet<QByteArray> mChangeSet; |
69 | /* | 72 | /* |
70 | * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. | 73 | * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. |
71 | */ | 74 | */ |
@@ -83,6 +86,16 @@ inline bool operator==(const ApplicationDomainType& lhs, const ApplicationDomain | |||
83 | && lhs.resourceInstanceIdentifier() == rhs.resourceInstanceIdentifier(); | 86 | && lhs.resourceInstanceIdentifier() == rhs.resourceInstanceIdentifier(); |
84 | } | 87 | } |
85 | 88 | ||
89 | inline QDebug operator<< (QDebug d, const ApplicationDomainType &type) | ||
90 | { | ||
91 | d << "ApplicationDomainType(\n"; | ||
92 | for (const auto &property : type.mAdaptor->availableProperties()) { | ||
93 | d << " " << property << "\t" << type.getProperty(property) << "\n"; | ||
94 | } | ||
95 | d << ")"; | ||
96 | return d; | ||
97 | } | ||
98 | |||
86 | struct SINKCOMMON_EXPORT Entity : public ApplicationDomainType { | 99 | struct SINKCOMMON_EXPORT Entity : public ApplicationDomainType { |
87 | typedef QSharedPointer<Entity> Ptr; | 100 | typedef QSharedPointer<Entity> Ptr; |
88 | using ApplicationDomainType::ApplicationDomainType; | 101 | using ApplicationDomainType::ApplicationDomainType; |
diff --git a/common/domain/event.cpp b/common/domain/event.cpp index 9f81eb8..4210125 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp | |||
@@ -69,6 +69,7 @@ QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImple | |||
69 | { | 69 | { |
70 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); | 70 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); |
71 | propertyMapper->addMapping<QString, Buffer>("summary", &Buffer::summary); | 71 | propertyMapper->addMapping<QString, Buffer>("summary", &Buffer::summary); |
72 | propertyMapper->addMapping<QString, Buffer>("description", &Buffer::description); | ||
72 | propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid); | 73 | propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid); |
73 | propertyMapper->addMapping<QByteArray, Buffer>("attachment", &Buffer::attachment); | 74 | propertyMapper->addMapping<QByteArray, Buffer>("attachment", &Buffer::attachment); |
74 | return propertyMapper; | 75 | return propertyMapper; |
@@ -78,6 +79,7 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Event>::BufferBuilder> > T | |||
78 | { | 79 | { |
79 | auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create(); | 80 | auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create(); |
80 | propertyMapper->addMapping<QString>("summary", &BufferBuilder::add_summary); | 81 | propertyMapper->addMapping<QString>("summary", &BufferBuilder::add_summary); |
82 | propertyMapper->addMapping<QString>("description", &BufferBuilder::add_description); | ||
81 | propertyMapper->addMapping<QString>("uid", &BufferBuilder::add_uid); | 83 | propertyMapper->addMapping<QString>("uid", &BufferBuilder::add_uid); |
82 | propertyMapper->addMapping<QByteArray>("attachment", &BufferBuilder::add_attachment); | 84 | propertyMapper->addMapping<QByteArray>("attachment", &BufferBuilder::add_attachment); |
83 | return propertyMapper; | 85 | return propertyMapper; |
diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 0598bad..03d4e42 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp | |||
@@ -279,9 +279,16 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size) | |||
279 | //Apply diff | 279 | //Apply diff |
280 | //FIXME only apply the properties that are available in the buffer | 280 | //FIXME only apply the properties that are available in the buffer |
281 | Trace() << "Applying changed properties: " << diff->availableProperties(); | 281 | Trace() << "Applying changed properties: " << diff->availableProperties(); |
282 | QSet<QByteArray> changeset; | ||
282 | for (const auto &property : diff->availableProperties()) { | 283 | for (const auto &property : diff->availableProperties()) { |
283 | newObject->setProperty(property, diff->getProperty(property)); | 284 | changeset << property; |
285 | const auto value = diff->getProperty(property); | ||
286 | if (value.isValid()) { | ||
287 | newObject->setProperty(property, value); | ||
288 | } | ||
284 | } | 289 | } |
290 | //Altough we only set some properties, we want all to be serialized | ||
291 | newObject->setChangedProperties(changeset); | ||
285 | 292 | ||
286 | //Remove deletions | 293 | //Remove deletions |
287 | if (modifyEntity->deletions()) { | 294 | if (modifyEntity->deletions()) { |
@@ -304,8 +311,11 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size) | |||
304 | 311 | ||
305 | storeNewRevision(newRevision, fbb, bufferType, key); | 312 | storeNewRevision(newRevision, fbb, bufferType, key); |
306 | Log() << "Pipeline: modified entity: " << key << newRevision << bufferType; | 313 | Log() << "Pipeline: modified entity: " << key << newRevision << bufferType; |
307 | d->transaction.openDatabase(bufferType + ".main").scan(Sink::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, current, key](const QByteArray &, const QByteArray &value) -> bool { | 314 | d->transaction.openDatabase(bufferType + ".main").scan(Sink::Storage::assembleKey(key, newRevision), [this, bufferType, newRevision, adaptorFactory, current, key](const QByteArray &k, const QByteArray &value) -> bool { |
308 | auto entity = Sink::GetEntity(value); | 315 | if (value.isEmpty()) { |
316 | ErrorMsg() << "Read buffer is empty."; | ||
317 | } | ||
318 | auto entity = Sink::GetEntity(value.data()); | ||
309 | auto newEntity = adaptorFactory->createAdaptor(*entity); | 319 | auto newEntity = adaptorFactory->createAdaptor(*entity); |
310 | for (auto processor : d->processors[bufferType]) { | 320 | for (auto processor : d->processors[bufferType]) { |
311 | processor->modifiedEntity(key, newRevision, *current, *newEntity, d->transaction); | 321 | processor->modifiedEntity(key, newRevision, *current, *newEntity, d->transaction); |