cql3: Use shared_from_this for parsed_statement::prepare()

Use shared_from_this instead of the synthetic unique_ptr argument for
parsed_statement::prepare() to preserve the original Cassandra API for
parsed statements.

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
This commit is contained in:
Pekka Enberg
2015-01-12 15:02:52 +02:00
parent e6f87e332a
commit 677264fb3b
4 changed files with 16 additions and 16 deletions

View File

@@ -59,24 +59,24 @@ public:
class prepared {
public:
const std::unique_ptr<cql_statement> statement;
const ::shared_ptr<cql_statement> statement;
const std::vector<::shared_ptr<column_specification>> bound_names;
prepared(std::unique_ptr<cql_statement>&& statement_, const std::vector<::shared_ptr<column_specification>>& bound_names_)
prepared(::shared_ptr<cql_statement> statement_, const std::vector<::shared_ptr<column_specification>>& bound_names_)
: statement(std::move(statement_))
, bound_names(bound_names_)
{ }
prepared(std::unique_ptr<cql_statement>&& statement_, const variable_specifications& names)
: prepared(std::move(statement_), names.get_specifications())
prepared(::shared_ptr<cql_statement> statement_, const variable_specifications& names)
: prepared(statement_, names.get_specifications())
{ }
prepared(std::unique_ptr<cql_statement>&& statement_)
: prepared(std::move(statement_), std::vector<::shared_ptr<column_specification>>())
prepared(::shared_ptr<cql_statement>&& statement_)
: prepared(statement_, std::vector<::shared_ptr<column_specification>>())
{ }
};
virtual std::unique_ptr<prepared> prepare(std::unique_ptr<cql_statement>&& stmt) = 0;
virtual std::unique_ptr<prepared> prepare() = 0;
virtual bool uses_function(sstring ks_name, sstring function_name) {
return false;

View File

@@ -37,7 +37,7 @@ namespace statements {
/**
* Abstract class for statements that alter the schema.
*/
class schema_altering_statement : public cf_statement, public virtual cql_statement {
class schema_altering_statement : public cf_statement, public virtual cql_statement, public ::enable_shared_from_this<use_statement> {
private:
const bool _is_column_family_level;
@@ -63,8 +63,8 @@ protected:
}
}
virtual std::unique_ptr<prepared> prepare(std::unique_ptr<cql_statement>&& stmt) override {
return std::make_unique<parsed_statement::prepared>(std::move(stmt));
virtual std::unique_ptr<prepared> prepare() override {
return std::make_unique<parsed_statement::prepared>(this->shared_from_this());
}
#if 0

View File

@@ -34,7 +34,7 @@ namespace cql3 {
namespace statements {
class truncate_statement : public cf_statement, public virtual cql_statement {
class truncate_statement : public cf_statement, public virtual cql_statement, public ::enable_shared_from_this<truncate_statement> {
public:
truncate_statement(std::experimental::optional<cf_name>&& name)
: cf_statement{std::move(name)}
@@ -44,8 +44,8 @@ public:
return 0;
}
virtual std::unique_ptr<prepared> prepare(std::unique_ptr<cql_statement>&& stmt) override {
return std::make_unique<parsed_statement::prepared>(std::move(stmt));
virtual std::unique_ptr<prepared> prepare() override {
return std::make_unique<parsed_statement::prepared>(this->shared_from_this());
}
virtual void check_access(const service::client_state& state) override {

View File

@@ -32,7 +32,7 @@ namespace cql3 {
namespace statements {
class use_statement : public parsed_statement, public virtual cql_statement {
class use_statement : public parsed_statement, public virtual cql_statement, public ::enable_shared_from_this<use_statement> {
private:
const sstring _keyspace;
@@ -45,8 +45,8 @@ public:
return 0;
}
virtual std::unique_ptr<prepared> prepare(std::unique_ptr<cql_statement>&& stmt) override {
return std::make_unique<parsed_statement::prepared>(std::move(stmt));
virtual std::unique_ptr<prepared> prepare() override {
return std::make_unique<parsed_statement::prepared>(this->shared_from_this());
}
virtual void check_access(const service::client_state& state) override {