public abstract class AbstractSession extends Object implements Session, ContinuousPagingSession
This is primarly intended to make mocking easier.
Session.State
Constructor and Description |
---|
AbstractSession() |
Modifier and Type | Method and Description |
---|---|
void |
checkNotInEventLoop()
Checks that the current thread is not one of the Netty I/O threads used by the driver.
|
void |
close()
Initiates a shutdown of this session instance and blocks until that shutdown completes.
|
ResultSet |
execute(Statement statement)
Executes the provided query.
|
ResultSet |
execute(String query)
Executes the provided query.
|
ResultSet |
execute(String query,
Map<String,Object> values)
Executes the provided query using the provided named values.
|
ResultSet |
execute(String query,
Object... values)
Executes the provided query using the provided values.
|
ResultSetFuture |
executeAsync(String query)
Executes the provided query asynchronously.
|
ResultSetFuture |
executeAsync(String query,
Map<String,Object> values)
Executes the provided query asynchronously using the provided values.
|
ResultSetFuture |
executeAsync(String query,
Object... values)
Executes the provided query asynchronously using the provided values.
|
protected Cluster |
getConcreteCluster()
|
PreparedStatement |
prepare(RegularStatement statement)
Prepares the provided query.
|
PreparedStatement |
prepare(String query)
Prepares the provided query string.
|
ListenableFuture<PreparedStatement> |
prepareAsync(RegularStatement statement)
Prepares the provided query asynchronously.
|
ListenableFuture<PreparedStatement> |
prepareAsync(String query)
Prepares the provided query string asynchronously.
|
protected abstract ListenableFuture<PreparedStatement> |
prepareAsync(String query,
String keyspace,
Map<String,ByteBuffer> customPayload)
Prepares the provided query string asynchronously, sending along the provided custom payload,
if any.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
executeContinuously, executeContinuouslyAsync
closeAsync, executeAsync, getCluster, getLoggedKeyspace, getState, init, initAsync, isClosed
public ResultSet execute(String query)
This is a convenience method for execute(new SimpleStatement(query))
.
public ResultSet execute(String query, Object... values)
This is a convenience method for execute(new SimpleStatement(query, values))
.
execute
in interface Session
query
- the CQL query to execute.values
- values required for the execution of query
. See SimpleStatement.SimpleStatement(String, Object...)
for more details.public ResultSet execute(String query, Map<String,Object> values)
This is a convenience method for execute(new SimpleStatement(query, values))
.
execute
in interface Session
query
- the CQL query to execute.values
- values required for the execution of query
. See SimpleStatement.SimpleStatement(String, Map)
for more details.public ResultSet execute(Statement statement)
This method blocks until at least some result has been received from the database. However, for SELECT queries, it does not guarantee that the result has been received in full. But it does guarantee that some response has been received from the database, and in particular guarantees that if the request is invalid, an exception will be thrown by this method.
public ResultSetFuture executeAsync(String query)
This is a convenience method for executeAsync(new SimpleStatement(query))
.
executeAsync
in interface Session
query
- the CQL query to execute.public ResultSetFuture executeAsync(String query, Map<String,Object> values)
This is a convenience method for executeAsync(new SimpleStatement(query, values))
.
executeAsync
in interface Session
query
- the CQL query to execute.values
- values required for the execution of query
. See SimpleStatement.SimpleStatement(String, Map)
for more details.public ResultSetFuture executeAsync(String query, Object... values)
This is a convenience method for executeAsync(new SimpleStatement(query, values))
.
executeAsync
in interface Session
query
- the CQL query to execute.values
- values required for the execution of query
. See SimpleStatement.SimpleStatement(String, Object...)
for more details.public PreparedStatement prepare(String query)
public PreparedStatement prepare(RegularStatement statement)
This method behaves like Session.prepare(String)
, but the resulting PreparedStatement
will inherit some of the properties set on statement
: routing key, consistency level, serial consistency level, tracing flag, retry policy,
outgoing payload, and idempotence. Concretely, this means that in the following code:
RegularStatement toPrepare = new SimpleStatement("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.
public ListenableFuture<PreparedStatement> prepareAsync(String query)
This method is equivalent to Session.prepare(String)
except that it does not block but
return a future instead. Any error during preparation will be thrown when accessing the future,
not by this method itself.
prepareAsync
in interface Session
query
- the CQL query string to preparequery
.public ListenableFuture<PreparedStatement> prepareAsync(RegularStatement statement)
Session.prepareAsync(String)
, but note that the resulting PreparedStatement
will inherit the
query properties set on statement
. Concretely, this means that in the following code:
RegularStatement toPrepare = new SimpleStatement("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.
prepareAsync
in interface Session
statement
- the statement to preparestatement
.Session.prepare(RegularStatement)
protected abstract ListenableFuture<PreparedStatement> prepareAsync(String query, String keyspace, Map<String,ByteBuffer> customPayload)
query
- the CQL query string to preparekeyspace
- the keyspace to prepare this query withcustomPayload
- the custom payload to send along the query, or null
if no payload
is to be sentquery
.public void close()
This method is a shortcut for closeAsync().get()
.
Note that this method does not close the corresponding Cluster
instance (which holds
additional resources, in particular internal executors that must be shut down in order for the
client program to terminate). If you want to do so, use Cluster.close()
, but note that it
will close all sessions created from that cluster.
protected Cluster getConcreteCluster()
Cluster
instance driving the Session
. This is useful to
override in cases where the Session implementation is backed by DelegatingCluster
.public void checkNotInEventLoop()
This method is called from all the synchronous methods of this class to prevent deadlock issues.
User code extending this class can also call this method at any time to check if any code making blocking calls is being wrongly executed on a Netty I/O thread.
Note that the check performed by this method has a small overhead; if that is an issue,
checks can be disabled by setting the System property com.datastax.driver.CHECK_IO_DEADLOCKS
to false
.
IllegalStateException
- if the current thread is one of the Netty I/O thread used by the
driver.Copyright © 2012–2018. All rights reserved.