Class AsyncCqlTemplate
- All Implemented Interfaces:
InitializingBean,AsyncCqlOperations
ResultSets and
catching DriverException exceptions and translating them to the generic, more informative exception hierarchy
defined in the org.springframework.dao package.
Code using this class need only implement callback interfaces, giving them a clearly defined contract. The
PreparedStatementCreator callback interface creates a prepared statement given a Connection, providing CQL
and any necessary parameters. The AsyncResultSetExtractor interface extracts values from a ResultSet.
See also PreparedStatementBinder and RowMapper for two popular alternative callback interfaces.
Can be used within a service implementation via direct instantiation with a CqlSession reference, or get
prepared in an application context and given to services as bean reference. Note: The CqlSession should
always be configured as a bean in the application context, in the first case given to the service directly, in the
second case to the prepared template.
Because this class is parameterizable by the callback interfaces and the
PersistenceExceptionTranslator interface, there should be no need to subclass
it.
All CQL operations performed by this class are logged at debug level, using "org.springframework.data.cassandra.core.cqlTemplate" as log category.
NOTE: An instance of this class is thread-safe once configured.
- Since:
- 2.0
- Author:
- Mark Paluch, John Blum
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classAdapter to enable use of aRowCallbackHandlerinside aResultSetExtractor. -
Field Summary
Fields inherited from class org.springframework.data.cassandra.core.cql.CassandraAccessor
logger -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new, uninitializedAsyncCqlTemplate.AsyncCqlTemplate(com.datastax.oss.driver.api.core.CqlSession session) Create a newAsyncCqlTemplatewith the givenCqlSession.AsyncCqlTemplate(SessionFactory sessionFactory) Constructs a newAsyncCqlTemplatewith the givenSessionFactory. -
Method Summary
Modifier and TypeMethodDescriptionexecute(com.datastax.oss.driver.api.core.cql.Statement<?> statement) Issue a single CQL execute, typically a DDL statement, insert, update or delete statement.Issue a single CQL execute, typically a DDL statement, insert, update or delete statement.Issue a single CQL operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.execute(String cql, PreparedStatementBinder psb) Issue an statement using aPreparedStatementBinderto set bind parameters, with given CQL.<T> CompletableFuture<T>execute(String cql, PreparedStatementCallback<T> action) Execute a CQL data access operation, implemented as callback action working on a CQLPreparedStatement.execute(AsyncPreparedStatementCreator preparedStatementCreator) Issue a single CQL execute operation (such as an insert, update or delete statement) using aAsyncPreparedStatementCreatorto provide CQL and any required parameters.<T> CompletableFuture<T>execute(AsyncPreparedStatementCreator preparedStatementCreator, PreparedStatementCallback<T> action) Execute a CQL data access operation, implemented as callback action working on a CQLPreparedStatement.<T> CompletableFuture<T>execute(AsyncSessionCallback<T> action) Execute a CQL data access operation, implemented as callback action working on aCqlSession.protected AsyncPreparedStatementCreatorCreate a new CQL-basedAsyncPreparedStatementCreatorusing the CQL passed in.newAsyncResultSetExtractor(RowCallbackHandler rowCallbackHandler) Constructs a new instance of theResultSetExtractoradapting the givenRowCallbackHandler.protected <T> AsyncRowMapperResultSetExtractor<T>newAsyncResultSetExtractor(RowMapper<T> rowMapper) Constructs a new instance of theResultSetExtractoradapting the givenRowMapper.<T> CompletableFuture<T>query(com.datastax.oss.driver.api.core.cql.Statement<?> statement, AsyncResultSetExtractor<T> resultSetExtractor) Execute a query given static CQL, reading theResultSetwith aAsyncResultSetExtractor.query(com.datastax.oss.driver.api.core.cql.Statement<?> statement, RowCallbackHandler rowCallbackHandler) Execute a query given static CQL, reading theResultSeton a per-row basis with aRowCallbackHandler.<T> CompletableFuture<List<T>>Execute a query given static CQL, mapping each row to a Java object via aRowMapper.<T> CompletableFuture<T>query(String cql, AsyncResultSetExtractor<T> resultSetExtractor) Execute a query given static CQL, reading theResultSetwith aAsyncResultSetExtractor.<T> CompletableFuture<T>query(String cql, AsyncResultSetExtractor<T> resultSetExtractor, Object... args) Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, reading theResultSetwith aAsyncResultSetExtractor.<T> CompletableFuture<T>query(String cql, PreparedStatementBinder psb, AsyncResultSetExtractor<T> resultSetExtractor) Query using a prepared statement, reading theResultSetwith aAsyncResultSetExtractor.query(String cql, PreparedStatementBinder psb, RowCallbackHandler rowCallbackHandler) Query given CQL to create a prepared statement from CQL and aPreparedStatementBinderimplementation that knows how to bind values to the query, reading theResultSeton a per-row basis with aRowCallbackHandler.<T> CompletableFuture<List<T>>query(String cql, PreparedStatementBinder psb, RowMapper<T> rowMapper) Query given CQL to create a prepared statement from CQL and aPreparedStatementBinderimplementation that knows how to bind values to the query, mapping each row to a Java object via aRowMapper.query(String cql, RowCallbackHandler rowCallbackHandler) Execute a query given static CQL, reading theResultSeton a per-row basis with aRowCallbackHandler.query(String cql, RowCallbackHandler rowCallbackHandler, Object... args) Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, reading theResultSeton a per-row basis with aRowCallbackHandler.<T> CompletableFuture<List<T>>Execute a query given static CQL, mapping each row to a Java object via aRowMapper.<T> CompletableFuture<List<T>>Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, mapping each row to a Java object via aRowMapper.<T> CompletableFuture<T>query(AsyncPreparedStatementCreator preparedStatementCreator, AsyncResultSetExtractor<T> resultSetExtractor) Query using a prepared statement, reading theResultSetwith aAsyncResultSetExtractor.<T> CompletableFuture<T>query(AsyncPreparedStatementCreator preparedStatementCreator, PreparedStatementBinder psb, AsyncResultSetExtractor<T> resultSetExtractor) Query using a prepared statement and aPreparedStatementBinderimplementation that knows how to bind values to the query, reading theResultSetwith aAsyncResultSetExtractor.query(AsyncPreparedStatementCreator preparedStatementCreator, PreparedStatementBinder psb, RowCallbackHandler rowCallbackHandler) Query using a prepared statement and aPreparedStatementBinderimplementation that knows how to bind values to the query, reading theResultSeton a per-row basis with aRowCallbackHandler.<T> CompletableFuture<List<T>>query(AsyncPreparedStatementCreator preparedStatementCreator, PreparedStatementBinder psb, RowMapper<T> rowMapper) Query using a prepared statement and aPreparedStatementBinderimplementation that knows how to bind values to the query, mapping each row to a Java object via aRowMapper.query(AsyncPreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler) Query using a prepared statement, reading theResultSeton a per-row basis with aRowCallbackHandler.<T> CompletableFuture<List<T>>query(AsyncPreparedStatementCreator preparedStatementCreator, RowMapper<T> rowMapper) Query using a prepared statement, mapping each row to a Java object via aRowMapper.queryForList(com.datastax.oss.driver.api.core.cql.Statement<?> statement) Execute a query for a resultList, given static CQL.<T> CompletableFuture<List<T>>queryForList(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> elementType) Execute a query for a resultList, given static CQL.queryForList(String cql) Execute a query for a resultList, given static CQL.<T> CompletableFuture<List<T>>queryForList(String cql, Class<T> elementType) Execute a query for a resultList, given static CQL.<T> CompletableFuture<List<T>>queryForList(String cql, Class<T> elementType, Object... args) Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a resultList.queryForList(String cql, Object... args) Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a resultList.queryForMap(com.datastax.oss.driver.api.core.cql.Statement<?> statement) Execute a query for a result Map, given static CQL.queryForMap(String cql) Execute a query for a result Map, given static CQL.queryForMap(String cql, Object... args) Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a result Map.<T> CompletableFuture<T>queryForObject(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> requiredType) Execute a query for a result object, given static CQL.<T> CompletableFuture<T>queryForObject(com.datastax.oss.driver.api.core.cql.Statement<?> statement, RowMapper<T> rowMapper) Execute a query given static CQL, mapping a single result row to a Java object via aRowMapper.<T> CompletableFuture<T>queryForObject(String cql, Class<T> requiredType) Execute a query for a result object, given static CQL.<T> CompletableFuture<T>queryForObject(String cql, Class<T> requiredType, Object... args) Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a result object.<T> CompletableFuture<T>queryForObject(String cql, RowMapper<T> rowMapper) Execute a query given static CQL, mapping a single result row to a Java object via aRowMapper.<T> CompletableFuture<T>queryForObject(String cql, RowMapper<T> rowMapper, Object... args) Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, mapping a single result row to a Java object via aRowMapper.CompletableFuture<com.datastax.oss.driver.api.core.cql.AsyncResultSet>queryForResultSet(com.datastax.oss.driver.api.core.cql.Statement<?> statement) Execute a query for a ResultSet, given static CQL.CompletableFuture<com.datastax.oss.driver.api.core.cql.AsyncResultSet>queryForResultSet(String cql) Execute a query for a ResultSet, given static CQL.CompletableFuture<com.datastax.oss.driver.api.core.cql.AsyncResultSet>queryForResultSet(String cql, Object... args) Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a ResultSet.protected DataAccessExceptiontranslateException(String task, String cql, com.datastax.oss.driver.api.core.DriverException ex) Translate the givenDriverExceptioninto a genericDataAccessException.protected DataAccessExceptiontranslateExceptionIfPossible(String task, String cql, RuntimeException ex) Translate the givenDriverExceptioninto a genericDataAccessException.Methods inherited from class org.springframework.data.cassandra.core.cql.CassandraAccessor
afterPropertiesSet, applyStatementSettings, getConsistencyLevel, getExceptionTranslator, getExecutionProfileResolver, getFetchSize, getKeyspace, getPageSize, getSerialConsistencyLevel, getSession, getSessionFactory, newColumnMapRowMapper, newPreparedStatementBinder, newSingleColumnRowMapper, newStatement, setConsistencyLevel, setExceptionTranslator, setExecutionProfile, setExecutionProfileResolver, setFetchSize, setKeyspace, setPageSize, setSerialConsistencyLevel, setSession, setSessionFactory, toCql, translate, translateExceptionIfPossible
-
Constructor Details
-
AsyncCqlTemplate
public AsyncCqlTemplate()Create a new, uninitializedAsyncCqlTemplate. Note: TheSessionFactoryhas to be set before using the instance. -
AsyncCqlTemplate
public AsyncCqlTemplate(com.datastax.oss.driver.api.core.CqlSession session) Create a newAsyncCqlTemplatewith the givenCqlSession.- Parameters:
session- the active CassandraCqlSession, must not be null.- Throws:
IllegalStateException- ifCqlSessionis null.
-
AsyncCqlTemplate
Constructs a newAsyncCqlTemplatewith the givenSessionFactory.- Parameters:
sessionFactory- the active CassandraSessionFactory.- Since:
- 2.0
- See Also:
-
-
Method Details
-
execute
Description copied from interface:AsyncCqlOperationsExecute a CQL data access operation, implemented as callback action working on aCqlSession. This allows for implementing arbitrary data access operations, within Spring's managed CQL environment: that is, converting CQLDriverExceptions into Spring'sDataAccessExceptionhierarchy.The callback action can return a result object, for example a domain object or a collection of domain objects.
- Specified by:
executein interfaceAsyncCqlOperations- Parameters:
action- the callback object that specifies the action.- Returns:
- a result object returned by the action, or null.
- Throws:
DataAccessException- if there is any problem executing the query.
-
execute
Description copied from interface:AsyncCqlOperationsIssue a single CQL execute, typically a DDL statement, insert, update or delete statement.- Specified by:
executein interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.- Returns:
- boolean value whether the statement was applied.
- Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<T> query(String cql, AsyncResultSetExtractor<T> resultSetExtractor) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query given static CQL, reading theResultSetwith aAsyncResultSetExtractor.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedquerymethod with null as argument array.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.resultSetExtractor- object that will extract all rows of results, must not be null.- Returns:
- an arbitrary result object, as returned by the AsyncResultSetExtractor.
- Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
query
public CompletableFuture<Void> query(String cql, RowCallbackHandler rowCallbackHandler) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query given static CQL, reading theResultSeton a per-row basis with aRowCallbackHandler.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedquerymethod with null as argument array.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.rowCallbackHandler- object that will extract results, one row at a time, must not be null.- Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
query
public <T> CompletableFuture<List<T>> query(String cql, RowMapper<T> rowMapper) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query given static CQL, mapping each row to a Java object via aRowMapper.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedquerymethod with null as argument array.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.rowMapper- object that will map one object per row, must not be null.- Returns:
- the result
List, containing mapped objects. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
queryForList
public CompletableFuture<List<Map<String,Object>>> queryForList(String cql) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query for a resultList, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedqueryForListmethod with null as argument array.The results will be mapped to a
List(one item for each row) ofMaps (one entry for each column using the column name as the key). Each item in theListwill be of the form returned by this interface's queryForMap() methods.- Specified by:
queryForListin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.- Returns:
- a
Listthat contains aMapper row. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
queryForList
public <T> CompletableFuture<List<T>> queryForList(String cql, Class<T> elementType) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query for a resultList, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedqueryForListmethod with null as argument array.The results will be mapped to a
List(one item for each row) of result objects, each of them matching the specified element type.- Specified by:
queryForListin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.elementType- the required type of element in the resultList(for example,Integer.class), must not be null.- Returns:
- a
Listof objects that match the specified element type. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
queryForMap
Description copied from interface:AsyncCqlOperationsExecute a query for a result Map, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedAsyncCqlOperations.queryForMap(String, Object...)method with null as argument array.The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
- Specified by:
queryForMapin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.- Returns:
- the result Map (one entry for each column, using the column name as the key), must not be null.
- Throws:
IncorrectResultSizeDataAccessException- if the query does not return exactly one row.DataAccessException- if there is any problem executing the query.- See Also:
-
queryForObject
public <T> CompletableFuture<T> queryForObject(String cql, Class<T> requiredType) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query for a result object, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedAsyncCqlOperations.queryForObject(String, Class, Object...)method with null as argument array.This method is useful for running static CQL with a known outcome. The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
- Specified by:
queryForObjectin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.requiredType- the type that the result object is expected to match, must not be null.- Returns:
- the result object of the required type, or null in case of CQL NULL.
- Throws:
IncorrectResultSizeDataAccessException- if the query does not return exactly one row, or does not return exactly one column in that row.DataAccessException- if there is any problem executing the query.- See Also:
-
queryForObject
public <T> CompletableFuture<T> queryForObject(String cql, RowMapper<T> rowMapper) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query given static CQL, mapping a single result row to a Java object via aRowMapper.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedAsyncCqlOperations.queryForObject(String, RowMapper, Object...)method with null as argument array.- Specified by:
queryForObjectin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.rowMapper- object that will map one object per row, must not be null.- Returns:
- the single mapped object.
- Throws:
IncorrectResultSizeDataAccessException- if the query does not return exactly one row.DataAccessException- if there is any problem executing the query.- See Also:
-
queryForResultSet
public CompletableFuture<com.datastax.oss.driver.api.core.cql.AsyncResultSet> queryForResultSet(String cql) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query for a ResultSet, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedqueryForResultSetmethod with null as argument array.The results will be mapped to an
ResultSet.- Specified by:
queryForResultSetin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.- Returns:
- a
ResultSetrepresentation. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
execute
public CompletableFuture<Boolean> execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement) throws DataAccessException Description copied from interface:AsyncCqlOperationsIssue a single CQL execute, typically a DDL statement, insert, update or delete statement.- Specified by:
executein interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatement, must not be null.- Returns:
- boolean value whether the statement was applied.
- Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<T> query(com.datastax.oss.driver.api.core.cql.Statement<?> statement, AsyncResultSetExtractor<T> resultSetExtractor) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query given static CQL, reading theResultSetwith aAsyncResultSetExtractor.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedquerymethod with null as argument array.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatement, must not be null.resultSetExtractor- object that will extract all rows of results, must not be null.- Returns:
- an arbitrary result object, as returned by the AsyncResultSetExtractor.
- Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
query
public CompletableFuture<Void> query(com.datastax.oss.driver.api.core.cql.Statement<?> statement, RowCallbackHandler rowCallbackHandler) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query given static CQL, reading theResultSeton a per-row basis with aRowCallbackHandler.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedquerymethod with null as argument array.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatement, must not be null.rowCallbackHandler- object that will extract results, one row at a time, must not be null.- Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
query
public <T> CompletableFuture<List<T>> query(com.datastax.oss.driver.api.core.cql.Statement<?> statement, RowMapper<T> rowMapper) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query given static CQL, mapping each row to a Java object via aRowMapper.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedquerymethod with null as argument array.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatement, must not be null.rowMapper- object that will map one object per row, must not be null.- Returns:
- the result
List, containing mapped objects. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
queryForList
public CompletableFuture<List<Map<String,Object>>> queryForList(com.datastax.oss.driver.api.core.cql.Statement<?> statement) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query for a resultList, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedqueryForListmethod with null as argument array.The results will be mapped to a
List(one item for each row) ofMaps (one entry for each column using the column name as the key). Each item in theListwill be of the form returned by this interface's queryForMap() methods.- Specified by:
queryForListin interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatementto execute, must not be null or empty.- Returns:
- a
Listthat contains aMapper row. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
queryForList
public <T> CompletableFuture<List<T>> queryForList(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> elementType) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query for a resultList, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedqueryForListmethod with null as argument array.The results will be mapped to a
List(one item for each row) of result objects, each of them matching the specified element type.- Specified by:
queryForListin interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatement, must not be null.elementType- the required type of element in the resultList(for example,Integer.class), must not be null.- Returns:
- a
Listof objects that match the specified element type. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
queryForMap
public CompletableFuture<Map<String,Object>> queryForMap(com.datastax.oss.driver.api.core.cql.Statement<?> statement) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query for a result Map, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedAsyncCqlOperations.queryForMap(String, Object...)method with null as argument array.The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
- Specified by:
queryForMapin interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatement, must not be null.- Returns:
- the result Map (one entry for each column, using the column name as the key), must not be null.
- Throws:
IncorrectResultSizeDataAccessException- if the query does not return exactly one row.DataAccessException- if there is any problem executing the query.- See Also:
-
queryForObject
public <T> CompletableFuture<T> queryForObject(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> requiredType) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query for a result object, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedAsyncCqlOperations.queryForObject(String, Class, Object...)method with null as argument array.This method is useful for running static CQL with a known outcome. The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
- Specified by:
queryForObjectin interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatement, must not be null.requiredType- the type that the result object is expected to match, must not be null.- Returns:
- the result object of the required type, or null in case of CQL NULL.
- Throws:
IncorrectResultSizeDataAccessException- if the query does not return exactly one row, or does not return exactly one column in that row.DataAccessException- if there is any problem executing the query.- See Also:
-
queryForObject
public <T> CompletableFuture<T> queryForObject(com.datastax.oss.driver.api.core.cql.Statement<?> statement, RowMapper<T> rowMapper) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query given static CQL, mapping a single result row to a Java object via aRowMapper.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedAsyncCqlOperations.queryForObject(String, RowMapper, Object...)method with null as argument array.- Specified by:
queryForObjectin interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatement, must not be null.rowMapper- object that will map one object per row, must not be null.- Returns:
- the single mapped object.
- Throws:
IncorrectResultSizeDataAccessException- if the query does not return exactly one row.DataAccessException- if there is any problem executing the query.- See Also:
-
queryForResultSet
public CompletableFuture<com.datastax.oss.driver.api.core.cql.AsyncResultSet> queryForResultSet(com.datastax.oss.driver.api.core.cql.Statement<?> statement) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a query for a ResultSet, given static CQL.Uses a CQL Statement, not a
PreparedStatement. If you want to execute a static query with aPreparedStatement, use the overloadedqueryForResultSetmethod with null as argument array.The results will be mapped to an
ResultSet.- Specified by:
queryForResultSetin interfaceAsyncCqlOperations- Parameters:
statement- static CQLStatement, must not be null.- Returns:
- a
ResultSetrepresentation. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
execute
public CompletableFuture<Boolean> execute(AsyncPreparedStatementCreator preparedStatementCreator) throws DataAccessException Description copied from interface:AsyncCqlOperationsIssue a single CQL execute operation (such as an insert, update or delete statement) using aAsyncPreparedStatementCreatorto provide CQL and any required parameters.- Specified by:
executein interfaceAsyncCqlOperations- Parameters:
preparedStatementCreator- object that provides CQL and any necessary parameters, must not be null.- Returns:
- boolean value whether the statement was applied.
- Throws:
DataAccessException- if there is any problem executing the query.
-
execute
Description copied from interface:AsyncCqlOperationsIssue a single CQL operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.- Specified by:
executein interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.args- arguments to bind to the query (leaving it to thePreparedStatementto guess the corresponding CQL type).- Returns:
- boolean value whether the statement was applied.
- Throws:
DataAccessException- if there is any problem executing the query.
-
execute
public CompletableFuture<Boolean> execute(String cql, @Nullable PreparedStatementBinder psb) throws DataAccessException Description copied from interface:AsyncCqlOperationsIssue an statement using aPreparedStatementBinderto set bind parameters, with given CQL. Simpler than using aAsyncPreparedStatementCreatoras this method will create thePreparedStatement: ThePreparedStatementBinderjust needs to set parameters.- Specified by:
executein interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.psb- object that knows how to set values on the prepared statement. If this is null, the CQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.- Returns:
- boolean value whether the statement was applied.
- Throws:
DataAccessException- if there is any problem executing the query.
-
execute
public <T> CompletableFuture<T> execute(String cql, PreparedStatementCallback<T> action) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a CQL data access operation, implemented as callback action working on a CQLPreparedStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed CQL environment: that is, participating in Spring-managed transactions and converting CQLDriverExceptions into Spring'sDataAccessExceptionhierarchy.The callback action can return a result object, for example a domain object or a collection of domain objects.
- Specified by:
executein interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.action- callback object that specifies the action, must not be null.- Returns:
- a result object returned by the action, or null
- Throws:
DataAccessException- if there is any problem executing the query.
-
execute
public <T> CompletableFuture<T> execute(AsyncPreparedStatementCreator preparedStatementCreator, PreparedStatementCallback<T> action) throws DataAccessException Description copied from interface:AsyncCqlOperationsExecute a CQL data access operation, implemented as callback action working on a CQLPreparedStatement. This allows for implementing arbitrary data access operations on a singlePreparedStatement, within Spring's managed CQL environment: that is, participating in Spring-managed transactions and converting CQLDriverExceptions into Spring'sDataAccessExceptionhierarchy.The callback action can return a result object, for example a domain object or a collection of domain objects.
- Specified by:
executein interfaceAsyncCqlOperations- Parameters:
preparedStatementCreator- object that can create aPreparedStatementgiven aCqlSession, must not be null.action- callback object that specifies the action, must not be null.- Returns:
- a result object returned by the action, or null.
- Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<T> query(AsyncPreparedStatementCreator preparedStatementCreator, AsyncResultSetExtractor<T> resultSetExtractor) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery using a prepared statement, reading theResultSetwith aAsyncResultSetExtractor.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
preparedStatementCreator- object that can create aPreparedStatementgiven aCqlSession, must not be null.resultSetExtractor- object that will extract results, must not be null.- Returns:
- an arbitrary result object, as returned by the
AsyncResultSetExtractor - Throws:
DataAccessException- if there is any problem executing the query.
-
query
public CompletableFuture<Void> query(AsyncPreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery using a prepared statement, reading theResultSeton a per-row basis with aRowCallbackHandler.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
preparedStatementCreator- object that can create aPreparedStatementgiven aCqlSession, must not be null.rowCallbackHandler- object that will extract results, one row at a time, must not be null.- Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<List<T>> query(AsyncPreparedStatementCreator preparedStatementCreator, RowMapper<T> rowMapper) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery using a prepared statement, mapping each row to a Java object via aRowMapper.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
preparedStatementCreator- object that can create aPreparedStatementgiven aCqlSession, must not be null.rowMapper- object that will map one object per row, must not be null.- Returns:
- the result
List, containing mapped objects. - Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<T> query(AsyncPreparedStatementCreator preparedStatementCreator, @Nullable PreparedStatementBinder psb, AsyncResultSetExtractor<T> resultSetExtractor) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery using a prepared statement and aPreparedStatementBinderimplementation that knows how to bind values to the query, reading theResultSetwith aAsyncResultSetExtractor.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
preparedStatementCreator- object that can create aPreparedStatementgiven aCqlSession, must not be null.psb- object that knows how to set values on the prepared statement. If this is null, the CQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.resultSetExtractor- object that will extract results, must not be null.- Returns:
- an arbitrary result object, as returned by the
AsyncResultSetExtractor. - Throws:
DataAccessException- if there is any problem executing the query.
-
query
public CompletableFuture<Void> query(AsyncPreparedStatementCreator preparedStatementCreator, @Nullable PreparedStatementBinder psb, RowCallbackHandler rowCallbackHandler) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery using a prepared statement and aPreparedStatementBinderimplementation that knows how to bind values to the query, reading theResultSeton a per-row basis with aRowCallbackHandler.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
preparedStatementCreator- object that can create aPreparedStatementgiven aCqlSession, must not be null.psb- object that knows how to set values on the prepared statement. If this is null, the CQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.rowCallbackHandler- object that will extract results, one row at a time, must not be null.- Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<List<T>> query(AsyncPreparedStatementCreator preparedStatementCreator, @Nullable PreparedStatementBinder psb, RowMapper<T> rowMapper) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery using a prepared statement and aPreparedStatementBinderimplementation that knows how to bind values to the query, mapping each row to a Java object via aRowMapper.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
preparedStatementCreator- object that can create aPreparedStatementgiven aCqlSession, must not be null.psb- object that knows how to set values on the prepared statement. If this is null, the CQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.rowMapper- object that will map one object per row, must not be null.- Returns:
- the result
List, containing mapped objects. - Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<T> query(String cql, AsyncResultSetExtractor<T> resultSetExtractor, Object... args) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, reading theResultSetwith aAsyncResultSetExtractor.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.resultSetExtractor- object that will extract results, must not be null.args- arguments to bind to the query (leaving it to thePreparedStatementto guess the corresponding CQL type).- Returns:
- an arbitrary result object, as returned by the
AsyncResultSetExtractor - Throws:
DataAccessException- if there is any problem executing the query.
-
query
public CompletableFuture<Void> query(String cql, RowCallbackHandler rowCallbackHandler, Object... args) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, reading theResultSeton a per-row basis with aRowCallbackHandler.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.rowCallbackHandler- object that will extract results, one row at a time, must not be null.args- arguments to bind to the query (leaving it to thePreparedStatementto guess the corresponding CQL type)- Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<List<T>> query(String cql, RowMapper<T> rowMapper, Object... args) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, mapping each row to a Java object via aRowMapper.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.rowMapper- object that will map one object per rowargs- arguments to bind to the query (leaving it to thePreparedStatementto guess the corresponding CQL type)- Returns:
- the result
List, containing mapped objects - Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<T> query(String cql, @Nullable PreparedStatementBinder psb, AsyncResultSetExtractor<T> resultSetExtractor) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery using a prepared statement, reading theResultSetwith aAsyncResultSetExtractor.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.psb- object that knows how to set values on the prepared statement. If this is null, the CQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.resultSetExtractor- object that will extract results, must not be null.- Returns:
- an arbitrary result object, as returned by the
AsyncResultSetExtractor. - Throws:
DataAccessException- if there is any problem executing the query.
-
query
public CompletableFuture<Void> query(String cql, @Nullable PreparedStatementBinder psb, RowCallbackHandler rowCallbackHandler) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and aPreparedStatementBinderimplementation that knows how to bind values to the query, reading theResultSeton a per-row basis with aRowCallbackHandler.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.psb- object that knows how to set values on the prepared statement. If this is null, the CQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.rowCallbackHandler- object that will extract results, one row at a time, must not be null.- Throws:
DataAccessException- if there is any problem executing the query.
-
query
public <T> CompletableFuture<List<T>> query(String cql, @Nullable PreparedStatementBinder psb, RowMapper<T> rowMapper) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and aPreparedStatementBinderimplementation that knows how to bind values to the query, mapping each row to a Java object via aRowMapper.- Specified by:
queryin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.psb- object that knows how to set values on the prepared statement. If this is null, the CQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to set fetch size and other performance options.rowMapper- object that will map one object per row, must not be null.- Returns:
- the result
List, containing mapped objects. - Throws:
DataAccessException- if there is any problem executing the query.
-
queryForList
public CompletableFuture<List<Map<String,Object>>> queryForList(String cql, Object... args) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a resultList.The results will be mapped to a
List(one item for each row) ofMaps (one entry for each column, using the column name as the key). Each item in theListwill be of the form returned by this interface's queryForMap() methods.- Specified by:
queryForListin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.args- arguments to bind to the query (leaving it to thePreparedStatementto guess the corresponding CQL type).- Returns:
- a
Listthat contains aMapper row - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
queryForList
public <T> CompletableFuture<List<T>> queryForList(String cql, Class<T> elementType, Object... args) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a resultList.The results will be mapped to a
List(one item for each row) of result objects, each of them matching the specified element type.- Specified by:
queryForListin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.elementType- the required type of element in the resultList(for example,Integer.class), must not be null.args- arguments to bind to the query (leaving it to thePreparedStatementto guess the corresponding CQL type).- Returns:
- a
Listof objects that match the specified element type. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
queryForMap
public CompletableFuture<Map<String,Object>> queryForMap(String cql, Object... args) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a result Map. The queryForMap() methods defined by this interface are appropriate when you don't have a domain model. Otherwise, consider using one of the queryForObject() methods.The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
- Specified by:
queryForMapin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.args- arguments to bind to the query (leaving it to thePreparedStatementto guess the corresponding CQL type).- Returns:
- the result Map (one entry for each column, using the column name as the key).
- Throws:
IncorrectResultSizeDataAccessException- if the query does not return exactly one rowDataAccessException- if there is any problem executing the query.- See Also:
-
queryForObject
public <T> CompletableFuture<T> queryForObject(String cql, Class<T> requiredType, Object... args) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a result object.The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
- Specified by:
queryForObjectin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.requiredType- the type that the result object is expected to match, must not be null.args- arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding CQL type)- Returns:
- the result object of the required type, or null in case of CQL NULL.
- Throws:
IncorrectResultSizeDataAccessException- if the query does not return exactly one row, or does not return exactly one column in that row.DataAccessException- if there is any problem executing the query.- See Also:
-
queryForObject
public <T> CompletableFuture<T> queryForObject(String cql, RowMapper<T> rowMapper, Object... args) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, mapping a single result row to a Java object via aRowMapper.- Specified by:
queryForObjectin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.rowMapper- object that will map one object per row, must not be null.args- arguments to bind to the query (leaving it to thePreparedStatementto guess the corresponding CQL type)- Returns:
- the single mapped object
- Throws:
IncorrectResultSizeDataAccessException- if the query does not return exactly one row.DataAccessException- if there is any problem executing the query.
-
queryForResultSet
public CompletableFuture<com.datastax.oss.driver.api.core.cql.AsyncResultSet> queryForResultSet(String cql, Object... args) throws DataAccessException Description copied from interface:AsyncCqlOperationsQuery given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, expecting a ResultSet.The results will be mapped to an
ResultSet.- Specified by:
queryForResultSetin interfaceAsyncCqlOperations- Parameters:
cql- static CQL to execute, must not be null or empty.args- arguments to bind to the query (leaving it to thePreparedStatementto guess the corresponding CQL type).- Returns:
- a
ResultSetrepresentation. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
translateException
protected DataAccessException translateException(String task, @Nullable String cql, com.datastax.oss.driver.api.core.DriverException ex) Translate the givenDriverExceptioninto a genericDataAccessException.- Parameters:
task- readable text describing the task being attemptedcql- CQL query or update that caused the problem (may be null)ex- the offendingRuntimeException.- Returns:
- the exception translation
Function - See Also:
-
translateExceptionIfPossible
@Nullable protected DataAccessException translateExceptionIfPossible(String task, @Nullable String cql, RuntimeException ex) Translate the givenDriverExceptioninto a genericDataAccessException.- Parameters:
task- readable text describing the task being attemptedcql- CQL query or update that caused the problem (may be null)ex- the offendingRuntimeException.- Returns:
- the translated
DataAccessExceptionor null if translation not possible. - See Also:
-
newAsyncPreparedStatementCreator
Create a new CQL-basedAsyncPreparedStatementCreatorusing the CQL passed in. By default, we'll create anAsyncCqlTemplate.SimpleAsyncPreparedStatementCreator. This method allows for the creation to be overridden by subclasses.- Parameters:
cql- static CQL to execute, must not be empty or null.- Returns:
- the new
AsyncPreparedStatementCreatorto use
-
newAsyncResultSetExtractor
protected AsyncCqlTemplate.AsyncRowCallbackHandlerResultSetExtractor newAsyncResultSetExtractor(RowCallbackHandler rowCallbackHandler) Constructs a new instance of theResultSetExtractoradapting the givenRowCallbackHandler.- Parameters:
rowCallbackHandler-RowCallbackHandlerto adapt as aResultSetExtractor.- Returns:
- a
ResultSetExtractorimplementation adapting an instance of theRowCallbackHandler. - See Also:
-
newAsyncResultSetExtractor
protected <T> AsyncRowMapperResultSetExtractor<T> newAsyncResultSetExtractor(RowMapper<T> rowMapper) Constructs a new instance of theResultSetExtractoradapting the givenRowMapper.- Parameters:
rowMapper-RowMapperto adapt as aResultSetExtractor.- Returns:
- a
ResultSetExtractorimplementation adapting an instance of theRowMapper. - See Also:
-