diff options
Diffstat (limited to 'common/entitystore.h')
-rw-r--r-- | common/entitystore.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/common/entitystore.h b/common/entitystore.h index 17156ec..b6f8713 100644 --- a/common/entitystore.h +++ b/common/entitystore.h | |||
@@ -38,12 +38,28 @@ public: | |||
38 | auto typeName = ApplicationDomain::getTypeName<T>(); | 38 | auto typeName = ApplicationDomain::getTypeName<T>(); |
39 | auto mainDatabase = Storage::mainDatabase(mTransaction, typeName); | 39 | auto mainDatabase = Storage::mainDatabase(mTransaction, typeName); |
40 | auto bufferAdaptor = getLatest(mainDatabase, identifier, *Sink::AdaptorFactoryRegistry::instance().getFactory<T>(mResourceType)); | 40 | auto bufferAdaptor = getLatest(mainDatabase, identifier, *Sink::AdaptorFactoryRegistry::instance().getFactory<T>(mResourceType)); |
41 | Q_ASSERT(bufferAdaptor); | 41 | if (!bufferAdaptor) { |
42 | return T(); | ||
43 | } | ||
44 | return T(mResourceInstanceIdentifier, identifier, 0, bufferAdaptor); | ||
45 | } | ||
46 | |||
47 | template<typename T> | ||
48 | T readFromKey(const QByteArray &key) const | ||
49 | { | ||
50 | auto typeName = ApplicationDomain::getTypeName<T>(); | ||
51 | auto mainDatabase = Storage::mainDatabase(mTransaction, typeName); | ||
52 | auto bufferAdaptor = get(mainDatabase, key, *Sink::AdaptorFactoryRegistry::instance().getFactory<T>(mResourceType)); | ||
53 | const auto identifier = Storage::uidFromKey(key); | ||
54 | if (!bufferAdaptor) { | ||
55 | return T(); | ||
56 | } | ||
42 | return T(mResourceInstanceIdentifier, identifier, 0, bufferAdaptor); | 57 | return T(mResourceInstanceIdentifier, identifier, 0, bufferAdaptor); |
43 | } | 58 | } |
44 | 59 | ||
45 | 60 | ||
46 | static QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> getLatest(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory); | 61 | static QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> getLatest(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory); |
62 | static QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> get(const Sink::Storage::NamedDatabase &db, const QByteArray &key, DomainTypeAdaptorFactoryInterface &adaptorFactory); | ||
47 | private: | 63 | private: |
48 | QByteArray mResourceType; | 64 | QByteArray mResourceType; |
49 | QByteArray mResourceInstanceIdentifier; | 65 | QByteArray mResourceInstanceIdentifier; |