summaryrefslogtreecommitdiffstats
path: root/common/entitystore.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-16 14:55:20 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-21 09:02:21 +0200
commit237b9ae4113e7a9f489632296941becb71afdb45 (patch)
tree01cde58f495944f01cad9d282391d4efd2897141 /common/entitystore.h
parent95d11bf0be98a4e3c08502fe23417b800233ce14 (diff)
downloadsink-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/entitystore.h')
-rw-r--r--common/entitystore.h30
1 files changed, 11 insertions, 19 deletions
diff --git a/common/entitystore.h b/common/entitystore.h
index 6bfe414..3d9ca36 100644
--- a/common/entitystore.h
+++ b/common/entitystore.h
@@ -20,50 +20,42 @@
20#pragma once 20#pragma once
21 21
22#include "sink_export.h" 22#include "sink_export.h"
23#include <domainadaptor.h>
24 23
25#include "storage.h" 24#include "storage/entitystore.h"
26#include "adaptorfactoryregistry.h"
27#include "entityreader.h"
28 25
29namespace Sink { 26namespace Sink {
30 27
31class SINK_EXPORT EntityStore 28class SINK_EXPORT EntityStore
32{ 29{
33public: 30public:
34 EntityStore(const QByteArray &resourceType, const QByteArray &mResourceInstanceIdentifier, Sink::Storage::Transaction &transaction); 31 EntityStore(Storage::EntityStore &store);
35 32
36 template<typename T> 33 template<typename T>
37 T read(const QByteArray &identifier) const 34 T read(const QByteArray &identifier) const
38 { 35 {
39 EntityReader<T> reader(mResourceType, mResourceInstanceIdentifier, mTransaction); 36 return store.readLatest<T>(identifier);
40 return reader.read(identifier);
41 } 37 }
42 38
43 template<typename T> 39 template<typename T>
44 T readFromKey(const QByteArray &key) const 40 T readFromKey(const QByteArray &key) const
45 { 41 {
46 EntityReader<T> reader(mResourceType, mResourceInstanceIdentifier, mTransaction); 42 return store.readEntity<T>(key);
47 return reader.readFromKey(key);
48 } 43 }
49 44
50 template<typename T> 45 template<typename T>
51 T readPrevious(const QByteArray &uid, qint64 revision) const 46 T readPrevious(const QByteArray &uid, qint64 revision) const
52 { 47 {
53 EntityReader<T> reader(mResourceType, mResourceInstanceIdentifier, mTransaction); 48 return store.readPrevious<T>(uid, revision);
54 return reader.readPrevious(uid, revision);
55 } 49 }
56 50
57 template<typename T> 51 /* template<typename T> */
58 EntityReader<T> reader() 52 /* EntityReader<T> reader() */
59 { 53 /* { */
60 return EntityReader<T>(mResourceType, mResourceInstanceIdentifier, mTransaction); 54 /* return EntityReader<T>(mResourceType, mResourceInstanceIdentifier, mTransaction); */
61 } 55 /* } */
62 56
63private: 57private:
64 QByteArray mResourceType; 58 Sink::Storage::EntityStore &store;
65 QByteArray mResourceInstanceIdentifier;
66 Sink::Storage::Transaction &mTransaction;
67}; 59};
68 60
69} 61}