public class CqlTemplate extends CassandraAccessor implements CqlOperations
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 ResultSetExtractor 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 Session reference, or get
prepared in an application context and given to services as bean reference. Note: The Session 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.
PreparedStatementCreator,
PreparedStatementBinder,
PreparedStatementCallback,
ResultSetExtractor,
RowCallbackHandler,
RowMapper,
PersistenceExceptionTranslatorCassandraAccessor.RowCallbackHandlerResultSetExtractorlogger| Constructor and Description |
|---|
CqlTemplate()
Create a new, uninitialized
CqlTemplate. |
CqlTemplate(com.datastax.driver.core.Session session)
Create a new
CqlTemplate initialized with the given Session. |
CqlTemplate(SessionFactory sessionFactory)
Constructs a new
CqlTemplate with the given SessionFactory. |
| Modifier and Type | Method and Description |
|---|---|
List<RingMember> |
describeRing()
Describe the current Ring.
|
<T> Collection<T> |
describeRing(HostMapper<T> hostMapper)
Describe the current Ring.
|
boolean |
execute(PreparedStatementCreator preparedStatementCreator)
Issue a single CQL execute operation (such as an insert, update or delete statement) using a
PreparedStatementCreator to provide CQL and any required parameters. |
<T> T |
execute(PreparedStatementCreator preparedStatementCreator,
PreparedStatementCallback<T> action)
Execute a CQL data access operation, implemented as callback action working on a CQL
PreparedStatement. |
<T> T |
execute(SessionCallback<T> action)
Execute a CQL data access operation, implemented as callback action working on a
Session. |
boolean |
execute(com.datastax.driver.core.Statement statement)
Issue a single CQL execute, typically a DDL statement, insert, update or delete statement.
|
boolean |
execute(String cql)
Issue a single CQL execute, typically a DDL statement, insert, update or delete statement.
|
boolean |
execute(String cql,
Object... args)
Issue a single CQL operation (such as an insert, update or delete statement) via a prepared statement, binding the
given arguments.
|
boolean |
execute(String cql,
PreparedStatementBinder psb)
Issue an statement using a
PreparedStatementBinder to set bind parameters, with given CQL. |
<T> T |
execute(String cql,
PreparedStatementCallback<T> action)
Execute a CQL data access operation, implemented as callback action working on a CQL
PreparedStatement. |
protected PreparedStatementCreator |
newPreparedStatementCreator(String cql)
Create a new CQL-based
PreparedStatementCreator using the CQL passed in. |
<T> T |
query(PreparedStatementCreator preparedStatementCreator,
PreparedStatementBinder psb,
ResultSetExtractor<T> resultSetExtractor)
Query using a prepared statement and a
PreparedStatementBinder implementation that knows how to bind values
to the query, reading the ResultSet with a ResultSetExtractor. |
void |
query(PreparedStatementCreator preparedStatementCreator,
PreparedStatementBinder psb,
RowCallbackHandler rowCallbackHandler)
Query using a prepared statement and a
PreparedStatementBinder implementation that knows how to bind values
to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler. |
<T> List<T> |
query(PreparedStatementCreator preparedStatementCreator,
PreparedStatementBinder psb,
RowMapper<T> rowMapper)
Query using a prepared statement and a
PreparedStatementBinder implementation that knows how to bind values
to the query, mapping each row to a Java object via a RowMapper. |
<T> T |
query(PreparedStatementCreator preparedStatementCreator,
ResultSetExtractor<T> resultSetExtractor)
Query using a prepared statement, reading the
ResultSet with a ResultSetExtractor. |
void |
query(PreparedStatementCreator preparedStatementCreator,
RowCallbackHandler rowCallbackHandler)
Query using a prepared statement, reading the
ResultSet on a per-row basis with a
RowCallbackHandler. |
<T> List<T> |
query(PreparedStatementCreator preparedStatementCreator,
RowMapper<T> rowMapper)
Query using a prepared statement, mapping each row to a Java object via a
RowMapper. |
<T> T |
query(com.datastax.driver.core.Statement statement,
ResultSetExtractor<T> resultSetExtractor)
Execute a query given static CQL, reading the
ResultSet with a ResultSetExtractor. |
void |
query(com.datastax.driver.core.Statement statement,
RowCallbackHandler rowCallbackHandler)
Execute a query given static CQL, reading the
ResultSet on a per-row basis with a
RowCallbackHandler. |
<T> List<T> |
query(com.datastax.driver.core.Statement statement,
RowMapper<T> rowMapper)
Execute a query given static CQL, mapping each row to a Java object via a
RowMapper. |
<T> T |
query(String cql,
PreparedStatementBinder psb,
ResultSetExtractor<T> resultSetExtractor)
Query using a prepared statement, reading the
ResultSet with a ResultSetExtractor. |
void |
query(String cql,
PreparedStatementBinder psb,
RowCallbackHandler rowCallbackHandler)
Query given CQL to create a prepared statement from CQL and a
PreparedStatementBinder implementation that
knows how to bind values to the query, reading the ResultSet on a per-row basis with a
RowCallbackHandler. |
<T> List<T> |
query(String cql,
PreparedStatementBinder psb,
RowMapper<T> rowMapper)
Query given CQL to create a prepared statement from CQL and a
PreparedStatementBinder implementation that
knows how to bind values to the query, mapping each row to a Java object via a RowMapper. |
<T> T |
query(String cql,
ResultSetExtractor<T> resultSetExtractor)
Execute a query given static CQL, reading the
ResultSet with a ResultSetExtractor. |
<T> T |
query(String cql,
ResultSetExtractor<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 the
ResultSet with a ResultSetExtractor. |
void |
query(String cql,
RowCallbackHandler rowCallbackHandler)
Execute a query given static CQL, reading the
ResultSet on a per-row basis with a
RowCallbackHandler. |
void |
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 the
ResultSet on a per-row basis with a RowCallbackHandler. |
<T> List<T> |
query(String cql,
RowMapper<T> rowMapper)
Execute a query given static CQL, mapping each row to a Java object via a
RowMapper. |
<T> List<T> |
query(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 each
row to a Java object via a
RowMapper. |
List<Map<String,Object>> |
queryForList(com.datastax.driver.core.Statement statement)
Execute a query for a result
List, given static CQL. |
<T> List<T> |
queryForList(com.datastax.driver.core.Statement statement,
Class<T> elementType)
Execute a query for a result
List, given static CQL. |
List<Map<String,Object>> |
queryForList(String cql)
Execute a query for a result
List, given static CQL. |
<T> List<T> |
queryForList(String cql,
Class<T> elementType)
Execute a query for a result
List, given static CQL. |
<T> 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
result
List. |
List<Map<String,Object>> |
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
result
List. |
Map<String,Object> |
queryForMap(com.datastax.driver.core.Statement statement)
Execute a query for a result Map, given static CQL.
|
Map<String,Object> |
queryForMap(String cql)
Execute a query for a result Map, given static CQL.
|
Map<String,Object> |
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> T |
queryForObject(com.datastax.driver.core.Statement statement,
Class<T> requiredType)
Execute a query for a result object, given static CQL.
|
<T> T |
queryForObject(com.datastax.driver.core.Statement statement,
RowMapper<T> rowMapper)
Execute a query given static CQL, mapping a single result row to a Java object via a
RowMapper. |
<T> T |
queryForObject(String cql,
Class<T> requiredType)
Execute a query for a result object, given static CQL.
|
<T> 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> T |
queryForObject(String cql,
RowMapper<T> rowMapper)
Execute a query given static CQL, mapping a single result row to a Java object via a
RowMapper. |
<T> 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 a
RowMapper. |
com.datastax.driver.core.ResultSet |
queryForResultSet(com.datastax.driver.core.Statement statement)
Execute a query for a ResultSet, given static CQL.
|
com.datastax.driver.core.ResultSet |
queryForResultSet(String cql)
Execute a query for a ResultSet, given static CQL.
|
com.datastax.driver.core.ResultSet |
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.
|
Iterable<com.datastax.driver.core.Row> |
queryForRows(com.datastax.driver.core.Statement statement)
Execute a query for Rows, given static CQL.
|
Iterable<com.datastax.driver.core.Row> |
queryForRows(String cql)
Execute a query for Rows, given static CQL.
|
Iterable<com.datastax.driver.core.Row> |
queryForRows(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
Rows.
|
protected DataAccessException |
translateException(String task,
String cql,
com.datastax.driver.core.exceptions.DriverException driverException)
Translate the given
DriverException into a generic DataAccessException. |
afterPropertiesSet, applyStatementSettings, applyStatementSettings, getConsistencyLevel, getExceptionTranslator, getFetchSize, getRetryPolicy, getSession, getSessionFactory, newColumnMapRowMapper, newPreparedStatementBinder, newResultSetExtractor, newResultSetExtractor, newResultSetExtractor, newSingleColumnRowMapper, setConsistencyLevel, setExceptionTranslator, setFetchSize, setRetryPolicy, setSession, setSessionFactory, toCql, translate, translateExceptionIfPossiblepublic CqlTemplate()
CqlTemplate. Note: The SessionFactory has to be set before using the
instance.public CqlTemplate(com.datastax.driver.core.Session session)
CqlTemplate initialized with the given Session.session - the active Cassandra Session.IllegalStateException - if Session is null.Sessionpublic CqlTemplate(SessionFactory sessionFactory)
CqlTemplate with the given SessionFactory.sessionFactory - the active Cassandra SessionFactory, must not be null.SessionFactorypublic <T> T execute(SessionCallback<T> action) throws DataAccessException
CqlOperationsSession. This allows for implementing arbitrary data access operations, within
Spring's managed CQL environment: that is, converting CQL
DriverExceptions into Spring's DataAccessException hierarchy.
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute in interface CqlOperationsaction - the callback object that specifies the action.DataAccessException - if there is any problem executing the query.public boolean execute(String cql) throws DataAccessException
CqlOperationsexecute in interface CqlOperationscql - static CQL to execute, must not be empty or null.DataAccessException - if there is any problem executing the query.@Nullable public <T> T query(String cql, ResultSetExtractor<T> resultSetExtractor) throws DataAccessException
CqlOperationsResultSet with a ResultSetExtractor.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded query method with null as argument array.
query in interface CqlOperationscql - static CQL to execute, must not be empty or null.resultSetExtractor - object that will extract all rows of results, must not be null.DataAccessException - if there is any problem executing the query.CqlOperations.query(String, ResultSetExtractor, Object...)public void query(String cql, RowCallbackHandler rowCallbackHandler) throws DataAccessException
CqlOperationsResultSet on a per-row basis with a
RowCallbackHandler.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded query method with null as argument array.
query in interface CqlOperationscql - static CQL to execute, must not be empty or null.rowCallbackHandler - object that will extract results, one row at a time, must not be null.DataAccessException - if there is any problem executing the query.CqlOperations.query(String, RowCallbackHandler, Object[])public <T> List<T> query(String cql, RowMapper<T> rowMapper) throws DataAccessException
CqlOperationsRowMapper.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded query method with null as argument array.
query in interface CqlOperationscql - static CQL to execute, must not be empty or null.rowMapper - object that will map one object per row, must not be null.List, containing mapped objects.DataAccessException - if there is any problem executing the query.CqlOperations.query(String, RowMapper, Object[])public List<Map<String,Object>> queryForList(String cql) throws DataAccessException
CqlOperationsList, given static CQL.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded queryForList method with null as argument array.
The results will be mapped to a List (one item for each row) of Maps (one entry for each column
using the column name as the key). Each item in the List will be of the form returned by this interface's
queryForMap() methods.
queryForList in interface CqlOperationscql - static CQL to execute, must not be empty or null.List that contains a Map per row.DataAccessException - if there is any problem executing the query.CqlOperations.queryForList(String, Object[])public <T> List<T> queryForList(String cql, Class<T> elementType) throws DataAccessException
CqlOperationsList, given static CQL.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded queryForList method 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.
queryForList in interface CqlOperationscql - static CQL to execute, must not be empty or null.elementType - the required type of element in the result List (for example, Integer.class),
must not be null.List of objects that match the specified element type.DataAccessException - if there is any problem executing the query.CqlOperations.queryForList(String, Class, Object[]),
SingleColumnRowMapperpublic Map<String,Object> queryForMap(String cql) throws DataAccessException
CqlOperations
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded CqlOperations.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).
queryForMap in interface CqlOperationscql - static CQL to execute, must not be empty or null.IncorrectResultSizeDataAccessException - if the query does not return exactly one row.DataAccessException - if there is any problem executing the query.CqlOperations.queryForMap(String, Object[]),
ColumnMapRowMapperpublic <T> T queryForObject(String cql, Class<T> requiredType) throws DataAccessException
CqlOperations
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded CqlOperations.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.
queryForObject in interface CqlOperationscql - static CQL to execute, must not be empty or null.requiredType - the type that the result object is expected to match, must not be null.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.CqlOperations.queryForObject(String, Class, Object[])public <T> T queryForObject(String cql, RowMapper<T> rowMapper) throws DataAccessException
CqlOperationsRowMapper.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded CqlOperations.queryForObject(String, RowMapper, Object...) method with
null as argument array.
queryForObject in interface CqlOperationscql - static CQL to execute, must not be empty or null.rowMapper - object that will map one object per row, must not be null.IncorrectResultSizeDataAccessException - if the query does not return exactly one row.DataAccessException - if there is any problem executing the query.CqlOperations.queryForObject(String, RowMapper, Object[])public com.datastax.driver.core.ResultSet queryForResultSet(String cql) throws DataAccessException
CqlOperations
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded queryForResultSet method with null as argument
array.
The results will be mapped to an ResultSet.
queryForResultSet in interface CqlOperationscql - static CQL to execute, must not be empty or null.ResultSet representation.DataAccessException - if there is any problem executing the query.CqlOperations.queryForResultSet(String, Object[])public Iterable<com.datastax.driver.core.Row> queryForRows(String cql) throws DataAccessException
CqlOperations
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded queryForResultSet method with null as argument
array.
The results will be mapped to Rows.
queryForRows in interface CqlOperationscql - static CQL to execute, must not be empty or null.DataAccessException - if there is any problem executing the query.CqlOperations.queryForResultSet(String, Object[])public boolean execute(com.datastax.driver.core.Statement statement)
throws DataAccessException
CqlOperationsexecute in interface CqlOperationsstatement - static CQL Statement, must not be null.DataAccessException - if there is any problem executing the query.public <T> T query(com.datastax.driver.core.Statement statement,
ResultSetExtractor<T> resultSetExtractor)
throws DataAccessException
CqlOperationsResultSet with a ResultSetExtractor.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded query method with null as argument array.
query in interface CqlOperationsstatement - static CQL Statement, must not be null.resultSetExtractor - object that will extract all rows of results, must not be null.DataAccessException - if there is any problem executing the query.CqlOperations.query(String, ResultSetExtractor, Object...)public void query(com.datastax.driver.core.Statement statement,
RowCallbackHandler rowCallbackHandler)
throws DataAccessException
CqlOperationsResultSet on a per-row basis with a
RowCallbackHandler.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded query method with null as argument array.
query in interface CqlOperationsstatement - static CQL Statement, must not be null.rowCallbackHandler - object that will extract results, one row at a time, must not be null.DataAccessException - if there is any problem executing the query.CqlOperations.query(String, RowCallbackHandler, Object[])public <T> List<T> query(com.datastax.driver.core.Statement statement, RowMapper<T> rowMapper) throws DataAccessException
CqlOperationsRowMapper.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded query method with null as argument array.
query in interface CqlOperationsstatement - static CQL Statement, must not be null.rowMapper - object that will map one object per row, must not be null.List, containing mapped objects.DataAccessException - if there is any problem executing the query.CqlOperations.query(String, RowMapper, Object[])public List<Map<String,Object>> queryForList(com.datastax.driver.core.Statement statement) throws DataAccessException
CqlOperationsList, given static CQL.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded queryForList method with null as argument array.
The results will be mapped to a List (one item for each row) of Maps (one entry for each column
using the column name as the key). Each item in the List will be of the form returned by this interface's
queryForMap() methods.
queryForList in interface CqlOperationsstatement - static CQL Statement to execute, must not be empty or null.List that contains a Map per row.DataAccessException - if there is any problem executing the query.CqlOperations.queryForList(String, Object[])public <T> List<T> queryForList(com.datastax.driver.core.Statement statement, Class<T> elementType) throws DataAccessException
CqlOperationsList, given static CQL.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded queryForList method 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.
queryForList in interface CqlOperationsstatement - static CQL Statement, must not be null.elementType - the required type of element in the result List (for example, Integer.class),
must not be null.List of objects that match the specified element type.DataAccessException - if there is any problem executing the query.CqlOperations.queryForList(String, Class, Object[]),
SingleColumnRowMapperpublic Map<String,Object> queryForMap(com.datastax.driver.core.Statement statement) throws DataAccessException
CqlOperations
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded CqlOperations.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).
queryForMap in interface CqlOperationsstatement - static CQL Statement, must not be null.IncorrectResultSizeDataAccessException - if the query does not return exactly one row.DataAccessException - if there is any problem executing the query.CqlOperations.queryForMap(String, Object[]),
ColumnMapRowMapperpublic <T> T queryForObject(com.datastax.driver.core.Statement statement,
Class<T> requiredType)
throws DataAccessException
CqlOperations
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded CqlOperations.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.
queryForObject in interface CqlOperationsstatement - static CQL Statement, must not be null.requiredType - the type that the result object is expected to match, must not be null.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.CqlOperations.queryForObject(String, Class, Object[])public <T> T queryForObject(com.datastax.driver.core.Statement statement,
RowMapper<T> rowMapper)
throws DataAccessException
CqlOperationsRowMapper.
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded CqlOperations.queryForObject(String, RowMapper, Object...) method with
null as argument array.
queryForObject in interface CqlOperationsstatement - static CQL Statement, must not be null.rowMapper - object that will map one object per row, must not be null.IncorrectResultSizeDataAccessException - if the query does not return exactly one row.DataAccessException - if there is any problem executing the query.CqlOperations.queryForObject(String, RowMapper, Object[])public com.datastax.driver.core.ResultSet queryForResultSet(com.datastax.driver.core.Statement statement)
throws DataAccessException
CqlOperations
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded queryForResultSet method with null as argument
array.
The results will be mapped to an ResultSet.
queryForResultSet in interface CqlOperationsstatement - static CQL Statement, must not be null.ResultSet representation.DataAccessException - if there is any problem executing the query.CqlOperations.queryForResultSet(String, Object[])public Iterable<com.datastax.driver.core.Row> queryForRows(com.datastax.driver.core.Statement statement) throws DataAccessException
CqlOperations
Uses a CQL Statement, not a PreparedStatement. If you want to execute a static query with a
PreparedStatement, use the overloaded queryForResultSet method with null as argument
array.
The results will be mapped to Rows.
queryForRows in interface CqlOperationsstatement - static CQL Statement, must not be null.DataAccessException - if there is any problem executing the query.CqlOperations.queryForResultSet(String, Object[])public boolean execute(String cql, Object... args) throws DataAccessException
CqlOperationsexecute in interface CqlOperationscql - static CQL to execute, must not be empty or null.args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding
CQL type).DataAccessException - if there is any problem executing the query.public boolean execute(String cql, @Nullable PreparedStatementBinder psb) throws DataAccessException
CqlOperationsPreparedStatementBinder to set bind parameters, with given CQL. Simpler than
using a PreparedStatementCreator as this method will create the PreparedStatement: The
PreparedStatementBinder just needs to set parameters.execute in interface CqlOperationscql - static CQL to execute, must not be empty or 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.DataAccessException - if there is any problem executing the query.@Nullable public <T> T execute(String cql, PreparedStatementCallback<T> action) throws DataAccessException
CqlOperationsPreparedStatement.
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 CQL
DriverExceptions into Spring's DataAccessException hierarchy.
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute in interface CqlOperationscql - static CQL to execute, must not be empty or null.action - callback object that specifies the action, must not be null.DataAccessException - if there is any problem executing the query.public boolean execute(PreparedStatementCreator preparedStatementCreator) throws DataAccessException
CqlOperationsPreparedStatementCreator to provide CQL and any required parameters.execute in interface CqlOperationspreparedStatementCreator - object that provides CQL and any necessary parameters, must not be null.DataAccessException - if there is any problem executing the query.@Nullable public <T> T execute(PreparedStatementCreator preparedStatementCreator, PreparedStatementCallback<T> action) throws DataAccessException
CqlOperationsPreparedStatement.
This allows for implementing arbitrary data access operations on a single PreparedStatement, within
Spring's managed CQL environment: that is, participating in Spring-managed transactions and converting CQL
DriverExceptions into Spring's DataAccessException hierarchy.
The callback action can return a result object, for example a domain object or a collection of domain objects.
execute in interface CqlOperationspreparedStatementCreator - object that can create a PreparedStatement given a
Session, must not be null.action - callback object that specifies the action, must not be null.DataAccessException - if there is any problem executing the query.public <T> T query(PreparedStatementCreator preparedStatementCreator, ResultSetExtractor<T> resultSetExtractor) throws DataAccessException
CqlOperationsResultSet with a ResultSetExtractor.query in interface CqlOperationspreparedStatementCreator - object that can create a PreparedStatement given a
Session, must not be null.resultSetExtractor - object that will extract results, must not be null.ResultSetExtractorDataAccessException - if there is any problem executing the query.public void query(PreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler) throws DataAccessException
CqlOperationsResultSet on a per-row basis with a
RowCallbackHandler.query in interface CqlOperationspreparedStatementCreator - object that can create a PreparedStatement given a
Session, must not be null.rowCallbackHandler - object that will extract results, one row at a time, must not be null.DataAccessException - if there is any problem executing the query.public <T> List<T> query(PreparedStatementCreator preparedStatementCreator, RowMapper<T> rowMapper) throws DataAccessException
CqlOperationsRowMapper.query in interface CqlOperationspreparedStatementCreator - object that can create a PreparedStatement given a
Session, must not be null.rowMapper - object that will map one object per row, must not be null.List, containing mapped objects.DataAccessException - if there is any problem executing the query.@Nullable public <T> T query(PreparedStatementCreator preparedStatementCreator, @Nullable PreparedStatementBinder psb, ResultSetExtractor<T> resultSetExtractor) throws DataAccessException
CqlOperationsPreparedStatementBinder implementation that knows how to bind values
to the query, reading the ResultSet with a ResultSetExtractor.query in interface CqlOperationspreparedStatementCreator - object that can create a PreparedStatement given a
Session, 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.ResultSetExtractor.DataAccessException - if there is any problem executing the query.public void query(PreparedStatementCreator preparedStatementCreator, @Nullable PreparedStatementBinder psb, RowCallbackHandler rowCallbackHandler) throws DataAccessException
CqlOperationsPreparedStatementBinder implementation that knows how to bind values
to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.query in interface CqlOperationspreparedStatementCreator - object that can create a PreparedStatement given a
Session, 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.DataAccessException - if there is any problem executing the query.public <T> List<T> query(PreparedStatementCreator preparedStatementCreator, @Nullable PreparedStatementBinder psb, RowMapper<T> rowMapper) throws DataAccessException
CqlOperationsPreparedStatementBinder implementation that knows how to bind values
to the query, mapping each row to a Java object via a RowMapper.query in interface CqlOperationspreparedStatementCreator - object that can create a PreparedStatement given a
Session, 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.List, containing mapped objects.DataAccessException - if there is any problem executing the query.public <T> T query(String cql, ResultSetExtractor<T> resultSetExtractor, Object... args) throws DataAccessException
CqlOperationsResultSet with a ResultSetExtractor.query in interface CqlOperationscql - static CQL to execute, must not be empty or null.resultSetExtractor - object that will extract results, must not be null.args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding
CQL type).ResultSetExtractorDataAccessException - if there is any problem executing the query.public void query(String cql, RowCallbackHandler rowCallbackHandler, Object... args) throws DataAccessException
CqlOperationsResultSet on a per-row basis with a RowCallbackHandler.query in interface CqlOperationscql - static CQL to execute, must not be empty or null.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 the PreparedStatement to guess the corresponding
CQL type)DataAccessException - if there is any problem executing the query.public <T> List<T> query(String cql, RowMapper<T> rowMapper, Object... args) throws DataAccessException
CqlOperationsRowMapper.query in interface CqlOperationscql - static CQL to execute, must not be empty or null.rowMapper - object that will map one object per rowargs - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding
CQL type)List, containing mapped objectsDataAccessException - if there is any problem executing the query.public <T> T query(String cql, @Nullable PreparedStatementBinder psb, ResultSetExtractor<T> resultSetExtractor) throws DataAccessException
CqlOperationsResultSet with a ResultSetExtractor.query in interface CqlOperationscql - static CQL to execute, must not be empty or 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.ResultSetExtractor.DataAccessException - if there is any problem executing the query.public void query(String cql, @Nullable PreparedStatementBinder psb, RowCallbackHandler rowCallbackHandler) throws DataAccessException
CqlOperationsPreparedStatementBinder implementation that
knows how to bind values to the query, reading the ResultSet on a per-row basis with a
RowCallbackHandler.query in interface CqlOperationscql - static CQL to execute, must not be empty or 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.DataAccessException - if there is any problem executing the query.public <T> List<T> query(String cql, @Nullable PreparedStatementBinder psb, RowMapper<T> rowMapper) throws DataAccessException
CqlOperationsPreparedStatementBinder implementation that
knows how to bind values to the query, mapping each row to a Java object via a RowMapper.query in interface CqlOperationscql - static CQL to execute, must not be empty or 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.List, containing mapped objects.DataAccessException - if there is any problem executing the query.public List<Map<String,Object>> queryForList(String cql, Object... args) throws DataAccessException
CqlOperationsList.
The results will be mapped to a List (one item for each row) of Maps (one entry for each column,
using the column name as the key). Each item in the List will be of the form returned by this interface's
queryForMap() methods.
queryForList in interface CqlOperationscql - static CQL to execute, must not be empty or null.args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding
CQL type).List that contains a Map per rowDataAccessException - if there is any problem executing the query.CqlOperations.queryForList(String)public <T> List<T> queryForList(String cql, Class<T> elementType, Object... args) throws DataAccessException
CqlOperationsList.
The results will be mapped to a List (one item for each row) of result objects, each of them matching the
specified element type.
queryForList in interface CqlOperationscql - static CQL to execute, must not be empty or null.elementType - the required type of element in the result List (for example, Integer.class),
must not be null.args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding
CQL type).List of objects that match the specified element type.DataAccessException - if there is any problem executing the query.CqlOperations.queryForList(String, Class),
SingleColumnRowMapperpublic Map<String,Object> queryForMap(String cql, Object... args) throws DataAccessException
CqlOperationsThe 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).
queryForMap in interface CqlOperationscql - static CQL to execute, must not be empty or null.args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding
CQL type).IncorrectResultSizeDataAccessException - if the query does not return exactly one rowDataAccessException - if there is any problem executing the query.CqlOperations.queryForMap(String),
ColumnMapRowMapperpublic <T> T queryForObject(String cql, Class<T> requiredType, Object... args) throws DataAccessException
CqlOperationsThe query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.
queryForObject in interface CqlOperationscql - static CQL to execute, must not be empty or null.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)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.CqlOperations.queryForObject(String, Class)public <T> T queryForObject(String cql, RowMapper<T> rowMapper, Object... args) throws DataAccessException
CqlOperationsRowMapper.queryForObject in interface CqlOperationscql - static CQL to execute, must not be empty or null.rowMapper - object that will map one object per row, must not be null.args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding
CQL type)IncorrectResultSizeDataAccessException - if the query does not return exactly one row.DataAccessException - if there is any problem executing the query.public com.datastax.driver.core.ResultSet queryForResultSet(String cql, Object... args) throws DataAccessException
CqlOperations
The results will be mapped to an ResultSet.
queryForResultSet in interface CqlOperationscql - static CQL to execute, must not be empty or null.args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding
CQL type).ResultSet representation.DataAccessException - if there is any problem executing the query.CqlOperations.queryForResultSet(String)public Iterable<com.datastax.driver.core.Row> queryForRows(String cql, Object... args) throws DataAccessException
CqlOperations
The results will be mapped to Rows.
queryForRows in interface CqlOperationscql - static CQL to execute, must not be empty or null.args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding
CQL type).Row representation.DataAccessException - if there is any problem executing the query.CqlOperations.queryForResultSet(String)public List<RingMember> describeRing() throws DataAccessException
CqlOperationsRingMemberHostMapper to provide the basics of the
Cassandra Ring topology.describeRing in interface CqlOperationsDataAccessException - if there is any problem executing the query.public <T> Collection<T> describeRing(HostMapper<T> hostMapper) throws DataAccessException
CqlOperationsHostMapper implementation to process the
lists of hosts returned by the Cassandra Cluster Metadata.describeRing in interface CqlOperationshostMapper - The implementation to use for host mapping.DataAccessException - if there is any problem executing the query.protected PreparedStatementCreator newPreparedStatementCreator(String cql)
PreparedStatementCreator using the CQL passed in. By default, we'll create an
SimplePreparedStatementCreator. This method allows for the creation to be overridden by subclasses.cql - static CQL to execute, must not be empty or null.PreparedStatementCreator to useprotected DataAccessException translateException(String task, @Nullable String cql, com.datastax.driver.core.exceptions.DriverException driverException)
DriverException into a generic DataAccessException.task - readable text describing the task being attemptedcql - CQL query or update that caused the problem (may be null)driverException - the offending RuntimeException.FunctionCqlProviderCopyright © 2011–2018 Pivotal Software, Inc.. All rights reserved.