diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-29 15:19:21 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-29 15:19:21 +0200 |
commit | dabd408dcd372f16c7934597db30346869cd8ad8 (patch) | |
tree | 0d6513204b7fa6e34cf50733ad0472866ea05e2a /common/synchronizer.cpp | |
parent | b441386c4e138d19bbd79d578e0a2ff1b3f54a93 (diff) | |
download | sink-dabd408dcd372f16c7934597db30346869cd8ad8.tar.gz sink-dabd408dcd372f16c7934597db30346869cd8ad8.zip |
Fixed genericresource so it works with the maildirresourcetest
Diffstat (limited to 'common/synchronizer.cpp')
-rw-r--r-- | common/synchronizer.cpp | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index fb0baaa..b264662 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp | |||
@@ -54,7 +54,7 @@ void Synchronizer::enqueueCommand(int commandId, const QByteArray &data) | |||
54 | EntityStore &Synchronizer::store() | 54 | EntityStore &Synchronizer::store() |
55 | { | 55 | { |
56 | if (!mEntityStore) { | 56 | if (!mEntityStore) { |
57 | mEntityStore = QSharedPointer<EntityStore>::create(mResourceType, mResourceInstanceIdentifier, mTransaction); | 57 | mEntityStore = QSharedPointer<EntityStore>::create(mResourceType, mResourceInstanceIdentifier, transaction()); |
58 | } | 58 | } |
59 | return *mEntityStore; | 59 | return *mEntityStore; |
60 | } | 60 | } |
@@ -62,7 +62,7 @@ EntityStore &Synchronizer::store() | |||
62 | RemoteIdMap &Synchronizer::syncStore() | 62 | RemoteIdMap &Synchronizer::syncStore() |
63 | { | 63 | { |
64 | if (!mSyncStore) { | 64 | if (!mSyncStore) { |
65 | mSyncStore = QSharedPointer<RemoteIdMap>::create(mSyncTransaction); | 65 | mSyncStore = QSharedPointer<RemoteIdMap>::create(syncTransaction()); |
66 | } | 66 | } |
67 | return *mSyncStore; | 67 | return *mSyncStore; |
68 | } | 68 | } |
@@ -125,7 +125,7 @@ void Synchronizer::scanForRemovals(const QByteArray &bufferType, const std::func | |||
125 | if (!remoteId.isEmpty()) { | 125 | if (!remoteId.isEmpty()) { |
126 | if (!exists(remoteId)) { | 126 | if (!exists(remoteId)) { |
127 | Trace() << "Found a removed entity: " << sinkId; | 127 | Trace() << "Found a removed entity: " << sinkId; |
128 | deleteEntity(sinkId, Sink::Storage::maxRevision(mTransaction), bufferType, | 128 | deleteEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType, |
129 | [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::DeleteEntityCommand, buffer); }); | 129 | [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::DeleteEntityCommand, buffer); }); |
130 | } | 130 | } |
131 | } | 131 | } |
@@ -135,7 +135,7 @@ void Synchronizer::scanForRemovals(const QByteArray &bufferType, const std::func | |||
135 | void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) | 135 | void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) |
136 | { | 136 | { |
137 | Trace() << "Create or modify" << bufferType << remoteId; | 137 | Trace() << "Create or modify" << bufferType << remoteId; |
138 | auto mainDatabase = Storage::mainDatabase(mTransaction, bufferType); | 138 | auto mainDatabase = Storage::mainDatabase(transaction(), bufferType); |
139 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); | 139 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); |
140 | const auto found = mainDatabase.contains(sinkId); | 140 | const auto found = mainDatabase.contains(sinkId); |
141 | auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(mResourceType, bufferType); | 141 | auto adaptorFactory = Sink::AdaptorFactoryRegistry::instance().getFactory(mResourceType, bufferType); |
@@ -154,7 +154,7 @@ void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray | |||
154 | } | 154 | } |
155 | if (changed) { | 155 | if (changed) { |
156 | Trace() << "Found a modified entity: " << remoteId; | 156 | Trace() << "Found a modified entity: " << remoteId; |
157 | modifyEntity(sinkId, Sink::Storage::maxRevision(mTransaction), bufferType, entity, *adaptorFactory, | 157 | modifyEntity(sinkId, Sink::Storage::maxRevision(transaction()), bufferType, entity, *adaptorFactory, |
158 | [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::ModifyEntityCommand, buffer); }); | 158 | [this](const QByteArray &buffer) { enqueueCommand(Sink::Commands::ModifyEntityCommand, buffer); }); |
159 | } | 159 | } |
160 | } else { | 160 | } else { |
@@ -165,12 +165,37 @@ void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray | |||
165 | 165 | ||
166 | KAsync::Job<void> Synchronizer::synchronize() | 166 | KAsync::Job<void> Synchronizer::synchronize() |
167 | { | 167 | { |
168 | mTransaction = mStorage.createTransaction(Sink::Storage::ReadOnly); | 168 | Trace() << "Synchronizing"; |
169 | mSyncTransaction = mSyncStorage.createTransaction(Sink::Storage::ReadWrite); | ||
170 | return synchronizeWithSource().then<void>([this]() { | 169 | return synchronizeWithSource().then<void>([this]() { |
171 | mTransaction.abort(); | ||
172 | mSyncTransaction.commit(); | ||
173 | mSyncStore.clear(); | 170 | mSyncStore.clear(); |
174 | mEntityStore.clear(); | 171 | mEntityStore.clear(); |
175 | }); | 172 | }); |
176 | } | 173 | } |
174 | |||
175 | void Synchronizer::commit() | ||
176 | { | ||
177 | mTransaction.abort(); | ||
178 | } | ||
179 | |||
180 | void Synchronizer::commitSync() | ||
181 | { | ||
182 | mSyncTransaction.commit(); | ||
183 | } | ||
184 | |||
185 | Sink::Storage::Transaction &Synchronizer::transaction() | ||
186 | { | ||
187 | if (!mTransaction) { | ||
188 | Trace() << "Starting transaction"; | ||
189 | mTransaction = mStorage.createTransaction(Sink::Storage::ReadOnly); | ||
190 | } | ||
191 | return mTransaction; | ||
192 | } | ||
193 | |||
194 | Sink::Storage::Transaction &Synchronizer::syncTransaction() | ||
195 | { | ||
196 | if (!mSyncTransaction) { | ||
197 | Trace() << "Starting transaction"; | ||
198 | mSyncTransaction = mSyncStorage.createTransaction(Sink::Storage::ReadWrite); | ||
199 | } | ||
200 | return mSyncTransaction; | ||
201 | } | ||