public abstract class AbstractSession extends Object implements Session
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.
|
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,
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
closeAsync, executeAsync, getCluster, getLoggedKeyspace, getState, init, initAsync, isClosed
public ResultSet execute(String query)
execute(new SimpleStatement(query))
.public ResultSet execute(String query, Object... values)
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)
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)
public ResultSetFuture executeAsync(String query)
executeAsync(new SimpleStatement(query))
.executeAsync
in interface Session
query
- the CQL query to execute.public ResultSetFuture executeAsync(String query, Map<String,Object> values)
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)
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)
Session.prepare(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.public ListenableFuture<PreparedStatement> prepareAsync(String query)
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, Map<String,ByteBuffer> customPayload)
query
- the CQL query string to preparecustomPayload
- the custom payload to send along the query, or null
if no payload is to be sentquery
.public void close()
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.public void checkNotInEventLoop()
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.