public interface ReactiveSession extends Closeable
ReactiveSession
executes
queries and prepares statements in a reactive style returning results wrapped in Mono
and
Flux
.
Each session maintains multiple connections to the cluster nodes, provides policies to choose which node to use for
each query (round-robin on all nodes of the cluster by default), and handles retries for failed queries (when it
makes sense).
Session instances are thread-safe and usually a single instance is enough per application. As a given session can
only be "logged" into one keyspace at a time (where the "logged" keyspace is the one used by queries that don't
explicitly use a fully qualified table name), it can make sense to create one session per keyspace used. This is
however not necessary when querying multiple keyspaces since it is always possible to use a single session with fully
qualified table names in queries.Publisher
,
Mono
,
ReactiveResultSet
Modifier and Type | Method and Description |
---|---|
void |
close()
Initiates a shutdown of this session instance and blocks until that shutdown completes.
|
reactor.core.publisher.Mono<ReactiveResultSet> |
execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement)
Executes the provided query.
|
reactor.core.publisher.Mono<ReactiveResultSet> |
execute(String query)
Executes the provided query.
|
reactor.core.publisher.Mono<ReactiveResultSet> |
execute(String query,
Map<String,Object> values)
Executes the provided query using the provided named values.
|
reactor.core.publisher.Mono<ReactiveResultSet> |
execute(String query,
Object... values)
Executes the provided query using the provided values.
|
com.datastax.oss.driver.api.core.context.DriverContext |
getContext()
Returns a context that provides access to all the policies used by this driver instance.
|
boolean |
isClosed()
Whether this Session instance has been closed.
|
reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement> |
prepare(com.datastax.oss.driver.api.core.cql.SimpleStatement statement)
Prepares the provided query.
|
reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement> |
prepare(String query)
Prepares the provided query string.
|
boolean isClosed()
close()
and wait
until it returns (or call the get method on closeAsync()
with a very short timeout and check this doesn't
timeout).true
if this Session instance has been closed, false
otherwise.com.datastax.oss.driver.api.core.context.DriverContext getContext()
reactor.core.publisher.Mono<ReactiveResultSet> execute(String query)
execute(new SimpleStatement(query))
.query
- the CQL query to execute.reactor.core.publisher.Mono<ReactiveResultSet> execute(String query, Object... values)
execute(new SimpleStatement(query, values))
.query
- the CQL query to execute.values
- values required for the execution of query
. See
SimpleStatement.newInstance(String, Object...)
for more details.reactor.core.publisher.Mono<ReactiveResultSet> execute(String query, Map<String,Object> values)
execute(new SimpleStatement(query, values))
.query
- the CQL query to execute.values
- values required for the execution of query
. See
SimpleStatement.newInstance(String, Map)
for more details.reactor.core.publisher.Mono<ReactiveResultSet> execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement)
statement
- the CQL query to execute (that can be any Statement
).reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement> prepare(String query)
query
- the CQL query string to preparequery
.reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement> prepare(com.datastax.oss.driver.api.core.cql.SimpleStatement statement)
prepare(String)
, but note that the resulting PreparedStatement
will
inherit the query properties set on statement
. Concretely, this means that in the following code:
Statement toPrepare = SimpleStatement.newInstance("SELECT * FROM test WHERE k=?") .setConsistencyLevel(ConsistencyLevel.QUORUM); PreparedStatement prepared = session.prepare(toPrepare); session.execute(prepared.bind("someValue"));the final execution will be performed with Quorum consistency. Please note that if the same CQL statement is prepared more than once, all calls to this method will return the same
PreparedStatement
object but the method will still apply the properties of the prepared
Statement
to this object.statement
- the statement to preparestatement
.IllegalArgumentException
- if statement.getValues() != null
(values for executing a prepared
statement should be provided after preparation though the PreparedStatement.bind(java.lang.Object...)
method or
through a corresponding BoundStatement
).void close()
close
in interface AutoCloseable
close
in interface Closeable
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.