use of com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder in project spring-data-cassandra by spring-projects.
the class StatementBuilder method build.
/**
* Build a {@link SimpleStatement statement} by applying builder and bind functions using the given
* {@link CodecRegistry} and {@link ParameterHandling}.
*
* @param parameterHandling {@link ParameterHandling} used to determine how to render parameters.
* @param codecRegistry registry of Apache Cassandra codecs for converting to/from Java types and CQL types.
* @return the built {@link SimpleStatement}.
*/
public SimpleStatement build(ParameterHandling parameterHandling, CodecRegistry codecRegistry) {
Assert.notNull(parameterHandling, "ParameterHandling must not be null");
Assert.notNull(codecRegistry, "CodecRegistry must not be null");
S statement = this.statement;
if (parameterHandling == ParameterHandling.INLINE) {
TermFactory termFactory = new TermFactory() {
@Override
public Term create(@Nullable Object value) {
return toLiteralTerms(value, codecRegistry);
}
@Override
public boolean canBindCollection() {
return false;
}
};
for (BuilderRunnable<S> runnable : queryActions) {
statement = runnable.run(statement, termFactory);
}
return build(statement.builder());
}
if (parameterHandling == ParameterHandling.BY_INDEX) {
List<Object> values = new ArrayList<>();
TermFactory termFactory = value -> {
values.add(value);
return QueryBuilder.bindMarker();
};
for (BuilderRunnable<S> runnable : queryActions) {
statement = runnable.run(statement, termFactory);
}
SimpleStatementBuilder builder = statement.builder();
values.forEach(builder::addPositionalValue);
return build(builder);
}
if (parameterHandling == ParameterHandling.BY_NAME) {
Map<String, Object> values = new LinkedHashMap<>();
TermFactory termFactory = value -> {
String name = "p" + values.size();
values.put(name, value);
return QueryBuilder.bindMarker(name);
};
for (BuilderRunnable<S> runnable : queryActions) {
statement = runnable.run(statement, termFactory);
}
SimpleStatementBuilder builder = statement.builder();
values.forEach(builder::addNamedValue);
return build(builder);
}
throw new UnsupportedOperationException(String.format("ParameterHandling %s not supported", parameterHandling));
}
use of com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder in project vertx-cassandra-client by vert-x3.
the class StreamingTest method streamFetchesDoesNotOverflowDefault512KbJVMStack.
@Test
public void streamFetchesDoesNotOverflowDefault512KbJVMStack(TestContext testContext) throws Exception {
int fetchSize = 100_000;
initializeRandomStringKeyspace();
insertRandomStrings(5_000);
final SimpleStatement query = new SimpleStatementBuilder(String.format("select random_string from random_strings.random_string_by_first_letter limit %d", fetchSize)).setPageSize(fetchSize).build();
Async async = testContext.async();
client.queryStream(query, testContext.asyncAssertSuccess(stream -> {
stream.endHandler(end -> async.countDown()).exceptionHandler(testContext::fail).handler(item -> {
});
}));
}
Aggregations