Author: eevans Date: Wed Dec 14 22:54:54 2011 New Revision: 1214525 URL: http://svn.apache.org/viewvc?rev=1214525&view=rev Log: refactor for better encapsulation of prepare()
Patch by eevans; reviewed by Rick Shaw for CASSANDRA-2475 Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java?rev=1214525&r1=1214524&r2=1214525&view=diff ============================================================================== --- cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java (original) +++ cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java Wed Dec 14 22:54:54 2011 @@ -501,7 +501,7 @@ public class QueryProcessor term.setBindIndex(statement.boundTerms++); } - public static void discoverBoundTerms(CQLStatement statement) throws InvalidRequestException + private static void discoverBoundTerms(CQLStatement statement) throws InvalidRequestException { switch (statement.type) { @@ -1094,11 +1094,24 @@ public class QueryProcessor return processStatement(getStatement(queryString), clientState, new ArrayList<String>()); } - public static CQLStatement prepare(String queryString, ClientState clientState) + public static CqlPreparedResult prepare(String queryString, ClientState clientState) throws RecognitionException, InvalidRequestException { if (logger.isDebugEnabled()) logger.debug("CQL QUERY: {}", queryString); - return getStatement(queryString); + + CQLStatement statement = getStatement(queryString); + int statementId = makeStatementId(queryString); + + discoverBoundTerms(statement); + if (logger.isTraceEnabled()) logger.trace("Discovered "+ statement.boundTerms + " bound variables."); + + clientState.getPrepared().put(statementId, statement); + if (logger.isTraceEnabled()) + logger.trace(String.format("Stored prepared statement #%d with %d bind markers", + statementId, + clientState.getPrepared().size())); + + return new CqlPreparedResult(statementId, statement.boundTerms); } public static CqlResult processPrepared(CQLStatement statement, ClientState clientState, List<String> variables) @@ -1114,12 +1127,17 @@ public class QueryProcessor // at this point there is a match in count between markers and variables that is non-zero if (logger.isTraceEnabled()) - for (int i = 0; i < variables.size(); i++) logger.trace("[{}] '{}'",i+1,variables.get(i)); + for (int i = 0; i < variables.size(); i++) logger.trace("[{}] '{}'", i+1, variables.get(i)); } return processStatement(statement, clientState, variables); } - + + private static final int makeStatementId(String cql) + { + // use the hash of the string till something better is provided + return cql.hashCode(); + } private static Column thriftify(IColumn c) { Modified: cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java?rev=1214525&r1=1214524&r2=1214525&view=diff ============================================================================== --- cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java (original) +++ cassandra/trunk/src/java/org/apache/cassandra/thrift/CassandraServer.java Wed Dec 14 22:54:54 2011 @@ -1228,34 +1228,17 @@ public class CassandraServer implements throw ire; } } - - private static final int makeItemId(String cql) - { - // use the hash of the string till something better is provided - return cql.hashCode(); - } - + public CqlPreparedResult prepare_cql_query(ByteBuffer query, Compression compression) throws InvalidRequestException, TException { if (logger.isDebugEnabled()) logger.debug("prepare_cql_query"); String queryString = uncompress(query,compression); - int itemId = makeItemId(queryString); try { - CQLStatement statement = QueryProcessor.prepare(queryString, state()); - - // discover all the marked Terms and hang them off of statement for use later - QueryProcessor.discoverBoundTerms(statement); - if (logger.isTraceEnabled()) logger.trace("Discovered "+ statement.boundTerms + " bound variables."); - - // put the prepared Statement into the Map - state().getPrepared().put(itemId, statement); - if (logger.isTraceEnabled()) - logger.trace("Storing prepared statement: #"+ itemId + " count:"+state().getPrepared().size()); - return new CqlPreparedResult(itemId, statement.boundTerms); + return QueryProcessor.prepare(queryString, state()); } catch (RecognitionException e) { @@ -1264,8 +1247,7 @@ public class CassandraServer implements throw ire; } } - - + public CqlResult execute_prepared_cql_query(int itemId, List<String> bindVariables) throws InvalidRequestException, UnavailableException, TimedOutException, SchemaDisagreementException, TException {