diff options
Diffstat (limited to 'src/DatabaseStorage.cpp')
-rw-r--r-- | src/DatabaseStorage.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp new file mode 100644 index 0000000..2028c63 --- /dev/null +++ b/src/DatabaseStorage.cpp @@ -0,0 +1,35 @@ +#include "../include/DatabaseStorage.hpp" + +using namespace std; + +namespace odhtdb +{ + void DatabaseStorage::createStorage(const Key &key, vector<Group*> &&groups, u64 timestamp) + { + if(storageMap.find(key) != storageMap.end()) + { + string errMsg = "Database storage with key "; + errMsg += key.hashedKey.toString(); + errMsg += " already exists"; + throw DatabaseStorageAlreadyExists(errMsg); + } + + DatabaseStorageObjectList *databaseStorageObjectList = new DatabaseStorageObjectList(); + databaseStorageObjectList->timestamp = timestamp; + databaseStorageObjectList->groups = move(groups); + storageMap[key] = databaseStorageObjectList; + } + + void DatabaseStorage::appendStorage(const Key &key, DataView &data, u64 timestamp, const Signature::PublicKey &creatorPublicKey) + { + auto it = storageMap.find(key); + if(it == storageMap.end()) + { + string errMsg = "Database storage with key "; + errMsg += key.hashedKey.toString(); + errMsg += " not found"; + throw DatabaseStorageNotFound(errMsg); + } + it->second->objects.push_back({data, timestamp, creatorPublicKey}); + } +} |