diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-16 14:55:20 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-21 09:02:21 +0200 |
commit | 237b9ae4113e7a9f489632296941becb71afdb45 (patch) | |
tree | 01cde58f495944f01cad9d282391d4efd2897141 /common/typeindex.cpp | |
parent | 95d11bf0be98a4e3c08502fe23417b800233ce14 (diff) | |
download | sink-237b9ae4113e7a9f489632296941becb71afdb45.tar.gz sink-237b9ae4113e7a9f489632296941becb71afdb45.zip |
Refactor how the storage is used.
This is the initial refactoring to improve how we deal with the storage.
It does a couple of things:
* Rename Sink::Storage to Sink::Storage::DataStore to free up the
Sink::Storage namespace
* Introduce a Sink::ResourceContext to have a single object that can be
passed around containing everything that is necessary to operate on a
resource. This is a lot better than the multiple separate parameters
that we used to pass around all over the place, while still allowing
for dependency injection for tests.
* Tie storage access together using the new EntityStore that directly
works with ApplicationDomainTypes. This gives us a central place where
main storage, indexes and buffer adaptors are tied together, which
will also give us a place to implement external indexes, such as a
fulltextindex using xapian.
* Use ApplicationDomainTypes as the default way to pass around entities.
Instead of using various ways to pass around entities (buffers,
buffer adaptors, ApplicationDomainTypes), only use a single way.
The old approach was confusing, and was only done as:
* optimization; really shouldn't be necessary and otherwise I'm sure
we can find better ways to optimize ApplicationDomainType itself.
* a way to account for entities that have multiple buffers, a concept
that I no longer deem relevant.
While this commit does the bulk of the work to get there, the following
commits will refactor more stuff to get things back to normal.
Diffstat (limited to 'common/typeindex.cpp')
-rw-r--r-- | common/typeindex.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/common/typeindex.cpp b/common/typeindex.cpp index 816e7ee..64c2a01 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp | |||
@@ -66,7 +66,7 @@ QByteArray TypeIndex::indexName(const QByteArray &property, const QByteArray &so | |||
66 | template <> | 66 | template <> |
67 | void TypeIndex::addProperty<QByteArray>(const QByteArray &property) | 67 | void TypeIndex::addProperty<QByteArray>(const QByteArray &property) |
68 | { | 68 | { |
69 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { | 69 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { |
70 | // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray(); | 70 | // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray(); |
71 | Index(indexName(property), transaction).add(getByteArray(value), identifier); | 71 | Index(indexName(property), transaction).add(getByteArray(value), identifier); |
72 | }; | 72 | }; |
@@ -77,7 +77,7 @@ void TypeIndex::addProperty<QByteArray>(const QByteArray &property) | |||
77 | template <> | 77 | template <> |
78 | void TypeIndex::addProperty<QString>(const QByteArray &property) | 78 | void TypeIndex::addProperty<QString>(const QByteArray &property) |
79 | { | 79 | { |
80 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { | 80 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { |
81 | // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray(); | 81 | // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray(); |
82 | Index(indexName(property), transaction).add(getByteArray(value), identifier); | 82 | Index(indexName(property), transaction).add(getByteArray(value), identifier); |
83 | }; | 83 | }; |
@@ -88,7 +88,7 @@ void TypeIndex::addProperty<QString>(const QByteArray &property) | |||
88 | template <> | 88 | template <> |
89 | void TypeIndex::addProperty<QDateTime>(const QByteArray &property) | 89 | void TypeIndex::addProperty<QDateTime>(const QByteArray &property) |
90 | { | 90 | { |
91 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::Transaction &transaction) { | 91 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { |
92 | //SinkTrace() << "Indexing " << mType + ".index." + property << getByteArray(value); | 92 | //SinkTrace() << "Indexing " << mType + ".index." + property << getByteArray(value); |
93 | Index(indexName(property), transaction).add(getByteArray(value), identifier); | 93 | Index(indexName(property), transaction).add(getByteArray(value), identifier); |
94 | }; | 94 | }; |
@@ -99,7 +99,7 @@ void TypeIndex::addProperty<QDateTime>(const QByteArray &property) | |||
99 | template <> | 99 | template <> |
100 | void TypeIndex::addPropertyWithSorting<QByteArray, QDateTime>(const QByteArray &property, const QByteArray &sortProperty) | 100 | void TypeIndex::addPropertyWithSorting<QByteArray, QDateTime>(const QByteArray &property, const QByteArray &sortProperty) |
101 | { | 101 | { |
102 | auto indexer = [=](const QByteArray &identifier, const QVariant &value, const QVariant &sortValue, Sink::Storage::Transaction &transaction) { | 102 | auto indexer = [=](const QByteArray &identifier, const QVariant &value, const QVariant &sortValue, Sink::Storage::DataStore::Transaction &transaction) { |
103 | const auto date = sortValue.toDateTime(); | 103 | const auto date = sortValue.toDateTime(); |
104 | const auto propertyValue = getByteArray(value); | 104 | const auto propertyValue = getByteArray(value); |
105 | Index(indexName(property, sortProperty), transaction).add(propertyValue + toSortableByteArray(date), identifier); | 105 | Index(indexName(property, sortProperty), transaction).add(propertyValue + toSortableByteArray(date), identifier); |
@@ -108,7 +108,7 @@ void TypeIndex::addPropertyWithSorting<QByteArray, QDateTime>(const QByteArray & | |||
108 | mSortedProperties.insert(property, sortProperty); | 108 | mSortedProperties.insert(property, sortProperty); |
109 | } | 109 | } |
110 | 110 | ||
111 | void TypeIndex::add(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) | 111 | void TypeIndex::add(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction) |
112 | { | 112 | { |
113 | for (const auto &property : mProperties) { | 113 | for (const auto &property : mProperties) { |
114 | const auto value = bufferAdaptor.getProperty(property); | 114 | const auto value = bufferAdaptor.getProperty(property); |
@@ -123,7 +123,7 @@ void TypeIndex::add(const QByteArray &identifier, const Sink::ApplicationDomain: | |||
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | void TypeIndex::remove(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) | 126 | void TypeIndex::remove(const QByteArray &identifier, const Sink::ApplicationDomain::BufferAdaptor &bufferAdaptor, Sink::Storage::DataStore::Transaction &transaction) |
127 | { | 127 | { |
128 | for (const auto &property : mProperties) { | 128 | for (const auto &property : mProperties) { |
129 | const auto value = bufferAdaptor.getProperty(property); | 129 | const auto value = bufferAdaptor.getProperty(property); |
@@ -159,7 +159,7 @@ static QVector<QByteArray> indexLookup(Index &index, Query::Comparator filter) | |||
159 | return keys; | 159 | return keys; |
160 | } | 160 | } |
161 | 161 | ||
162 | QVector<QByteArray> TypeIndex::query(const Sink::Query &query, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting, Sink::Storage::Transaction &transaction) | 162 | QVector<QByteArray> TypeIndex::query(const Sink::Query &query, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting, Sink::Storage::DataStore::Transaction &transaction) |
163 | { | 163 | { |
164 | QVector<QByteArray> keys; | 164 | QVector<QByteArray> keys; |
165 | for (auto it = mSortedProperties.constBegin(); it != mSortedProperties.constEnd(); it++) { | 165 | for (auto it = mSortedProperties.constBegin(); it != mSortedProperties.constEnd(); it++) { |
@@ -185,7 +185,7 @@ QVector<QByteArray> TypeIndex::query(const Sink::Query &query, QSet<QByteArray> | |||
185 | return keys; | 185 | return keys; |
186 | } | 186 | } |
187 | 187 | ||
188 | QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant &value, Sink::Storage::Transaction &transaction) | 188 | QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) |
189 | { | 189 | { |
190 | SinkTrace() << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties; | 190 | SinkTrace() << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties; |
191 | if (mProperties.contains(property)) { | 191 | if (mProperties.contains(property)) { |
@@ -218,19 +218,19 @@ QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant | |||
218 | } | 218 | } |
219 | 219 | ||
220 | template <> | 220 | template <> |
221 | void TypeIndex::index<QByteArray, QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::Transaction &transaction) | 221 | void TypeIndex::index<QByteArray, QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction) |
222 | { | 222 | { |
223 | Index(indexName(leftName + rightName), transaction).add(getByteArray(leftValue), getByteArray(rightValue)); | 223 | Index(indexName(leftName + rightName), transaction).add(getByteArray(leftValue), getByteArray(rightValue)); |
224 | } | 224 | } |
225 | 225 | ||
226 | template <> | 226 | template <> |
227 | void TypeIndex::index<QString, QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::Transaction &transaction) | 227 | void TypeIndex::index<QString, QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &leftValue, const QVariant &rightValue, Sink::Storage::DataStore::Transaction &transaction) |
228 | { | 228 | { |
229 | Index(indexName(leftName + rightName), transaction).add(getByteArray(leftValue), getByteArray(rightValue)); | 229 | Index(indexName(leftName + rightName), transaction).add(getByteArray(leftValue), getByteArray(rightValue)); |
230 | } | 230 | } |
231 | 231 | ||
232 | template <> | 232 | template <> |
233 | QVector<QByteArray> TypeIndex::secondaryLookup<QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value, Sink::Storage::Transaction &transaction) | 233 | QVector<QByteArray> TypeIndex::secondaryLookup<QByteArray>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) |
234 | { | 234 | { |
235 | QVector<QByteArray> keys; | 235 | QVector<QByteArray> keys; |
236 | Index index(indexName(leftName + rightName), transaction); | 236 | Index index(indexName(leftName + rightName), transaction); |
@@ -242,7 +242,7 @@ QVector<QByteArray> TypeIndex::secondaryLookup<QByteArray>(const QByteArray &lef | |||
242 | } | 242 | } |
243 | 243 | ||
244 | template <> | 244 | template <> |
245 | QVector<QByteArray> TypeIndex::secondaryLookup<QString>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value, Sink::Storage::Transaction &transaction) | 245 | QVector<QByteArray> TypeIndex::secondaryLookup<QString>(const QByteArray &leftName, const QByteArray &rightName, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) |
246 | { | 246 | { |
247 | QVector<QByteArray> keys; | 247 | QVector<QByteArray> keys; |
248 | Index index(indexName(leftName + rightName), transaction); | 248 | Index index(indexName(leftName + rightName), transaction); |