123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- #ifndef MYSQLX_DETAIL_SESSION_H
- #define MYSQLX_DETAIL_SESSION_H
- #include "../common.h"
- #include "../crud.h"
- #include <set>
- namespace cdk {
- class Session;
- }
- namespace mysqlx {
- class Value;
- class Session;
- class Schema;
- class Table;
- class Collection;
- namespace common {
- class Session_impl;
- class Session_pool;
- using Shared_session_pool = std::shared_ptr<Session_pool>;
- class Result_init;
- }
- namespace internal {
- class Schema_detail;
- using Client_impl = common::Session_pool;
- using Shared_client_impl = std::shared_ptr<Client_impl>;
- using Session_impl = common::Session_impl;
- using Shared_session_impl = std::shared_ptr<common::Session_impl>;
- class PUBLIC_API Db_obj_base
- {
- protected:
- DLL_WARNINGS_PUSH
- Shared_session_impl m_sess;
- string m_name;
- DLL_WARNINGS_POP
- Db_obj_base(const Shared_session_impl& sess, const string& name)
- : m_sess(sess), m_name(name)
- {}
- virtual ~Db_obj_base()
- {}
- };
- class PUBLIC_API Collection_detail
- : public Db_obj_base
- {
- protected:
- Collection_detail(const Shared_session_impl &sess, const string &name)
- : Db_obj_base(sess, name)
- {}
- virtual Schema_detail& get_schema() = 0;
- Result add_or_replace_one(const string &id, Value&&, bool);
- void index_drop(const string &name);
- void index_create(const string &name, Value &&spec);
- };
- struct PUBLIC_API Query_src
- {
- using Value = string;
- struct Res_impl;
- Res_impl *m_res = nullptr;
- const void *m_row = nullptr;
- public:
- Query_src()
- {}
- Query_src(Query_src &&other)
- : m_res(other.m_res)
- {
-
- other.m_res = nullptr;
- }
- Query_src(const Query_src&) = delete;
- virtual ~Query_src();
- virtual void iterator_start()
- {
- assert(m_res);
- }
- bool iterator_next();
- string iterator_get();
- };
- class PUBLIC_API Schema_detail
- : public Db_obj_base
- {
- protected:
- enum Obj_type { COLLECTION, TABLE };
-
- struct PUBLIC_API Name_src
- : public Query_src
- {
- const Schema &m_schema;
- Name_src(const Schema&, Obj_type, const string &pattern);
- };
- struct PUBLIC_API Collection_src
- : Name_src
- {
- using Value = Collection;
- Collection_src(const Schema &sch, const string &pattern)
- : Name_src(sch, COLLECTION, pattern)
- {}
- using Name_src::iterator_start;
- using Name_src::iterator_next;
- Collection iterator_get();
- };
- struct PUBLIC_API Table_src
- : Name_src
- {
- using Value = Table;
- Table_src(const Schema &sch, const string &pattern)
- : Name_src(sch, TABLE, pattern)
- {}
- using Name_src::iterator_start;
- using Name_src::iterator_next;
- Table iterator_get();
- };
- Schema_detail(const Shared_session_impl &sess, const string &name)
- : Db_obj_base(sess, name)
- {}
- public:
- using CollectionList = List_initializer<List_source<Collection_src>>;
- using TableList = List_initializer<List_source<Table_src>>;
- using StringList = List_initializer<List_source<Name_src>>;
- protected:
- void create_collection(const string &name, bool reuse);
- void drop_collection(const string &name);
- friend Collection_detail;
- struct Access;
- friend Access;
- };
- struct SQL_statement;
- using SQL_statement_cmd = Executable<SqlResult, SQL_statement>;
- struct SQL_statement
- : public Bind_placeholders< SQL_statement_cmd >
- {
- SQL_statement(Session *sess, const string &query)
- {
- assert(sess);
- try {
- reset(internal::Crud_factory::mk_sql(*sess, query));
- }
- CATCH_AND_WRAP
- }
- SQL_statement(SQL_statement_cmd &other)
- {
- SQL_statement_cmd::operator=(other);
- }
- SQL_statement(SQL_statement_cmd &&other)
- {
- SQL_statement_cmd::operator=(std::move(other));
- }
- };
- struct Session_detail;
- struct PUBLIC_API Client_detail
- {
-
- Client_detail(const Client_detail&) = delete;
- Client_detail& operator=(const Client_detail&) = delete;
- Client_detail(common::Settings_impl &settings);
- void close();
- protected:
- Client_detail(Client_detail && other)
- {
- m_impl = other.m_impl;
- other.m_impl.reset();
- }
- common::Shared_session_pool& get_session_pool();
- struct INTERNAL Impl;
- DLL_WARNINGS_PUSH
- Shared_client_impl m_impl = NULL;
- DLL_WARNINGS_POP
- friend Session;
- };
- struct PUBLIC_API Session_detail
- {
-
- Session_detail(const Session_detail&) = delete;
- Session_detail& operator=(const Session_detail&) = delete;
-
- struct PUBLIC_API Name_src
- : public Query_src
- {
- const Session &m_sess;
- Name_src(const Session&, const string &pattern);
- };
- struct PUBLIC_API Schema_src
- : Name_src
- {
- using Value = Schema;
- Schema_src(Session &sess, const string &pattern)
- : Name_src(sess, pattern)
- {}
- Schema_src(Session &sess)
- : Schema_src(sess, L"%")
- {}
- using Name_src::iterator_start;
- using Name_src::iterator_next;
- Schema iterator_get();
- };
- public:
- using SchemaList = List_initializer<List_source<Schema_src>>;
- protected:
- Session_detail(Session_detail && other)
- {
- m_impl = other.m_impl;
- other.m_impl.reset();
- }
- struct INTERNAL Impl;
-
- DLL_WARNINGS_PUSH
- Shared_session_impl m_impl = NULL;
- DLL_WARNINGS_POP
- Session_detail(common::Settings_impl&);
- Session_detail(common::Shared_session_pool&);
- virtual ~Session_detail()
- {
- try {
- if (m_impl)
- close();
- }
- catch (...) {}
- }
- void create_schema(const string &name, bool reuse);
- void drop_schema(const string &name);
- const std::wstring& get_default_schema_name();
- void start_transaction();
- void commit();
- void rollback(const string &sp = string());
- string savepoint_set(const string &sp = string());
- void savepoint_remove(const string&);
- common::Session_impl& get_impl()
- {
- if (!m_impl)
- THROW("Invalid session");
- return *m_impl;
- }
- INTERNAL cdk::Session& get_cdk_session();
- void close();
-
- void prepare_for_cmd();
- public:
-
- friend Result_detail::Impl;
- friend internal::Crud_factory;
-
- };
- }
- }
- #endif
|