summaryrefslogtreecommitdiffstats
path: root/common/storage/entitystore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/storage/entitystore.cpp')
-rw-r--r--common/storage/entitystore.cpp43
1 files changed, 18 insertions, 25 deletions
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp
index dce2fc6..3c3840a 100644
--- a/common/storage/entitystore.cpp
+++ b/common/storage/entitystore.cpp
@@ -57,40 +57,33 @@ public:
57 return transaction; 57 return transaction;
58 } 58 }
59 59
60 /* template<typename T> */ 60 template<typename ...Args>
61 /* TypeIndex &typeIndex(const QByteArray &type) */ 61 void configure(const QByteArray &type, Args && ... args)
62 /* { */
63 /* if (indexByType.contains(type)) { */
64 /* return *indexByType.value(type); */
65 /* } */
66 /* auto index = QSharedPointer<TypeIndex>::create(type); */
67 /* ApplicationDomain::TypeImplementation<T>::configure(*index); */
68 /* indexByType.insert(type, index); */
69 /* return *index; */
70 /* } */
71
72 TypeIndex &cachedIndex(const QByteArray &type)
73 { 62 {
74 if (indexByType.contains(type)) {
75 return *indexByType.value(type);
76 }
77 auto index = QSharedPointer<TypeIndex>::create(type);
78 //TODO expand for all types
79 /* TypeHelper<type>::configureIndex(*index); */
80 // Try this: (T would i.e. become
81 // TypeHelper<ApplicationDomain::TypeImplementation>::T::configureIndex(*index);
82 if (type == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) { 63 if (type == ApplicationDomain::getTypeName<ApplicationDomain::Folder>()) {
83 ApplicationDomain::TypeImplementation<ApplicationDomain::Folder>::configure(*index); 64 ApplicationDomain::TypeImplementation<ApplicationDomain::Folder>::configure(std::forward<Args...>(args...));
84 } else if (type == ApplicationDomain::getTypeName<ApplicationDomain::Mail>()) { 65 } else if (type == ApplicationDomain::getTypeName<ApplicationDomain::Mail>()) {
85 ApplicationDomain::TypeImplementation<ApplicationDomain::Mail>::configure(*index); 66 ApplicationDomain::TypeImplementation<ApplicationDomain::Mail>::configure(std::forward<Args...>(args...));
86 } else if (type == ApplicationDomain::getTypeName<ApplicationDomain::Event>()) { 67 } else if (type == ApplicationDomain::getTypeName<ApplicationDomain::Event>()) {
87 ApplicationDomain::TypeImplementation<ApplicationDomain::Event>::configure(*index); 68 ApplicationDomain::TypeImplementation<ApplicationDomain::Event>::configure(std::forward<Args...>(args...));
88 } else { 69 } else {
89 Q_ASSERT(false); 70 Q_ASSERT(false);
90 SinkError() << "Unkonwn type " << type; 71 SinkError() << "Unkonwn type " << type;
91 } 72 }
73 }
74
75 TypeIndex &cachedIndex(const QByteArray &type)
76 {
77 if (indexByType.contains(type)) {
78 return *indexByType.value(type);
79 }
80 auto index = QSharedPointer<TypeIndex>::create(type);
81 configure(type, *index);
92 indexByType.insert(type, index); 82 indexByType.insert(type, index);
93 return *index; 83 return *index;
84
85 }
86
94 TypeIndex &typeIndex(const QByteArray &type) 87 TypeIndex &typeIndex(const QByteArray &type)
95 { 88 {
96 auto &index = cachedIndex(type); 89 auto &index = cachedIndex(type);
@@ -114,6 +107,7 @@ EntityStore::EntityStore(const ResourceContext &context)
114 107
115void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) 108void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode)
116{ 109{
110 SinkTrace() << "Starting transaction";
117 Sink::Storage::DataStore store(Sink::storageLocation(), d->resourceContext.instanceId(), accessMode); 111 Sink::Storage::DataStore store(Sink::storageLocation(), d->resourceContext.instanceId(), accessMode);
118 d->transaction = store.createTransaction(accessMode); 112 d->transaction = store.createTransaction(accessMode);
119 Q_ASSERT(d->transaction.validateNamedDatabases()); 113 Q_ASSERT(d->transaction.validateNamedDatabases());
@@ -173,7 +167,6 @@ bool EntityStore::add(const QByteArray &type, const ApplicationDomain::Applicati
173bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &preprocess) 167bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::ApplicationDomainType &diff, const QByteArrayList &deletions, bool replayToSource, const PreprocessModification &preprocess)
174{ 168{
175 auto changeset = diff.changedProperties(); 169 auto changeset = diff.changedProperties();
176 //TODO handle errors
177 const auto current = readLatest(type, diff.identifier()); 170 const auto current = readLatest(type, diff.identifier());
178 if (current.identifier().isEmpty()) { 171 if (current.identifier().isEmpty()) {
179 SinkWarning() << "Failed to read current version: " << diff.identifier(); 172 SinkWarning() << "Failed to read current version: " << diff.identifier();