#pragma once #include #include #include #include #include beg_namespace_cpphibernate_driver_mariadb { /* destroy_impl_t */ template struct destroy_impl_t { using dataset_type = T_dataset; static inline void apply(const destroy_context& context, bool strict = true) { auto dataset_id = misc::get_type_id(hana::type_c); auto& connection = context.connection; auto& schema = context.schema; auto& table = schema.table(dataset_id); assert(table.primary_key_field); transaction_lock trans(connection); if (!table.primary_key_field->is_default(context)) { table.destroy(context); } else if (strict) { throw misc::hibernate_exception("can not destroy dataset with no primary key assigned!"); } trans.commit(); } }; /* destroy_impl_t - nullable */ template struct destroy_impl_t< T_dataset, mp::enable_if>> { using dataset_type = T_dataset; using nullable_helper_type = misc::nullable_helper; static inline void apply(const destroy_context& context, bool strict = true) { auto& dataset = context.get(); auto* value = nullable_helper_type::get(dataset); if (value) { using new_dataset_type = mp::decay_t; using new_destroy_impl_type = destroy_impl_t; auto new_context = change_context(context, *value); new_destroy_impl_type::apply(new_context, strict); } else if (strict) { throw misc::hibernate_exception("can not destroy nullable type with no value!"); } } }; /* destroy_impl_t - container */ template struct destroy_impl_t< T_dataset, mp::enable_if>> { using dataset_type = T_dataset; static inline void apply(const destroy_context& context, bool strict = true) { auto& connection = context.connection; auto& dataset = context.get(); transaction_lock trans(connection); for (auto& x : dataset) { using new_dataset_type = mp::decay_t; using new_destroy_impl_type = destroy_impl_t; auto new_context = change_context(context, x); new_destroy_impl_type::apply(new_context, strict); } trans.commit(); } }; } end_namespace_cpphibernate_driver_mariadb