-
Notifications
You must be signed in to change notification settings - Fork 9
[#1177] Create new class AtomDBFactory #1220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
dfbf5eb
d297947
653c4bd
9e390d6
622d81c
f415feb
edd7624
0eaaa34
2a210e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #include "AtomDBFactory.h" | ||
|
|
||
| #include "InMemoryDB.h" | ||
| #include "MorkDB.h" | ||
| #include "RedisMongoDB.h" | ||
| #include "Utils.h" | ||
|
|
||
| using namespace atomdb; | ||
| using namespace commons; | ||
|
|
||
| // -------------------------------------------------------------------------------- | ||
| // Public methods | ||
|
|
||
| shared_ptr<AtomDB> AtomDBFactory::create(const JsonConfig& config, const string& context) { | ||
| return wrap_if_protected(create_backend(config, context)); | ||
| } | ||
|
|
||
| shared_ptr<AtomDB> AtomDBFactory::create_backend(const JsonConfig& config, const string& context) { | ||
| auto atomdb_type = config.at_path("type").get_or<string>(""); | ||
|
|
||
| if (atomdb_type == "redismongodb") { | ||
| return shared_ptr<AtomDB>(new RedisMongoDB(context, false, config)); | ||
| } | ||
| if (atomdb_type == "morkdb") { | ||
| return shared_ptr<AtomDB>(new MorkDB(context, config)); | ||
| } | ||
| if (atomdb_type == "inmemorydb") { | ||
| return make_shared<InMemoryDB>(context.empty() ? "inmemorydb_" : context); | ||
| } | ||
|
|
||
| RAISE_ERROR("AtomDBFactory: unsupported AtomDB type: " + atomdb_type); | ||
| return shared_ptr<AtomDB>{}; | ||
| } | ||
|
|
||
| shared_ptr<AtomDB> AtomDBFactory::wrap_if_protected(shared_ptr<AtomDB> backend) { | ||
| // AtomDBFactory::wrap_if_protected() is not implemented yet. | ||
| return backend; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "AtomDB.h" | ||
| #include "JsonConfig.h" | ||
|
|
||
| using namespace std; | ||
| using namespace commons; | ||
|
|
||
| namespace atomdb { | ||
|
|
||
| /** | ||
| * @brief Single entry point to construct concrete AtomDB backends. | ||
| * | ||
| * Use this instead of calling RedisMongoDB/MorkDB/InMemoryDB constructors directly. | ||
|
marcocapozzoli marked this conversation as resolved.
Outdated
|
||
| */ | ||
| class AtomDBFactory { | ||
| public: | ||
| /** | ||
| * @brief Creates a backend and wraps it with ProtectedAtomDB when is_protected(). | ||
| */ | ||
| static shared_ptr<AtomDB> create(const JsonConfig& config, const string& context = ""); | ||
|
|
||
| /** | ||
| * @brief Creates a concrete backend without authorization wrapping. | ||
| * | ||
| * Supported types: redismongodb, morkdb, inmemorydb. | ||
| */ | ||
| static shared_ptr<AtomDB> create_backend(const JsonConfig& config, const string& context = ""); | ||
|
|
||
| /** | ||
| * @brief Wraps backend with ProtectedAtomDB when protected and not already wrapped. | ||
| */ | ||
| static shared_ptr<AtomDB> wrap_if_protected(shared_ptr<AtomDB> backend); | ||
| }; | ||
|
|
||
| } // namespace atomdb | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,6 @@ enum MONGODB_FIELD { ID = 0, NAME, TARGETS, NAMED_TYPE, size }; | |
|
|
||
| class RedisMongoDB : public AtomDB { | ||
| public: | ||
| RedisMongoDB(const string& context, bool skip_redis, const JsonConfig& config); | ||
| ~RedisMongoDB(); | ||
|
|
||
| bool allow_nested_indexing() override; | ||
|
|
@@ -146,6 +145,11 @@ class RedisMongoDB : public AtomDB { | |
| map<string, vector<string>>& composite_type_entries_map); | ||
|
|
||
| private: | ||
| friend class AtomDBFactory; | ||
| friend class MorkDB; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does MorkDB need to be a friend class?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of this code snippet This causes a compilation error if it is not a friend class
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding MorkDB as a friend is the wrong fix. Make RedisMongo constructor |
||
|
|
||
| RedisMongoDB(const string& context, bool skip_redis, const JsonConfig& config); | ||
|
|
||
| string context; | ||
| bool skip_redis_; | ||
| bool composite_type_enabled_; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.