From cff499989d18733ebf2952e22eb29ea3fa1a8c49 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Tue, 30 Dec 2014 10:38:08 +0200 Subject: [PATCH] cql3: convert UseStatement to C++ Signed-off-by: Pekka Enberg --- cql3/cql3.cc | 1 + cql3/statements/UseStatement.java | 67 --------------------------- cql3/statements/use_statement.hh | 77 +++++++++++++++++++++++++++++++ service/client_state.hh | 4 ++ 4 files changed, 82 insertions(+), 67 deletions(-) delete mode 100644 cql3/statements/UseStatement.java create mode 100644 cql3/statements/use_statement.hh diff --git a/cql3/cql3.cc b/cql3/cql3.cc index 50ec0ba2d1..6138d8a912 100644 --- a/cql3/cql3.cc +++ b/cql3/cql3.cc @@ -14,6 +14,7 @@ #include "functions/native_aggregate_function.hh" #include "functions/native_scalar_function.hh" +#include "statements/use_statement.hh" #include "statements/parsed_statement.hh" #include "cql_statement.hh" diff --git a/cql3/statements/UseStatement.java b/cql3/statements/UseStatement.java deleted file mode 100644 index efda72dad4..0000000000 --- a/cql3/statements/UseStatement.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cassandra.cql3.statements; - -import org.apache.cassandra.cql3.CQLStatement; -import org.apache.cassandra.cql3.QueryOptions; -import org.apache.cassandra.exceptions.InvalidRequestException; -import org.apache.cassandra.exceptions.UnauthorizedException; -import org.apache.cassandra.transport.messages.ResultMessage; -import org.apache.cassandra.service.ClientState; -import org.apache.cassandra.service.QueryState; - -public class UseStatement extends ParsedStatement implements CQLStatement -{ - private final String keyspace; - - public UseStatement(String keyspace) - { - this.keyspace = keyspace; - } - - public int getBoundTerms() - { - return 0; - } - - public Prepared prepare() throws InvalidRequestException - { - return new Prepared(this); - } - - public void checkAccess(ClientState state) throws UnauthorizedException - { - state.validateLogin(); - } - - public void validate(ClientState state) throws InvalidRequestException - { - } - - public ResultMessage execute(QueryState state, QueryOptions options) throws InvalidRequestException - { - state.getClientState().setKeyspace(keyspace); - return new ResultMessage.SetKeyspace(keyspace); - } - - public ResultMessage executeInternal(QueryState state, QueryOptions options) - { - // Internal queries are exclusively on the system keyspace and 'use' is thus useless - throw new UnsupportedOperationException(); - } -} diff --git a/cql3/statements/use_statement.hh b/cql3/statements/use_statement.hh new file mode 100644 index 0000000000..2b3e68e92c --- /dev/null +++ b/cql3/statements/use_statement.hh @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Copyright 2014 Cloudius Systems + * + * Modified by Cloudius Systems + */ + +#ifndef CQL3_STATEMENTS_USE_STATEMENT_HH +#define CQL3_STATEMENTS_USE_STATEMENT_HH + +#include "cql3/statements/parsed_statement.hh" +#include "cql3/cql_statement.hh" + +namespace cql3 { + +namespace statements { + +class use_statement : public parsed_statement, public virtual cql_statement { +private: + const sstring _keyspace; + +public: + use_statement(sstring keyspace) + : _keyspace(keyspace) + { } + + virtual int get_bound_terms() override { + return 0; + } + + virtual prepared prepare() override { + return parsed_statement::prepared(*this); + } + + virtual void check_access(const service::client_state& state) override { + state.validate_login(); + } + + virtual void validate(const service::client_state& state) override { + } + + virtual transport::messages::result_message execute(service::query_state& state, const query_options& options) { + throw std::runtime_error("not implemented"); +#if 0 + state.getClientState().setKeyspace(keyspace); + return new ResultMessage.SetKeyspace(keyspace); +#endif + } + + virtual transport::messages::result_message execute_internal(service::query_state& state, const query_options& options) override { + // Internal queries are exclusively on the system keyspace and 'use' is thus useless + throw std::runtime_error("unsupported operation"); + } +}; + +} + +} + +#endif diff --git a/service/client_state.hh b/service/client_state.hh index cd79616537..55ea31138c 100644 --- a/service/client_state.hh +++ b/service/client_state.hh @@ -4,7 +4,11 @@ namespace service { class client_state { +public: // FIXME: stub + + void validate_login() const { + } }; }