S - Statement typepublic class StatementBuilder<S extends com.datastax.oss.driver.api.querybuilder.BuildableQuery> extends Object
statements. Statements are built by applying
builder functions that get applied when building the actual
statement. The StatementBuilder provides a mutable container for statement creation
allowing a functional declaration of actions that are necessary to build a statement. This class helps building CQL
statements as a BuildableQuery classes are typically immutable and require return value tracking across
methods that want to apply modifications to a statement.
Building a statement consists of three phases:
StatementBuilder with a query stubbuilder functions, bind functions and
on build signalsbuild()query stub is used as base object for all built queries. Builder functions are
applied each time a statement is built allowing to build multiple statement instances while evolving the actual
statement.
The builder can be used for structural evolution and value evolution of statements. Values are bound through
binding functions that accept the statement and a TermFactory. Values can be bound
inline or through bind markers when building the statement. All
functions are applied in the order of their declaration.
All methods returning StatementBuilder point to the same instance. This class is intended for internal use.
| Modifier and Type | Class and Description |
|---|---|
static interface |
StatementBuilder.BindFunction<S>
Binding function.
|
static class |
StatementBuilder.ParameterHandling
Enumeration to represent how parameters are rendered.
|
| Modifier and Type | Method and Description |
|---|---|
<R extends com.datastax.oss.driver.api.querybuilder.BuildableQuery> |
apply(Function<S,R> action)
Apply a
builder function to the statement. |
StatementBuilder<S> |
bind(StatementBuilder.BindFunction<S> action)
Apply a
StatementBuilder.BindFunction to the statement. |
com.datastax.oss.driver.api.core.cql.SimpleStatement |
build()
Build a
statement by applying builder and bind functions using the default
CodecRegistry and StatementBuilder.ParameterHandling.BY_INDEX parameter rendering. |
com.datastax.oss.driver.api.core.cql.SimpleStatement |
build(StatementBuilder.ParameterHandling parameterHandling)
Build a
statement by applying builder and bind functions using the given
StatementBuilder.ParameterHandling. |
com.datastax.oss.driver.api.core.cql.SimpleStatement |
build(StatementBuilder.ParameterHandling parameterHandling,
com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry codecRegistry)
Build a
statement by applying builder and bind functions using the given
CodecRegistry and StatementBuilder.ParameterHandling. |
static <S extends com.datastax.oss.driver.api.querybuilder.BuildableQuery> |
of(S stub)
Factory method used to create a new
StatementBuilder with the given query stub. |
StatementBuilder<S> |
onBuild(Consumer<com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder> action)
Add behavior when the statement is built.
|
StatementBuilder<S> |
transform(UnaryOperator<com.datastax.oss.driver.api.core.cql.SimpleStatement> mappingFunction)
Add behavior after the
SimpleStatement has been built. |
public static <S extends com.datastax.oss.driver.api.querybuilder.BuildableQuery> StatementBuilder<S> of(S stub)
StatementBuilder with the given query stub.
The stub is used as base for the built query so each query inherits properties of this stub.S - query type.stub - the query stub to use.StatementBuilder for the given query stub.IllegalArgumentException - if the query stub is null.BuildableQuerypublic StatementBuilder<S> bind(StatementBuilder.BindFunction<S> action)
StatementBuilder.BindFunction to the statement. Bind functions are applied on build().action - the bind function to be applied to the statement.this StatementBuilder.public <R extends com.datastax.oss.driver.api.querybuilder.BuildableQuery> StatementBuilder<S> apply(Function<S,R> action)
builder function to the statement. Builder functions are applied on build().action - the builder function to be applied to the statement.this StatementBuilder.public StatementBuilder<S> onBuild(Consumer<com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder> action)
Consumer gets invoked with a SimpleStatementBuilder
allowing association of the final statement with additional settings. The Consumer is applied on
build().action - the Consumer function that gets notified on build().this StatementBuilder.public StatementBuilder<S> transform(UnaryOperator<com.datastax.oss.driver.api.core.cql.SimpleStatement> mappingFunction)
SimpleStatement has been built. The UnaryOperator gets invoked with a
SimpleStatement allowing association of the final statement with additional settings. The
UnaryOperator is applied on build().mappingFunction - the UnaryOperator function that gets notified on build().this StatementBuilder.public com.datastax.oss.driver.api.core.cql.SimpleStatement build()
statement by applying builder and bind functions using the default
CodecRegistry and StatementBuilder.ParameterHandling.BY_INDEX parameter rendering.SimpleStatement.public com.datastax.oss.driver.api.core.cql.SimpleStatement build(StatementBuilder.ParameterHandling parameterHandling)
statement by applying builder and bind functions using the given
StatementBuilder.ParameterHandling.parameterHandling - StatementBuilder.ParameterHandling used to determine how to render parameters.SimpleStatement.public com.datastax.oss.driver.api.core.cql.SimpleStatement build(StatementBuilder.ParameterHandling parameterHandling, com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry codecRegistry)
statement by applying builder and bind functions using the given
CodecRegistry and StatementBuilder.ParameterHandling.parameterHandling - StatementBuilder.ParameterHandling used to determine how to render parameters.codecRegistry - registry of Apache Cassandra codecs for converting to/from Java types and CQL types.SimpleStatement.Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.