Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3509643
D3082.id9365.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D3082.id9365.diff
View Options
diff --git a/services/backup/docker-server/contents/server/src/DatabaseManager.h b/services/backup/docker-server/contents/server/src/DatabaseManager.h
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/DatabaseManager.h
@@ -0,0 +1,61 @@
+#pragma once
+
+#include "AwsTools.h"
+#include "DatabaseEntitiesTools.h"
+
+#include <aws/core/Aws.h>
+#include <aws/dynamodb/model/AttributeDefinition.h>
+#include <aws/dynamodb/model/GetItemRequest.h>
+#include <aws/dynamodb/model/PutItemRequest.h>
+
+#include <memory>
+#include <string>
+
+#ifdef COMM_SERVICES_DEV_MODE
+#include "DatabaseSimulator.h"
+#endif
+
+namespace comm {
+namespace network {
+namespace database {
+
+// this class should be thread-safe in case any shared resources appear
+class DatabaseManager {
+#ifdef COMM_SERVICES_DEV_MODE
+ DatabaseSimulator dbSimulator;
+#endif
+
+ void innerPutItem(
+ std::shared_ptr<Item> item,
+ const Aws::DynamoDB::Model::PutItemRequest &request);
+
+ template <typename T>
+ std::shared_ptr<T>
+ innerFindItem(Aws::DynamoDB::Model::GetItemRequest &request);
+ void innerRemoveItem(const Item &item, const std::string &key);
+
+public:
+ static DatabaseManager &getInstance();
+};
+
+template <typename T>
+std::shared_ptr<T>
+DatabaseManager::innerFindItem(Aws::DynamoDB::Model::GetItemRequest &request) {
+ std::shared_ptr<T> item = createItemByType<T>();
+ request.SetTableName(item->getTableName());
+ const Aws::DynamoDB::Model::GetItemOutcome &outcome =
+ getDynamoDBClient()->GetItem(request);
+ if (!outcome.IsSuccess()) {
+ throw std::runtime_error(outcome.GetError().GetMessage());
+ }
+ const AttributeValues &outcomeItem = outcome.GetResult().GetItem();
+ if (!outcomeItem.size()) {
+ return nullptr;
+ }
+ item->assignItemFromDatabase(outcomeItem);
+ return std::move(item);
+}
+
+} // namespace database
+} // namespace network
+} // namespace comm
diff --git a/services/backup/docker-server/contents/server/src/DatabaseManager.cpp b/services/backup/docker-server/contents/server/src/DatabaseManager.cpp
new file mode 100644
--- /dev/null
+++ b/services/backup/docker-server/contents/server/src/DatabaseManager.cpp
@@ -0,0 +1,47 @@
+#include "DatabaseManager.h"
+#include "Constants.h"
+
+#include <aws/core/utils/Outcome.h>
+#include <aws/dynamodb/model/QueryRequest.h>
+#include <aws/dynamodb/model/ScanRequest.h>
+#include <aws/dynamodb/model/DeleteItemRequest.h>
+
+#include <iostream>
+
+namespace comm {
+namespace network {
+namespace database {
+
+DatabaseManager &DatabaseManager::getInstance() {
+ static DatabaseManager instance;
+ return instance;
+}
+
+void DatabaseManager::innerPutItem(
+ std::shared_ptr<Item> item,
+ const Aws::DynamoDB::Model::PutItemRequest &request) {
+ const Aws::DynamoDB::Model::PutItemOutcome outcome =
+ getDynamoDBClient()->PutItem(request);
+ if (!outcome.IsSuccess()) {
+ throw std::runtime_error(outcome.GetError().GetMessage());
+ }
+}
+
+void DatabaseManager::innerRemoveItem(
+ const Item &item,
+ const std::string &key) {
+ Aws::DynamoDB::Model::DeleteItemRequest request;
+ request.SetTableName(item.getTableName());
+ request.AddKey(
+ item.getPrimaryKey(), Aws::DynamoDB::Model::AttributeValue(key));
+
+ const Aws::DynamoDB::Model::DeleteItemOutcome &outcome =
+ getDynamoDBClient()->DeleteItem(request);
+ if (!outcome.IsSuccess()) {
+ throw std::runtime_error(outcome.GetError().GetMessage());
+ }
+}
+
+} // namespace database
+} // namespace network
+} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 22, 7:02 AM (5 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2688720
Default Alt Text
D3082.id9365.diff (3 KB)
Attached To
Mode
D3082: [services] Backup - add Database Manager base
Attached
Detach File
Event Timeline
Log In to Comment