diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-01 13:12:37 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-01 13:12:37 +0100 |
commit | 0b233494a69b5e9cd86e91c60016a294e6c9ef50 (patch) | |
tree | ecd21c0ddeb54f2fc43217016d0cc0f539cafd6d | |
parent | 18a6b06ac47a69ec53c658ca7384fe1b16cff3fd (diff) | |
download | sink-0b233494a69b5e9cd86e91c60016a294e6c9ef50.tar.gz sink-0b233494a69b5e9cd86e91c60016a294e6c9ef50.zip |
Fixed modifications
-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 | ||||
-rw-r--r-- | tests/pipelinetest.cpp | 12 |
5 files changed, 48 insertions, 12 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); |
diff --git a/tests/pipelinetest.cpp b/tests/pipelinetest.cpp index c74d319..baa67f6 100644 --- a/tests/pipelinetest.cpp +++ b/tests/pipelinetest.cpp | |||
@@ -52,7 +52,7 @@ static QByteArray getEntity(const QByteArray &dbEnv, const QByteArray &name, con | |||
52 | return result; | 52 | return result; |
53 | } | 53 | } |
54 | 54 | ||
55 | flatbuffers::FlatBufferBuilder &createEvent(flatbuffers::FlatBufferBuilder &entityFbb, const QString &s = QString("summary")) | 55 | flatbuffers::FlatBufferBuilder &createEvent(flatbuffers::FlatBufferBuilder &entityFbb, const QString &s = QString("summary"), const QString &d = QString()) |
56 | { | 56 | { |
57 | flatbuffers::FlatBufferBuilder eventFbb; | 57 | flatbuffers::FlatBufferBuilder eventFbb; |
58 | eventFbb.Clear(); | 58 | eventFbb.Clear(); |
@@ -66,9 +66,13 @@ flatbuffers::FlatBufferBuilder &createEvent(flatbuffers::FlatBufferBuilder &enti | |||
66 | { | 66 | { |
67 | auto uid = localFbb.CreateString("testuid"); | 67 | auto uid = localFbb.CreateString("testuid"); |
68 | auto summary = localFbb.CreateString(s.toStdString()); | 68 | auto summary = localFbb.CreateString(s.toStdString()); |
69 | auto description = localFbb.CreateString(d.toStdString()); | ||
69 | auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); | 70 | auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); |
70 | localBuilder.add_uid(uid); | 71 | localBuilder.add_uid(uid); |
71 | localBuilder.add_summary(summary); | 72 | localBuilder.add_summary(summary); |
73 | if (!d.isEmpty()) { | ||
74 | localBuilder.add_description(description); | ||
75 | } | ||
72 | auto location = localBuilder.Finish(); | 76 | auto location = localBuilder.Finish(); |
73 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); | 77 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); |
74 | } | 78 | } |
@@ -203,7 +207,7 @@ private Q_SLOTS: | |||
203 | void testModify() | 207 | void testModify() |
204 | { | 208 | { |
205 | flatbuffers::FlatBufferBuilder entityFbb; | 209 | flatbuffers::FlatBufferBuilder entityFbb; |
206 | auto command = createEntityCommand(createEvent(entityFbb)); | 210 | auto command = createEntityCommand(createEvent(entityFbb, "summary", "description")); |
207 | 211 | ||
208 | Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); | 212 | Sink::Pipeline pipeline("org.kde.pipelinetest.instance1"); |
209 | 213 | ||
@@ -233,7 +237,9 @@ private Q_SLOTS: | |||
233 | QVERIFY(!buffer.isEmpty()); | 237 | QVERIFY(!buffer.isEmpty()); |
234 | Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); | 238 | Sink::EntityBuffer entityBuffer(buffer.data(), buffer.size()); |
235 | auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); | 239 | auto adaptor = adaptorFactory->createAdaptor(entityBuffer.entity()); |
236 | QCOMPARE(adaptor->getProperty("summary").toString(), QString("summary2")); | 240 | QVERIFY2(adaptor->getProperty("summary").toString() == QString("summary2"), "The modification isn't applied."); |
241 | //Ensure we didn't modify anything else | ||
242 | QVERIFY2(adaptor->getProperty("description").toString() == QString("description"), "The modification has sideeffects."); | ||
237 | 243 | ||
238 | //Both revisions are in the store at this point | 244 | //Both revisions are in the store at this point |
239 | QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2); | 245 | QCOMPARE(getKeys("org.kde.pipelinetest.instance1", "event.main").size(), 2); |