/* * Copyright 2015 Cloudius Systems */ #pragma once #include #include "core/sharded.hh" #include "core/future.hh" #include "cql3/query_processor.hh" class database; namespace service { class storage_proxy; } namespace db { struct query_context { distributed& _db; distributed& _qp; query_context(distributed& db, distributed& qp) : _db(db), _qp(qp) {} template future<::shared_ptr> execute_cql(sstring text, sstring cf, Args&&... args) { // FIXME: Would be better not to use sprint here. sstring req = sprint(text, cf); return this->_qp.local().execute_internal(req, { boost::any(std::forward(args))... }); } database& db() { return _db.local(); } service::storage_proxy& proxy() { return _qp.local().proxy().local(); } api::timestamp_type next_timestamp() { return _qp.local().next_timestamp(); } }; // This does not have to be thread local, because all cores will share the same context. extern std::unique_ptr qctx; // Sometimes we are not concerned about system tables at all - for instance, when we are testing. In those cases, just pretend // we executed the query, and return an empty result template static future<::shared_ptr> execute_cql(sstring text, Args&&... args) { if (qctx) { return qctx->execute_cql(text, std::forward(args)...); } return make_ready_future>(::make_shared(cql3::untyped_result_set::make_empty())); } }