Class StatementBuilder<S extends com.datastax.oss.driver.api.querybuilder.BuildableQuery>
java.lang.Object
org.springframework.data.cassandra.core.cql.util.StatementBuilder<S>
- Type Parameters:
S
- Statement type
public class StatementBuilder<S extends com.datastax.oss.driver.api.querybuilder.BuildableQuery>
extends Object
Functional builder for Cassandra
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:
- Creation of the
StatementBuilder
with aquery stub
- Functional declaration applying
builder functions
,bind functions
andon build signals
- Building the statement using
build()
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.
- Since:
- 3.0
- Author:
- Mark Paluch
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Binding function.static enum
Enumeration to represent how parameters are rendered. -
Method Summary
Modifier and TypeMethodDescription<R extends com.datastax.oss.driver.api.querybuilder.BuildableQuery>
StatementBuilder<S>Apply abuilder function
to the statement.bind
(StatementBuilder.BindFunction<S> action) Apply aStatementBuilder.BindFunction
to the statement.com.datastax.oss.driver.api.core.cql.SimpleStatement
build()
Build astatement
by applying builder and bind functions using the defaultCodecRegistry
andStatementBuilder.ParameterHandling.BY_INDEX
parameter rendering.com.datastax.oss.driver.api.core.cql.SimpleStatement
build
(StatementBuilder.ParameterHandling parameterHandling) Build astatement
by applying builder and bind functions using the givenStatementBuilder.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 astatement
by applying builder and bind functions using the givenCodecRegistry
andStatementBuilder.ParameterHandling
.static <S extends com.datastax.oss.driver.api.querybuilder.BuildableQuery>
StatementBuilder<S>of
(S stub) Factory method used to create a newStatementBuilder
with the givenquery stub
.Add behavior when the statement is built.transform
(UnaryOperator<com.datastax.oss.driver.api.core.cql.SimpleStatement> mappingFunction) Add behavior after theSimpleStatement
has been built.
-
Method Details
-
of
public static <S extends com.datastax.oss.driver.api.querybuilder.BuildableQuery> StatementBuilder<S> of(S stub) Factory method used to create a newStatementBuilder
with the givenquery stub
. The stub is used as base for the built query so each query inherits properties of this stub.- Type Parameters:
S
- query type.- Parameters:
stub
- thequery stub
to use.- Returns:
- a
StatementBuilder
for the givenquery stub
. - Throws:
IllegalArgumentException
- if thequery stub
is null.- See Also:
-
BuildableQuery
-
bind
Apply aStatementBuilder.BindFunction
to the statement. Bind functions are applied onbuild()
.- Parameters:
action
- the bind function to be applied to the statement.- Returns:
this
StatementBuilder
.
-
apply
public <R extends com.datastax.oss.driver.api.querybuilder.BuildableQuery> StatementBuilder<S> apply(Function<S, R> action) Apply abuilder function
to the statement. Builder functions are applied onbuild()
.- Parameters:
action
- the builder function to be applied to the statement.- Returns:
this
StatementBuilder
.
-
onBuild
public StatementBuilder<S> onBuild(Consumer<com.datastax.oss.driver.api.core.cql.SimpleStatementBuilder> action) Add behavior when the statement is built. TheConsumer
gets invoked with aSimpleStatementBuilder
allowing association of the final statement with additional settings. TheConsumer
is applied onbuild()
.- Parameters:
action
- theConsumer
function that gets notified onbuild()
.- Returns:
this
StatementBuilder
.
-
transform
public StatementBuilder<S> transform(UnaryOperator<com.datastax.oss.driver.api.core.cql.SimpleStatement> mappingFunction) Add behavior after theSimpleStatement
has been built. TheUnaryOperator
gets invoked with aSimpleStatement
allowing association of the final statement with additional settings. TheUnaryOperator
is applied onbuild()
.- Parameters:
mappingFunction
- theUnaryOperator
function that gets notified onbuild()
.- Returns:
this
StatementBuilder
.
-
build
public com.datastax.oss.driver.api.core.cql.SimpleStatement build()Build astatement
by applying builder and bind functions using the defaultCodecRegistry
andStatementBuilder.ParameterHandling.BY_INDEX
parameter rendering.- Returns:
- the built
SimpleStatement
.
-
build
public com.datastax.oss.driver.api.core.cql.SimpleStatement build(StatementBuilder.ParameterHandling parameterHandling) Build astatement
by applying builder and bind functions using the givenStatementBuilder.ParameterHandling
.- Parameters:
parameterHandling
-StatementBuilder.ParameterHandling
used to determine how to render parameters.- Returns:
- the built
SimpleStatement
.
-
build
public com.datastax.oss.driver.api.core.cql.SimpleStatement build(StatementBuilder.ParameterHandling parameterHandling, com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry codecRegistry) Build astatement
by applying builder and bind functions using the givenCodecRegistry
andStatementBuilder.ParameterHandling
.- Parameters:
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.- Returns:
- the built
SimpleStatement
.
-