Przeglądaj źródła

* change connection of mariadb driver

master
bergmann 7 lat temu
rodzic
commit
b375aaa067
1 zmienionych plików z 16 dodań i 13 usunięć
  1. +16
    -13
      include/cpphibernate/driver/mariadb/mariadb.h

+ 16
- 13
include/cpphibernate/driver/mariadb/mariadb.h Wyświetl plik

@@ -12,14 +12,14 @@ beg_namespace_cpphibernate_driver_mariadb
struct mariadb_driver_t struct mariadb_driver_t
{ {
private: private:
::cppmariadb::connection& _connection;
::cppmariadb::connection* _connection;
schema_t _schema; schema_t _schema;
filter_t _filter; filter_t _filter;


public: public:
template<typename T_schema> template<typename T_schema>
mariadb_driver_t(T_schema&& p_schema, ::cppmariadb::connection& p_connection) mariadb_driver_t(T_schema&& p_schema, ::cppmariadb::connection& p_connection)
: _connection (p_connection)
: _connection (&p_connection)
, _schema (make_schema(std::forward<T_schema>(p_schema))) , _schema (make_schema(std::forward<T_schema>(p_schema)))
{ } { }


@@ -27,7 +27,10 @@ beg_namespace_cpphibernate_driver_mariadb
cpphibernate_moveable(mariadb_driver_t, default); cpphibernate_moveable(mariadb_driver_t, default);


inline const ::cppmariadb::connection& connection() const inline const ::cppmariadb::connection& connection() const
{ return _connection; }
{ return *_connection; }

inline void connection(::cppmariadb::connection& p_connection)
{ _connection = &p_connection; }


template<typename... T_args> template<typename... T_args>
inline void set_filter_inclusive(T_args&&... args) inline void set_filter_inclusive(T_args&&... args)
@@ -43,8 +46,8 @@ beg_namespace_cpphibernate_driver_mariadb
protected: protected:
inline void init_impl(bool recreate) const inline void init_impl(bool recreate) const
{ {
transaction_lock trans(_connection);
_schema.init(init_context(_schema, _connection, recreate));
transaction_lock trans(*_connection);
_schema.init(init_context(_schema, *_connection, recreate));
trans.commit(); trans.commit();
} }


@@ -52,7 +55,7 @@ beg_namespace_cpphibernate_driver_mariadb
inline void create_impl(T_dataset& dataset) const inline void create_impl(T_dataset& dataset) const
{ {
create_update_impl_t<T_dataset>::apply( create_update_impl_t<T_dataset>::apply(
create_update_context(dataset, _schema, _connection, _filter, false));
create_update_context(dataset, _schema, *_connection, _filter, false));
} }


template<typename T_dataset, typename T_modifiers> template<typename T_dataset, typename T_modifiers>
@@ -63,12 +66,12 @@ beg_namespace_cpphibernate_driver_mariadb


auto dataset_id = misc::get_type_id(hana::type_c<real_dataset_type>); auto dataset_id = misc::get_type_id(hana::type_c<real_dataset_type>);
auto& table = _schema.table(dataset_id); auto& table = _schema.table(dataset_id);
auto context = make_read_context(dataset, _schema, _connection, _filter);
context.where = build_where(_schema, modifiers).query(_connection);
context.limit = build_limit(modifiers).query(_connection);
context.order_by = build_order_by(_schema, modifiers).query(_connection);
auto context = make_read_context(dataset, _schema, *_connection, _filter);
context.where = build_where(_schema, modifiers).query(*_connection);
context.limit = build_limit(modifiers).query(*_connection);
context.order_by = build_order_by(_schema, modifiers).query(*_connection);


transaction_lock trans(_connection);
transaction_lock trans(*_connection);
table.read(context); table.read(context);
trans.commit(); trans.commit();
} }
@@ -77,7 +80,7 @@ beg_namespace_cpphibernate_driver_mariadb
inline void update_impl(T_dataset& dataset) const inline void update_impl(T_dataset& dataset) const
{ {
create_update_impl_t<T_dataset>::apply( create_update_impl_t<T_dataset>::apply(
create_update_context(dataset, _schema, _connection, _filter, true));
create_update_context(dataset, _schema, *_connection, _filter, true));
} }


template<typename T_dataset> template<typename T_dataset>
@@ -89,7 +92,7 @@ beg_namespace_cpphibernate_driver_mariadb
auto dataset_id = misc::get_type_id(hana::type_c<real_dataset_type>); auto dataset_id = misc::get_type_id(hana::type_c<real_dataset_type>);
auto& table = _schema.table(dataset_id); auto& table = _schema.table(dataset_id);


destroy_context context(dataset, _schema, _connection);
destroy_context context(dataset, _schema, *_connection);
context.where = table.get_where_primary_key(context); context.where = table.get_where_primary_key(context);


destroy_impl_t<T_dataset>::apply(context); destroy_impl_t<T_dataset>::apply(context);


Ładowanie…
Anuluj
Zapisz