本文整理汇总了Java中org.apache.cassandra.cql3.CQLStatement类的典型用法代码示例。如果您正苦于以下问题:Java CQLStatement类的具体用法?Java CQLStatement怎么用?Java CQLStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CQLStatement类属于org.apache.cassandra.cql3包,在下文中一共展示了CQLStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseSchema
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
/**
* Get the meta data (column definitions) for the target table.
*
* @param query The CREATE TABLE statement for the table the Json data should be put into.
* @return The table's meta data
*/
private static CFMetaData parseSchema(String query) {
try {
ClientState state = ClientState.forInternalCalls();
ParsedStatement.Prepared prepared = QueryProcessor.getStatement(query, state);
CQLStatement stmt = prepared.statement;
stmt.validate(state);
if (!stmt.getClass().equals(CreateTableStatement.class)) {
throw new IllegalArgumentException("Invalid query, must be a CREATE TABLE statement");
}
return CreateTableStatement.class.cast(stmt).getCFMetaData();
} catch (RequestValidationException | IllegalArgumentException e) {
throw new RuntimeException(e);
}
}
示例2: processPrepared
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
public ResultMessage processPrepared(CQLStatement statement,
QueryState state,
QueryOptions options,
Map<String, ByteBuffer> customPayload)
throws RequestExecutionException, RequestValidationException
{
if (customPayload != null)
requestPayload = customPayload;
ResultMessage result = QueryProcessor.instance.processPrepared(statement, state, options, customPayload);
if (customPayload != null)
{
result.setCustomPayload(responsePayload);
responsePayload = null;
}
return result;
}
示例3: extractResultMetadata
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
private static ResultSet.Metadata extractResultMetadata(CQLStatement statement)
{
if (!(statement instanceof SelectStatement))
return ResultSet.Metadata.EMPTY;
return ((SelectStatement)statement).getResultMetadata();
}
示例4: extractResultMetadata
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
private static ResultSet.ResultMetadata extractResultMetadata(CQLStatement statement)
{
if (!(statement instanceof SelectStatement))
return ResultSet.ResultMetadata.EMPTY;
return ((SelectStatement)statement).getResultMetadata();
}
示例5: assertFunctions
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
private void assertFunctions(CQLStatement stmt, String... function)
{
Set<String> expected = com.google.common.collect.Sets.newHashSet(function);
Set<String> actual = com.google.common.collect.Sets.newHashSet(Iterables.transform(stmt.getFunctions(),
toFunctionNames));
assertTrue(com.google.common.collect.Sets.symmetricDifference(expected, actual).isEmpty());
}
示例6: execute
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
CQLStatement statement = QueryProcessor.getPrepared(statementId);
if (statement == null)
throw new PreparedQueryNotFoundException(statementId);
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance().begin("Execute CQL3 prepared query", Collections.<String, String>emptyMap());
}
Message.Response response = QueryProcessor.processPrepared(statement, consistency, state, values);
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance().stopSession();
}
}
示例7: Prepared
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
protected Prepared(CQLStatement statement, List<ColumnSpecification> boundNames)
{
this.statement = statement;
this.boundNames = boundNames;
this.rawCQLStatement = "";
}
示例8: execute
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
QueryHandler handler = state.getClientState().getCQLQueryHandler();
ParsedStatement.Prepared prepared = handler.getPrepared(statementId);
if (prepared == null)
throw new PreparedQueryNotFoundException(statementId);
options.prepare(prepared.boundNames);
CQLStatement statement = prepared.statement;
if (options.getPageSize() == 0)
throw new ProtocolException("The page size cannot be 0");
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
if (options.getPageSize() > 0)
builder.put("page_size", Integer.toString(options.getPageSize()));
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute CQL3 prepared query", builder.build());
}
Message.Response response = handler.processPrepared(statement, state, options);
if (options.skipMetadata() && response instanceof ResultMessage.Rows)
((ResultMessage.Rows)response).result.metadata.setSkipMetadata();
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
JVMStabilityInspector.inspectThrowable(e);
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}
示例9: execute
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute batch of CQL3 queries", Collections.<String, String>emptyMap());
}
List<ModificationStatement> statements = new ArrayList<ModificationStatement>(queryOrIdList.size());
for (int i = 0; i < queryOrIdList.size(); i++)
{
Object query = queryOrIdList.get(i);
CQLStatement statement;
if (query instanceof String)
{
statement = QueryProcessor.parseStatement((String)query, state);
}
else
{
statement = QueryProcessor.getPrepared((MD5Digest)query);
if (statement == null)
throw new PreparedQueryNotFoundException((MD5Digest)query);
}
List<ByteBuffer> queryValues = values.get(i);
if (queryValues.size() != statement.getBoundsTerms())
throw new InvalidRequestException(String.format("There were %d markers(?) in CQL but %d bound variables",
statement.getBoundsTerms(),
queryValues.size()));
if (!(statement instanceof ModificationStatement))
throw new InvalidRequestException("Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed.");
ModificationStatement mst = (ModificationStatement)statement;
if (mst.isCounter())
{
if (type != BatchStatement.Type.COUNTER)
throw new InvalidRequestException("Cannot include counter statement in a non-counter batch");
}
else
{
if (type == BatchStatement.Type.COUNTER)
throw new InvalidRequestException("Cannot include non-counter statement in a counter batch");
}
statements.add(mst);
}
// Note: It's ok at this point to pass a bogus value for the number of bound terms in the BatchState ctor
// (and no value would be really correct, so we prefer passing a clearly wrong one).
BatchStatement batch = new BatchStatement(-1, type, statements, Attributes.none());
Message.Response response = QueryProcessor.processBatch(batch, consistency, state, values);
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}
示例10: execute
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
CQLStatement statement = QueryProcessor.getPrepared(statementId);
if (statement == null)
throw new PreparedQueryNotFoundException(statementId);
if (options.getPageSize() == 0)
throw new ProtocolException("The page size cannot be 0");
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
if (options.getPageSize() > 0)
builder.put("page_size", Integer.toString(options.getPageSize()));
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute CQL3 prepared query", builder.build());
}
Message.Response response = QueryProcessor.processPrepared(statement, state, options);
if (options.skipMetadata() && response instanceof ResultMessage.Rows)
((ResultMessage.Rows)response).result.metadata.setSkipMetadata();
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}
示例11: execute
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
QueryHandler handler = ClientState.getCQLQueryHandler();
ParsedStatement.Prepared prepared = handler.getPrepared(statementId);
if (prepared == null)
throw new PreparedQueryNotFoundException(statementId);
options.prepare(prepared.boundNames);
CQLStatement statement = prepared.statement;
if (options.getPageSize() == 0)
throw new ProtocolException("The page size cannot be 0");
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
if (options.getPageSize() > 0)
builder.put("page_size", Integer.toString(options.getPageSize()));
if(options.getConsistency() != null)
builder.put("consistency_level", options.getConsistency().name());
if(options.getSerialConsistency() != null)
builder.put("serial_consistency_level", options.getSerialConsistency().name());
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute CQL3 prepared query", state.getClientAddress(), builder.build());
}
// Some custom QueryHandlers are interested by the bound names. We provide them this information
// by wrapping the QueryOptions.
QueryOptions queryOptions = QueryOptions.addColumnSpecifications(options, prepared.boundNames);
Message.Response response = handler.processPrepared(statement, state, queryOptions, getCustomPayload());
if (options.skipMetadata() && response instanceof ResultMessage.Rows)
((ResultMessage.Rows)response).result.metadata.setSkipMetadata();
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
JVMStabilityInspector.inspectThrowable(e);
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}
示例12: getStatement
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
private CQLStatement getStatement(String cql)
{
return QueryProcessor.getStatement(cql, clientState).statement;
}
示例13: execute
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
QueryHandler handler = state.getClientState().getCQLQueryHandler();
ParsedStatement.Prepared prepared = handler.getPrepared(statementId);
if (prepared == null)
throw new PreparedQueryNotFoundException(statementId);
options.prepare(prepared.boundNames);
CQLStatement statement = prepared.statement;
if (options.getPageSize() == 0)
throw new ProtocolException("The page size cannot be 0");
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
if (options.getPageSize() > 0)
builder.put("page_size", Integer.toString(options.getPageSize()));
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute CQL3 prepared query", builder.build());
}
Message.Response response = handler.processPrepared(statement, state, options);
if (options.skipMetadata() && response instanceof ResultMessage.Rows)
((ResultMessage.Rows)response).result.metadata.setSkipMetadata();
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}
示例14: execute
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute batch of CQL3 queries", Collections.<String, String>emptyMap());
}
List<ModificationStatement> statements = new ArrayList<ModificationStatement>(queryOrIdList.size());
for (int i = 0; i < queryOrIdList.size(); i++)
{
Object query = queryOrIdList.get(i);
CQLStatement statement;
if (query instanceof String)
{
statement = QueryProcessor.parseStatement((String)query, state);
}
else
{
statement = QueryProcessor.getPrepared((MD5Digest)query);
if (statement == null)
throw new PreparedQueryNotFoundException((MD5Digest)query);
}
List<ByteBuffer> queryValues = values.get(i);
if (queryValues.size() != statement.getBoundTerms())
throw new InvalidRequestException(String.format("There were %d markers(?) in CQL but %d bound variables",
statement.getBoundTerms(),
queryValues.size()));
if (!(statement instanceof ModificationStatement))
throw new InvalidRequestException("Invalid statement in batch: only UPDATE, INSERT and DELETE statements are allowed.");
ModificationStatement mst = (ModificationStatement)statement;
if (mst.isCounter())
{
if (type != BatchStatement.Type.COUNTER)
throw new InvalidRequestException("Cannot include counter statement in a non-counter batch");
}
else
{
if (type == BatchStatement.Type.COUNTER)
throw new InvalidRequestException("Cannot include non-counter statement in a counter batch");
}
statements.add(mst);
}
// Note: It's ok at this point to pass a bogus value for the number of bound terms in the BatchState ctor
// (and no value would be really correct, so we prefer passing a clearly wrong one).
BatchStatement batch = new BatchStatement(-1, type, statements, Attributes.none());
Message.Response response = QueryProcessor.processBatch(batch, consistency, state, values, queryOrIdList);
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}
示例15: execute
import org.apache.cassandra.cql3.CQLStatement; //导入依赖的package包/类
public Message.Response execute(QueryState state)
{
try
{
QueryHandler handler = state.getClientState().getCQLQueryHandler();
CQLStatement statement = handler.getPrepared(statementId);
if (statement == null)
throw new PreparedQueryNotFoundException(statementId);
if (options.getPageSize() == 0)
throw new ProtocolException("The page size cannot be 0");
UUID tracingId = null;
if (isTracingRequested())
{
tracingId = UUIDGen.getTimeUUID();
state.prepareTracingSession(tracingId);
}
if (state.traceNextQuery())
{
state.createTracingSession();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
if (options.getPageSize() > 0)
builder.put("page_size", Integer.toString(options.getPageSize()));
// TODO we don't have [typed] access to CQL bind variables here. CASSANDRA-4560 is open to add support.
Tracing.instance.begin("Execute CQL3 prepared query", builder.build());
}
Message.Response response = handler.processPrepared(statement, state, options);
if (options.skipMetadata() && response instanceof ResultMessage.Rows)
((ResultMessage.Rows)response).result.metadata.setSkipMetadata();
if (tracingId != null)
response.setTracingId(tracingId);
return response;
}
catch (Exception e)
{
return ErrorMessage.fromException(e);
}
finally
{
Tracing.instance.stopSession();
}
}