cql3: convert UseStatement to C++

Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
This commit is contained in:
Pekka Enberg
2014-12-30 10:38:08 +02:00
committed by Avi Kivity
parent a17c3f8993
commit cff499989d
4 changed files with 82 additions and 67 deletions

View File

@@ -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"

View File

@@ -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();
}
}

View File

@@ -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

View File

@@ -4,7 +4,11 @@
namespace service {
class client_state {
public:
// FIXME: stub
void validate_login() const {
}
};
}