diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.h b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.h --- a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.h +++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.h @@ -34,7 +34,7 @@ void assignItemFromDatabase(const AttributeValues &itemFromDB) override; std::string getTableName() const override; - std::string getPrimaryKey() const override; + PrimaryKey getPrimaryKey() const override; std::string getBlobHash() const; S3Path getS3Path() const; diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp --- a/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp +++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/BlobItem.cpp @@ -49,8 +49,8 @@ return BlobItem::tableName; } -std::string BlobItem::getPrimaryKey() const { - return BlobItem::FIELD_BLOB_HASH; +PrimaryKey BlobItem::getPrimaryKey() const { + return PrimaryKey(BlobItem::FIELD_BLOB_HASH); } std::string BlobItem::getBlobHash() const { diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/Item.h b/services/blob/docker-server/contents/server/src/DatabaseEntities/Item.h --- a/services/blob/docker-server/contents/server/src/DatabaseEntities/Item.h +++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/Item.h @@ -3,6 +3,7 @@ #include #include +#include #include namespace comm { @@ -12,12 +13,25 @@ typedef Aws::Map AttributeValues; +struct PrimaryKey { + PrimaryKey(const std::string partitionKey) + : partitionKey(partitionKey), sortKey(nullptr) { + } + PrimaryKey(const std::string partitionKey, const std::string sortKey) + : partitionKey(partitionKey), + sortKey(std::make_unique(sortKey)) { + } + + const std::string partitionKey; + std::unique_ptr sortKey; +}; + class Item { virtual void validate() const = 0; public: virtual std::string getTableName() const = 0; - virtual std::string getPrimaryKey() const = 0; + virtual PrimaryKey getPrimaryKey() const = 0; virtual void assignItemFromDatabase(const AttributeValues &itemFromDB) = 0; }; diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.h b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.h --- a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.h +++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.h @@ -28,7 +28,7 @@ void assignItemFromDatabase(const AttributeValues &itemFromDB) override; std::string getTableName() const override; - std::string getPrimaryKey() const override; + PrimaryKey getPrimaryKey() const override; std::string getHolder() const; std::string getBlobHash() const; }; diff --git a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp --- a/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp +++ b/services/blob/docker-server/contents/server/src/DatabaseEntities/ReverseIndexItem.cpp @@ -42,8 +42,8 @@ return ReverseIndexItem::tableName; } -std::string ReverseIndexItem::getPrimaryKey() const { - return ReverseIndexItem::FIELD_HOLDER; +PrimaryKey ReverseIndexItem::getPrimaryKey() const { + return PrimaryKey(ReverseIndexItem::FIELD_HOLDER); } std::string ReverseIndexItem::getHolder() const { diff --git a/services/blob/docker-server/contents/server/src/DatabaseManager.h b/services/blob/docker-server/contents/server/src/DatabaseManager.h --- a/services/blob/docker-server/contents/server/src/DatabaseManager.h +++ b/services/blob/docker-server/contents/server/src/DatabaseManager.h @@ -35,7 +35,7 @@ template std::shared_ptr innerFindItem(Aws::DynamoDB::Model::GetItemRequest &request); - void innerRemoveItem(const Item &item, const std::string &key); + void innerRemoveItem(const Item &item, const PrimaryKey primaryKeyValue); public: static DatabaseManager &getInstance(); diff --git a/services/blob/docker-server/contents/server/src/DatabaseManager.cpp b/services/blob/docker-server/contents/server/src/DatabaseManager.cpp --- a/services/blob/docker-server/contents/server/src/DatabaseManager.cpp +++ b/services/blob/docker-server/contents/server/src/DatabaseManager.cpp @@ -29,11 +29,18 @@ void DatabaseManager::innerRemoveItem( const Item &item, - const std::string &key) { + const PrimaryKey primaryKeyValue) { Aws::DynamoDB::Model::DeleteItemRequest request; request.SetTableName(item.getTableName()); + PrimaryKey pk = item.getPrimaryKey(); request.AddKey( - item.getPrimaryKey(), Aws::DynamoDB::Model::AttributeValue(key)); + pk.partitionKey, + Aws::DynamoDB::Model::AttributeValue(primaryKeyValue.partitionKey)); + if (pk.sortKey != nullptr && primaryKeyValue.sortKey != nullptr) { + request.AddKey( + *pk.sortKey, + Aws::DynamoDB::Model::AttributeValue(*primaryKeyValue.sortKey)); + } const Aws::DynamoDB::Model::DeleteItemOutcome &outcome = getDynamoDBClient()->DeleteItem(request); @@ -69,7 +76,7 @@ } void DatabaseManager::removeBlobItem(const std::string &blobHash) { - this->innerRemoveItem(*(createItemByType()), blobHash); + this->innerRemoveItem(*(createItemByType()), PrimaryKey(blobHash)); } void DatabaseManager::putReverseIndexItem(const ReverseIndexItem &item) { @@ -133,7 +140,7 @@ if (item == nullptr) { return false; } - this->innerRemoveItem(*item, item->getHolder()); + this->innerRemoveItem(*item, PrimaryKey(item->getHolder())); return true; }