Interface PreparedStatementCallback<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
PreparedStatement
. Allows to execute any number of
operations on a single PreparedStatement
, for example a single SyncCqlSession.execute(Statement)
.
Used internally by CqlTemplate
, but also useful for application code. Note that the passed-in
PreparedStatement
can have been created by the framework or by a custom PreparedStatementCreator
.
However, the latter is hardly ever necessary, as most custom callback actions will perform updates in which case a
standard PreparedStatement
is fine. Custom actions will always set parameter values themselves, so that
PreparedStatementCreator
capability is not needed either.
-
Method Summary
Modifier and TypeMethodDescriptiondoInPreparedStatement
(com.datastax.oss.driver.api.core.CqlSession session, com.datastax.oss.driver.api.core.cql.PreparedStatement preparedStatement) Gets called byCqlTemplate.execute(String, PreparedStatementCallback)
with an active CQL session andPreparedStatement
.
-
Method Details
-
doInPreparedStatement
@Nullable T doInPreparedStatement(com.datastax.oss.driver.api.core.CqlSession session, com.datastax.oss.driver.api.core.cql.PreparedStatement preparedStatement) throws com.datastax.oss.driver.api.core.DriverException, DataAccessException Gets called byCqlTemplate.execute(String, PreparedStatementCallback)
with an active CQL session andPreparedStatement
. Does not need to care about closing the session: this will all be handled by Spring'sCqlTemplate
.Allows for returning a result object created within the callback, i.e. a domain object or a collection of domain objects. Note that there's special support for single step actions: see
CqlTemplate.queryForObject(String, Class, Object...)
etc. A thrown RuntimeException is treated as application exception, it gets propagated to the caller of the template.- Parameters:
session
- active Cassandra session, must not be null.preparedStatement
- thePreparedStatement
, must not be null.- Returns:
- a result object.
- Throws:
com.datastax.oss.driver.api.core.DriverException
- if thrown by a session method, to be auto-converted to aDataAccessException
.DataAccessException
- in case of custom exceptions.- See Also:
-