diff --git a/demo/work.cpp b/demo/work.cpp index 857758b..46f33dd 100644 --- a/demo/work.cpp +++ b/demo/work.cpp @@ -10,6 +10,12 @@ #include "work/admin/UserDirectory.hpp" #include "work/admin/UserSession.hpp" +#include "work/jobs/Job.hpp" +#include "work/jobs/Task.hpp"" +#include "work/jobs/Payload.hpp" +#include "work/jobs/IdPayload.hpp" +#include "work/jobs/IdListPayload.hpp" + #include "matador/object/schema.hpp" #include "matador/sql/connection.hpp" @@ -20,7 +26,7 @@ using namespace matador; using namespace work::models; int main() { - object::schema schema; + object::schema schema("Administration"); auto result = schema.attach("collection_center") .and_then([&schema] { return schema.attach("internal_user_directory"); }) @@ -32,7 +38,12 @@ int main() { .and_then([&schema] { return schema.attach("scenario"); }) .and_then([&schema] { return schema.attach("user"); }) .and_then([&schema] { return schema.attach("user_directory"); }) - .and_then([&schema] { return schema.attach("user_session"); }); + .and_then([&schema] { return schema.attach("user_session"); }) + .and_then([&schema] { return schema.attach("jobs"); }) + .and_then([&schema] { return schema.attach("id_payloads"); }) + .and_then([&schema] { return schema.attach("id_list_payloads"); }) + .and_then([&schema] { return schema.attach("payloads"); }) + .and_then([&schema] { return schema.attach("tasks"); }); if (!result.is_ok()) { return 0; @@ -51,3 +62,8 @@ int main() { return 0; } + +// registering table 'collection_center' (pk field: 'id') +// registering relation table 'collection_center_users' (first fk field: 'collection_center_id', second fk field: 'user_id') +// registering table 'internal_user_directory' (pk field: 'id') +// \ No newline at end of file diff --git a/demo/work/admin/CollectionCenter.hpp b/demo/work/admin/CollectionCenter.hpp index f2d6522..84d5f2a 100644 --- a/demo/work/admin/CollectionCenter.hpp +++ b/demo/work/admin/CollectionCenter.hpp @@ -38,7 +38,7 @@ struct CollectionCenter : core::Model { field::attribute( op, "name", name, 511 ); field::attribute( op, "symbol", symbol ); field::attribute( op, "type", type ); - field::has_many( op, "users", users, "collection_center_id", matador::utils::fetch_type::LAZY ); + field::has_many( op, "collection_center_users", users, "collection_center_id", matador::utils::fetch_type::LAZY ); } }; diff --git a/demo/work/core/UserInfo.hpp b/demo/work/core/UserInfo.hpp new file mode 100644 index 0000000..bf49bdb --- /dev/null +++ b/demo/work/core/UserInfo.hpp @@ -0,0 +1,22 @@ +#ifndef USERINFO_HPP +#define USERINFO_HPP + +#include "matador/utils/access.hpp" + +namespace work::core { +struct UserInfo { + unsigned long long user_session_id; + std::string user_role; + std::string database_name; + + template + void process( Operator& op ) { + namespace field = matador::access; + field::attribute( op, "user_session_id", user_session_id ); + field::attribute( op, "user_role", user_role, 255 ); + field::attribute( op, "database_name", database_name, 255 ); + } +}; +} + +#endif //USERINFO_HPP diff --git a/demo/work/jobs/IdListPayload.hpp b/demo/work/jobs/IdListPayload.hpp new file mode 100644 index 0000000..ff75438 --- /dev/null +++ b/demo/work/jobs/IdListPayload.hpp @@ -0,0 +1,20 @@ +#ifndef ID_LIST_PAYLOAD_HPP +#define ID_LIST_PAYLOAD_HPP + +#include "Payload.hpp" + +#include "matador/object/collection.hpp" + +namespace work::models::jobs { +struct IdListPayload : Payload { + matador::object::collection ids; + template + void process( Operator& op ) { + namespace field = matador::access; + field::process( op, *matador::base_class( this ) ); + field::has_many( op, "payload_ids", ids ); + } +}; +} + +#endif //ID_LIST_PAYLOAD_HPP diff --git a/demo/work/jobs/IdPayload.hpp b/demo/work/jobs/IdPayload.hpp new file mode 100644 index 0000000..2470840 --- /dev/null +++ b/demo/work/jobs/IdPayload.hpp @@ -0,0 +1,18 @@ +#ifndef ID_PAYLOAD_HPP +#define ID_PAYLOAD_HPP + +#include "Payload.hpp" + +namespace work::models::jobs { +struct IdPayload : Payload { + unsigned long long id; + template + void process( Operator& op ) { + namespace field = matador::access; + field::process( op, *matador::base_class( this ) ); + field::attribute( op, "id", id ); + } +}; +} + +#endif //ID_PAYLOAD_HPP diff --git a/demo/work/jobs/Job.hpp b/demo/work/jobs/Job.hpp new file mode 100644 index 0000000..1e350ab --- /dev/null +++ b/demo/work/jobs/Job.hpp @@ -0,0 +1,46 @@ +#ifndef JOB_HPP +#define JOB_HPP + +#include "JobMode.hpp" +#include "JobState.hpp" +#include "Payload.hpp" +#include "Task.hpp" + +#include "../core/Model.hpp" +#include "../core/Types.hpp" +#include "../core/UserInfo.hpp" + +#include "matador/object/object_ptr.hpp" + +#include "matador/utils/base_class.hpp" + +namespace work::models::jobs { + +struct Job : core::Model { + std::string name; + std::string description; + JobState state; + JobMode mode; + core::timestamp created_at; + matador::object::object_ptr payload; + matador::object::object_ptr task; + core::UserInfo user_info; + + template + void process( Operator& op ) { + namespace field = matador::access; + field::process( op, *matador::base_class( this ) ); + field::attribute( op, "name", name, 511 ); + field::attribute( op, "description", description, 511 ); + field::attribute( op, "state", state ); + field::attribute( op, "mode", mode ); + field::attribute( op, "created_at", created_at ); + field::belongs_to( op, "payload", payload, matador::utils::default_foreign_attributes ); + field::belongs_to( op, "task", task, matador::utils::default_foreign_attributes ); + field::attribute( op, "user_info", user_info ); + } +}; + +} + +#endif //JOB_HPP diff --git a/demo/work/jobs/JobMode.hpp b/demo/work/jobs/JobMode.hpp new file mode 100644 index 0000000..11a9e02 --- /dev/null +++ b/demo/work/jobs/JobMode.hpp @@ -0,0 +1,20 @@ +#ifndef JOB_MODE_HPP +#define JOB_MODE_HPP + +#include "matador/utils/enum_mapper.hpp" + +#include + +namespace work::models::jobs { +enum class JobMode : uint8_t { + Background, + Foreground +}; + +static const matador::utils::enum_mapper JobModeEnum({ + {JobMode::Background, "Background"}, + {JobMode::Foreground, "Foreground"} +}); +} + +#endif //JOB_MODE_HPP diff --git a/demo/work/jobs/JobState.hpp b/demo/work/jobs/JobState.hpp new file mode 100644 index 0000000..98b0597 --- /dev/null +++ b/demo/work/jobs/JobState.hpp @@ -0,0 +1,28 @@ +#ifndef JOB_STATE_HPP +#define JOB_STATE_HPP + +#include "matador/utils/enum_mapper.hpp" + +#include + +namespace work::models::jobs { +enum class JobState : uint8_t { + Pending, + Running, + Succeeded, + Failed, + Cancelled +}; + +static const matador::utils::enum_mapper JobStateEnum({ + {JobState::Pending, "Pending"}, + {JobState::Running, "Running"}, + {JobState::Succeeded, "Succeeded"}, + {JobState::Failed, "Failed"}, + {JobState::Cancelled, "Cancelled"} +}); + +} + + +#endif //JOB_STATE_HPP diff --git a/demo/work/jobs/Payload.hpp b/demo/work/jobs/Payload.hpp new file mode 100644 index 0000000..4c32b0d --- /dev/null +++ b/demo/work/jobs/Payload.hpp @@ -0,0 +1,20 @@ +#ifndef PAYLOAD_HPP +#define PAYLOAD_HPP + +#include "../core/Model.hpp" + +#include "matador/utils/base_class.hpp" + +namespace work::models::jobs { +struct Payload : core::Model { + std::string type; + template + void process( Operator& op ) { + namespace field = matador::access; + field::process( op, *matador::base_class( this ) ); + field::attribute( op, "type", type, 255 ); + } +}; +} + +#endif //PAYLOAD_HPP diff --git a/demo/work/jobs/Task.hpp b/demo/work/jobs/Task.hpp new file mode 100644 index 0000000..dc3c75c --- /dev/null +++ b/demo/work/jobs/Task.hpp @@ -0,0 +1,42 @@ +#ifndef TASK_HPP +#define TASK_HPP + +#include "TaskState.hpp" + +#include "../core/Model.hpp" +#include "../core/Types.hpp" + +#include "matador/object/object_ptr.hpp" + +#include "matador/utils/base_class.hpp" + +namespace work::models::jobs { +struct Task : core::Model { + std::string name; + std::string description; + std::string job_name; + TaskState state; + matador::object::object_ptr payload; + JobMode job_mode; + core::timestamp start_delay; + core::timestamp interval; + unsigned long long user_session_id; + + template + void process( Operator& op ) { + namespace field = matador::access; + field::process( op, *matador::base_class( this ) ); + field::attribute( op, "name", name, 511 ); + field::attribute( op, "description", description, 511 ); + field::attribute( op, "job_name", job_name, 511 ); + field::attribute( op, "state", state ); + field::belongs_to( op, "payload", payload, matador::utils::default_foreign_attributes ); + field::attribute( op, "job_mode", job_mode ); + field::attribute( op, "start_delay", start_delay ); + field::attribute( op, "interval", interval ); + field::attribute( op, "user_session_id", user_session_id ); + } +}; +} + +#endif //TASK_HPP diff --git a/demo/work/jobs/TaskState.hpp b/demo/work/jobs/TaskState.hpp new file mode 100644 index 0000000..b221b2b --- /dev/null +++ b/demo/work/jobs/TaskState.hpp @@ -0,0 +1,22 @@ +#ifndef TASK_STATE_HPP +#define TASK_STATE_HPP + +#include "matador/utils/enum_mapper.hpp" + +#include + +namespace work::models::jobs { +enum class TaskState : uint8_t { + Active, + Inactive +}; + +static const matador::utils::enum_mapper TaskStateEnum({ + {TaskState::Active, "Active"}, + {TaskState::Inactive, "Inactive"} +}); + +} + + +#endif //TASK_STATE_HPP diff --git a/include/matador/object/schema.hpp b/include/matador/object/schema.hpp index f324b22..c2827c4 100644 --- a/include/matador/object/schema.hpp +++ b/include/matador/object/schema.hpp @@ -1,7 +1,7 @@ #ifndef SCHEMA_HPP #define SCHEMA_HPP -#include "primary_key_resolver.hpp" +#include "matador/object/primary_key_resolver.hpp" #include "matador/object/error_code.hpp" #include "matador/object/schema_node.hpp" #include "matador/object/schema_node_iterator.hpp" diff --git a/include/matador/utils/thread_pool.hpp b/include/matador/utils/thread_pool.hpp new file mode 100644 index 0000000..e69de29 diff --git a/source/core/utils/thread_pool.cpp b/source/core/utils/thread_pool.cpp new file mode 100644 index 0000000..e69de29 diff --git a/test/core/utils/ThreadPoolTest.cpp b/test/core/utils/ThreadPoolTest.cpp new file mode 100644 index 0000000..e69de29