#pragma once #include "../context/init_context.inl" #include "../context/create_update_context.inl" #include "../context/read_context.inl" #include "../context/destroy_context.inl" #include "driver_impl/where.inl" #include "driver_impl/limit.inl" #include "driver_impl/order_by.inl" namespace cpphibernate { namespace mariadb { /* driver_impl_t */ template driver_impl_t::driver_impl_t(driver_t& p_owner, T_schema&& p_schema) : owner (p_owner) , schema(make_schema(std::forward(p_schema))) { } void driver_impl_t::init(bool recreate) const { auto * connection = owner.connection(); if (!connection) throw exception("Cpphibernate mariadb driver is not connected to any database!"); ::cppmariadb::transaction_lock trans(*connection); schema->init(init_context(*schema, *connection, recreate)); trans.commit(); } template void driver_impl_t::create(T_dataset& dataset) const { auto * connection = owner.connection(); if (!connection) throw exception("Cpphibernate mariadb driver is not connected to any database!"); create_update_impl_t::apply( create_update_context(*schema, *connection, dataset)); } template inline void driver_impl_t::read(T_dataset& dataset, const T_modifiers& modifiers) const { using dataset_type = mp::decay_t; using real_dataset_type = real_dataset_t; auto * connection = owner.connection(); if (!connection) throw exception("Cpphibernate mariadb driver is not connected to any database!"); auto dataset_id = get_type_id(hana::type_c); auto& table = schema->table(dataset_id); auto context = make_read_context(*schema, *connection, dataset, owner._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); ::cppmariadb::transaction_lock trans(*connection); table.read(context); trans.commit(); } template void driver_impl_t::update(T_dataset& dataset) const { auto * connection = owner.connection(); if (!connection) throw exception("Cpphibernate mariadb driver is not connected to any database!"); create_update_impl_t::apply( create_update_context(*schema, *connection, dataset, owner._filter)); } template void driver_impl_t::destroy(T_dataset& dataset) const { auto * connection = owner.connection(); if (!connection) throw exception("Cpphibernate mariadb driver is not connected to any database!"); destroy_impl_t::apply( destroy_context(*schema, *connection, dataset)); } } }