public class DefaultBridgedReactiveSession extends Object implements ReactiveSession
ReactiveSession. This implementation bridges asynchronous CqlSession
methods to reactive execution patterns.
Calls are deferred until a subscriber subscribes to the resulting Publisher. The calls
are executed by subscribing to CompletionStage and returning the result as calls complete.
Elements are emitted on netty EventLoop threads. AsyncResultSet allows AsyncPagingIterable.fetchNextPage()
asynchronous requesting} of subsequent pages. The next page is requested after emitting all elements of the previous
page. However, this is an intermediate solution until Datastax can provide a fully reactive driver.
All CQL operations performed by this class are logged at debug level, using
org.springframework.data.cassandra.core.cql.DefaultBridgedReactiveSession as log category.
Mono,
ReactiveResultSet,
Scheduler,
ReactiveSession| Constructor and Description |
|---|
DefaultBridgedReactiveSession(com.datastax.oss.driver.api.core.CqlSession session)
Create a new
DefaultBridgedReactiveSession for a CqlSession. |
| 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.
|
Optional<com.datastax.oss.driver.api.core.CqlIdentifier> |
getKeyspace()
The keyspace that this session is currently connected to, or
Optional.empty() if this session is not
connected to any keyspace. |
com.datastax.oss.driver.api.core.metadata.Metadata |
getMetadata()
Returns a snapshot of the Cassandra cluster's topology and schema metadata.
|
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.
|
public DefaultBridgedReactiveSession(com.datastax.oss.driver.api.core.CqlSession session)
DefaultBridgedReactiveSession for a CqlSession.session - must not be null.public com.datastax.oss.driver.api.core.metadata.Metadata getMetadata()
ReactiveSessionNode itself is not
immutable: some of its properties will be updated dynamically, in particular Node.getState()).
As a consequence of the above, you should call this method each time you need a fresh view of the metadata. Do
not call it once and store the result, because it is a frozen snapshot that will become stale over time.
If a metadata refresh triggers events (such as node added/removed, or schema events), then the new version of the metadata is guaranteed to be visible by the time you receive these events.
getMetadata in interface ReactiveSessionnull, but may be empty if metadata has been disabled in the configuration.public Optional<com.datastax.oss.driver.api.core.CqlIdentifier> getKeyspace()
ReactiveSessionOptional.empty() if this session is not
connected to any keyspace.
There are two ways that this can be set: before initializing the session (either with the session-keyspace
option in the configuration, or with SessionBuilder.withKeyspace(CqlIdentifier)); or at runtime, if the
client issues a request that changes the keyspace (such as a CQL USE query). Note that this second method
is inherently unsafe, since other requests expecting the old keyspace might be executing concurrently. Therefore it
is highly discouraged, aside from trivial cases (such as a cqlsh-style program where requests are never
concurrent).getKeyspace in interface ReactiveSessionpublic boolean isClosed()
ReactiveSessionclose() and wait
until it returns (or call the get method on closeAsync() with a very short timeout and check this doesn't
timeout).isClosed in interface ReactiveSessiontrue if this Session instance has been closed, false otherwise.public com.datastax.oss.driver.api.core.context.DriverContext getContext()
ReactiveSessiongetContext in interface ReactiveSessionpublic reactor.core.publisher.Mono<ReactiveResultSet> execute(String query)
ReactiveSessionexecute(new SimpleStatement(query)).execute in interface ReactiveSessionquery - the CQL query to execute.public reactor.core.publisher.Mono<ReactiveResultSet> execute(String query, Object... values)
ReactiveSessionexecute(new SimpleStatement(query, values)).execute in interface ReactiveSessionquery - the CQL query to execute.values - values required for the execution of query. See
SimpleStatement.newInstance(String, Object...) for more details.public reactor.core.publisher.Mono<ReactiveResultSet> execute(String query, Map<String,Object> values)
ReactiveSessionexecute(new SimpleStatement(query, values)).execute in interface ReactiveSessionquery - the CQL query to execute.values - values required for the execution of query. See
SimpleStatement.newInstance(String, Map) for more details.public reactor.core.publisher.Mono<ReactiveResultSet> execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement)
ReactiveSessionexecute in interface ReactiveSessionstatement - the CQL query to execute (that can be any Statement).public reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement> prepare(String query)
ReactiveSessionprepare in interface ReactiveSessionquery - the CQL query string to preparequery.public reactor.core.publisher.Mono<com.datastax.oss.driver.api.core.cql.PreparedStatement> prepare(com.datastax.oss.driver.api.core.cql.SimpleStatement statement)
ReactiveSessionReactiveSession.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.prepare in interface ReactiveSessionstatement - the statement to preparestatement.public void close()
ReactiveSessionclose in interface Closeableclose in interface AutoCloseableclose in interface ReactiveSessionCopyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.