Elffuss BraidHub

kikocis/java-driver public

f01502dcbaf7 · 2.7 KiBRenderedRawPermalink
1## Statements
2
3To execute a query, you create a [Statement] instance and pass it to
4`Session#execute()`. The driver provides various implementations:
5
6* [SimpleStatement]: a simple implementation built directly from a
7 character string. Typically used for queries that are executed only
8 once or a few times.
9* [BoundStatement]: obtained by binding values to a [prepared
10 statement](prepared/). Typically used for queries that are executed
11 often, with different values.
12* [BuiltStatement]: a statement built with the [QueryBuilder] DSL. It
13 can be executed directly like a simple statement, or prepared.
14* [BatchStatement]: a statement that groups multiple statements to be
15 executed as a batch.
16
17`Session` also has a shortcut to build and execute a simple statement in
18a single call:
19
20```java
21session.execute("select release_version from system.local");
22
23// Is equivalent to:
24Statement s = new SimpleStatement("select release_version from system.local");
25session.execute(s);
26```
27
28### Customizing execution
29
30Before executing a statement, you might want to customize certain
31aspects of its execution. `Statement` provides a number of methods for
32this, for example:
33
34```java
35Statement s = new SimpleStatement("select release_version from system.local");
36s.enableTracing();
37session.execute(s);
38```
39
40If you use custom policies ([RetryPolicy], [LoadBalancingPolicy],
41[SpeculativeExecutionPolicy]...), you might also want to have custom
42properties that influence statement execution. To achieve this, you can
43wrap your statements in a custom [StatementWrapper] implementation.
44
45[Statement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/Statement.html
46[SimpleStatement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/SimpleStatement.html
47[BoundStatement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/BoundStatement.html
48[BatchStatement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/BatchStatement.html
49[QueryBuilder]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/querybuilder/QueryBuilder.html
50[BuiltStatement]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/querybuilder/BuiltStatement.html
51[StatementWrapper]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/StatementWrapper.html
52[RetryPolicy]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/policies/RetryPolicy.html
53[LoadBalancingPolicy]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/policies/LoadBalancingPolicy.html
54[SpeculativeExecutionPolicy]: http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/policies/SpeculativeExecutionPolicy.html