public class CqlTemplate extends CassandraAccessor implements CqlOperations
CqlTemplate
simplifies the use of Cassandra
and helps to avoid common errors. The template executes the core Cassandra workflow, leaving application code to
provide CQL and result handling. The template executes CQL queries, provides different ways to extract and map
results, and provides Exception translation to the generic, more informative exception hierarchy defined in the
org.springframework.dao
package.
For working with POJOs, use the CassandraTemplate.
CqlOperations
,
CassandraAccessor
Modifier and Type | Field and Description |
---|---|
protected static ResultSetExtractor<com.datastax.driver.core.ResultSet> |
RESULT_SET_RETURNING_EXTRACTOR |
protected static Executor |
RUN_RUNNABLE_EXECUTOR |
logger
Constructor and Description |
---|
CqlTemplate()
Constructs an uninitialized instance of
CqlTemplate . |
CqlTemplate(com.datastax.driver.core.Session session)
Constructs an instance of
CqlTemplate initialized with the given Session . |
Modifier and Type | Method and Description |
---|---|
static com.datastax.driver.core.PreparedStatement |
addPreparedStatementOptions(com.datastax.driver.core.PreparedStatement preparedStatement,
QueryOptions queryOptions)
Add common
QueryOptions to Cassandra PreparedStatement s. |
static <T extends com.datastax.driver.core.Statement> |
addQueryOptions(T statement,
QueryOptions queryOptions)
Add common
QueryOptions to all types of queries. |
static com.datastax.driver.core.querybuilder.Insert |
addWriteOptions(com.datastax.driver.core.querybuilder.Insert insert,
WriteOptions writeOptions)
Add common
WriteOptions options to Insert CQL statements. |
static com.datastax.driver.core.querybuilder.Update |
addWriteOptions(com.datastax.driver.core.querybuilder.Update update,
WriteOptions writeOptions)
Add common
WriteOptions options to Update CQL statements. |
long |
count(CqlIdentifier tableName)
Counts all rows for given table
|
long |
count(String tableName)
Counts all rows for given table
|
List<RingMember> |
describeRing()
Describe the current Ring.
|
<T> Collection<T> |
describeRing(HostMapper<T> hostMapper)
Describe the current Ring.
|
protected <T> T |
doExecute(SessionCallback<T> callback)
Executes the given command in a Cassandra
Session . |
protected com.datastax.driver.core.ResultSet |
doExecute(com.datastax.driver.core.Statement statement)
Execute a command at the Session Level with optional options
|
protected com.datastax.driver.core.ResultSet |
doExecute(String cql) |
protected com.datastax.driver.core.ResultSet |
doExecute(String cql,
QueryOptions queryOptions) |
protected com.datastax.driver.core.ResultSetFuture |
doExecuteAsync(com.datastax.driver.core.Statement statement) |
protected Cancellable |
doExecuteAsync(com.datastax.driver.core.Statement statement,
AsynchronousQueryListener listener) |
protected Cancellable |
doExecuteAsync(com.datastax.driver.core.Statement statement,
AsynchronousQueryListener listener,
QueryOptions queryOptions) |
protected com.datastax.driver.core.ResultSet |
doExecuteQueryReturnResultSet(com.datastax.driver.core.querybuilder.Select select) |
protected com.datastax.driver.core.ResultSet |
doExecuteQueryReturnResultSet(String query) |
com.datastax.driver.core.ResultSet |
execute(AlterKeyspaceSpecification specification)
Convenience method to convert the given specification to CQL and execute it.
|
com.datastax.driver.core.ResultSet |
execute(AlterTableSpecification specification)
Convenience method to convert the given specification to CQL and execute it.
|
void |
execute(com.datastax.driver.core.querybuilder.Batch batch)
Executes the supplied Batch Query and returns nothing.
|
com.datastax.driver.core.ResultSet |
execute(CreateIndexSpecification specification)
Convenience method to convert the given specification to CQL and execute it.
|
com.datastax.driver.core.ResultSet |
execute(CreateKeyspaceSpecification specification)
Convenience method to convert the given specification to CQL and execute it.
|
com.datastax.driver.core.ResultSet |
execute(CreateTableSpecification specification)
Convenience method to convert the given specification to CQL and execute it.
|
void |
execute(com.datastax.driver.core.querybuilder.Delete delete)
Executes the supplied Delete Query and returns nothing.
|
com.datastax.driver.core.ResultSet |
execute(DropIndexSpecification specification)
Convenience method to convert the given specification to CQL and execute it.
|
com.datastax.driver.core.ResultSet |
execute(DropKeyspaceSpecification specification)
Convenience method to convert the given specification to CQL and execute it.
|
com.datastax.driver.core.ResultSet |
execute(DropTableSpecification specification)
Convenience method to convert the given specification to CQL and execute it.
|
void |
execute(com.datastax.driver.core.querybuilder.Insert insert)
Executes the supplied Insert Query and returns nothing.
|
<T> T |
execute(PreparedStatementCreator preparedStatementCreator,
PreparedStatementCallback<T> preparedStatementCallback)
Uses the provided
PreparedStatementCreator to create a PreparedStatement in the current
Session , then passes that PreparedStatement to the given PreparedStatementCallback . |
<T> T |
execute(SessionCallback<T> sessionCallback)
Executes the supplied
SessionCallback in the current Template Session. |
void |
execute(com.datastax.driver.core.Statement statement)
Executes the supplied Query and returns nothing.
|
void |
execute(String cql)
Executes the supplied CQL Query and returns nothing.
|
<T> T |
execute(String cql,
PreparedStatementCallback<T> callback)
Creates and caches a
PreparedStatement from the given CQL, invokes the PreparedStatementCallback
with that PreparedStatement , then returns the value returned by the PreparedStatementCallback . |
void |
execute(String cql,
QueryOptions options)
Executes the supplied CQL Query and returns nothing.
|
void |
execute(com.datastax.driver.core.querybuilder.Truncate truncate)
Executes the supplied Truncate Query and returns nothing.
|
void |
execute(com.datastax.driver.core.querybuilder.Update update)
Executes the supplied Update Query and returns nothing.
|
com.datastax.driver.core.ResultSetFuture |
executeAsynchronously(com.datastax.driver.core.querybuilder.Batch batch)
Executes the supplied CQL Batch Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(com.datastax.driver.core.querybuilder.Batch batch,
AsynchronousQueryListener listener) |
com.datastax.driver.core.ResultSetFuture |
executeAsynchronously(com.datastax.driver.core.querybuilder.Delete delete)
Executes the supplied CQL Delete Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(com.datastax.driver.core.querybuilder.Delete delete,
AsynchronousQueryListener listener) |
com.datastax.driver.core.ResultSetFuture |
executeAsynchronously(com.datastax.driver.core.querybuilder.Insert insert)
Executes the supplied CQL Insert Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(com.datastax.driver.core.querybuilder.Insert insert,
AsynchronousQueryListener listener) |
com.datastax.driver.core.ResultSetFuture |
executeAsynchronously(com.datastax.driver.core.Statement statement)
Executes the supplied CQL Query Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(com.datastax.driver.core.Statement statement,
AsynchronousQueryListener listener)
Executes the supplied CQL Query Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(com.datastax.driver.core.Statement statement,
AsynchronousQueryListener listener,
Executor executor)
Executes the supplied CQL Query Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(com.datastax.driver.core.Statement statement,
Runnable listener)
Executes the supplied CQL Query Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(com.datastax.driver.core.Statement statement,
Runnable listener,
Executor executor)
Executes the supplied CQL Query Asynchronously and returns nothing.
|
com.datastax.driver.core.ResultSetFuture |
executeAsynchronously(String cql)
Executes the supplied Query Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(String cql,
AsynchronousQueryListener listener)
Executes the supplied Query Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(String cql,
AsynchronousQueryListener listener,
Executor executor)
Executes the supplied Query Asynchronously and returns nothing.
|
com.datastax.driver.core.ResultSetFuture |
executeAsynchronously(String cql,
QueryOptions queryOptions)
Executes the supplied Query Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(String cql,
Runnable listener)
Executes the supplied Query Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(String cql,
Runnable listener,
Executor executor)
Executes the supplied Query Asynchronously and returns nothing.
|
com.datastax.driver.core.ResultSetFuture |
executeAsynchronously(com.datastax.driver.core.querybuilder.Truncate truncate)
Executes the supplied CQL Truncate Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(com.datastax.driver.core.querybuilder.Truncate truncate,
AsynchronousQueryListener listener) |
com.datastax.driver.core.ResultSetFuture |
executeAsynchronously(com.datastax.driver.core.querybuilder.Update update)
Executes the supplied CQL Update Asynchronously and returns nothing.
|
Cancellable |
executeAsynchronously(com.datastax.driver.core.querybuilder.Update update,
AsynchronousQueryListener listener) |
protected Object |
firstColumnToObject(com.datastax.driver.core.Row row) |
protected Set<com.datastax.driver.core.Host> |
getHosts()
Requests the set of hosts in the Cassandra cluster from the current
Session . |
com.datastax.driver.core.ResultSet |
getResultSetUninterruptibly(com.datastax.driver.core.ResultSetFuture resultSetFuture)
Convenient method that delegates to
ResultSetFuture.getUninterruptibly() but translates exceptions if any
are thrown. |
com.datastax.driver.core.ResultSet |
getResultSetUninterruptibly(com.datastax.driver.core.ResultSetFuture resultSetFuture,
long milliseconds)
Convenient method that delegates to
ResultSetFuture.getUninterruptibly() but translates exceptions if any
are thrown. |
com.datastax.driver.core.ResultSet |
getResultSetUninterruptibly(com.datastax.driver.core.ResultSetFuture resultSetFuture,
long timeout,
TimeUnit timeUnit)
Convenient method that delegates to
ResultSetFuture.getUninterruptibly() but translates exceptions if any
are thrown. |
void |
ingest(String cql,
List<List<?>> rows)
This is an operation designed for high performance writes.
|
void |
ingest(String cql,
List<List<?>> rows,
WriteOptions writeOptions)
This is an operation designed for high performance writes.
|
void |
ingest(String cql,
Object[][] rows)
This is an operation designed for high performance writes.
|
void |
ingest(String cql,
Object[][] rows,
WriteOptions writeOptions)
This is an operation designed for high performance writes.
|
void |
ingest(String cql,
RowIterator rowIterator)
This is an operation designed for high performance writes.
|
void |
ingest(String cql,
RowIterator rowIterator,
WriteOptions options)
This is an operation designed for high performance writes.
|
protected String |
logCql(String cql) |
protected String |
logCql(String message,
String cql) |
protected <T extends com.datastax.driver.core.Statement> |
logStatement(T statement) |
void |
process(com.datastax.driver.core.ResultSet resultSet,
RowCallbackHandler rowCallbackHandler)
Processes the ResultSet through the RowCallbackHandler and return nothing.
|
<T> List<T> |
process(com.datastax.driver.core.ResultSet resultSet,
RowMapper<T> rowMapper)
Processes the ResultSet through the RowMapper and returns the List of mapped Rows.
|
<T> List<T> |
processList(com.datastax.driver.core.ResultSet resultSet,
Class<T> elementType)
Process a ResultSet and convert the first column of the results to a List.
|
List<Map<String,Object>> |
processListOfMap(com.datastax.driver.core.ResultSet resultSet)
Process a ResultSet and convert it to a List of Maps with column/value.
|
Map<String,Object> |
processMap(com.datastax.driver.core.ResultSet resultSet)
Process a ResultSet with ONE Row and convert to a Map.
|
<T> T |
processOne(com.datastax.driver.core.ResultSet resultSet,
Class<T> requiredType)
Process a ResultSet, trying to convert the first columns of the first Row to Class
|
<T> T |
processOne(com.datastax.driver.core.ResultSet resultSet,
RowMapper<T> rowMapper)
Process
ResultSet with RowMapper . |
<T> T |
query(PreparedStatementCreator preparedStatementCreator,
PreparedStatementBinder preparedStatementBinder,
ResultSetExtractor<T> resultSetExtractor)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
<T> T |
query(PreparedStatementCreator preparedStatementCreator,
PreparedStatementBinder preparedStatementBinder,
ResultSetExtractor<T> resultSetExtractor,
QueryOptions queryOptions)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
void |
query(PreparedStatementCreator preparedStatementCreator,
PreparedStatementBinder preparedStatementBinder,
RowCallbackHandler rowCallbackHandler)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
void |
query(PreparedStatementCreator preparedStatementCreator,
PreparedStatementBinder preparedStatementBinder,
RowCallbackHandler rowCallbackHandler,
QueryOptions queryOptions)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
<T> List<T> |
query(PreparedStatementCreator preparedStatementCreator,
PreparedStatementBinder preparedStatementBinder,
RowMapper<T> rowMapper)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
<T> List<T> |
query(PreparedStatementCreator preparedStatementCreator,
PreparedStatementBinder preparedStatementBinder,
RowMapper<T> rowMapper,
QueryOptions queryOptions)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
<T> T |
query(PreparedStatementCreator preparedStatementCreator,
ResultSetExtractor<T> resultSetExtractor)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
<T> T |
query(PreparedStatementCreator preparedStatementCreator,
ResultSetExtractor<T> resultSetExtractor,
QueryOptions queryOptions)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
void |
query(PreparedStatementCreator preparedStatementCreator,
RowCallbackHandler rowCallbackHandler)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
void |
query(PreparedStatementCreator preparedStatementCreator,
RowCallbackHandler rowCallbackHandler,
QueryOptions queryOptions)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
<T> List<T> |
query(PreparedStatementCreator preparedStatementCreator,
RowMapper<T> rowMapper)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
<T> List<T> |
query(PreparedStatementCreator preparedStatementCreator,
RowMapper<T> rowMapper,
QueryOptions queryOptions)
Uses the provided PreparedStatementCreator to prepare a new Session call.
|
com.datastax.driver.core.ResultSet |
query(com.datastax.driver.core.querybuilder.Select select)
Executes the provided Select query and returns the
ResultSet . |
<T> T |
query(com.datastax.driver.core.querybuilder.Select select,
ResultSetExtractor<T> resultSetExtractor)
Executes the provided Select Query, and extracts the results with the ResultSetExtractor.
|
void |
query(com.datastax.driver.core.querybuilder.Select select,
RowCallbackHandler rowCallbackHandler)
Executes the provided Select Query, and then processes the results with the
RowCallbackHandler . |
<T> List<T> |
query(com.datastax.driver.core.querybuilder.Select select,
RowMapper<T> rowMapper)
Executes the provided Select Query, and maps all Rows returned with the supplied RowMapper.
|
com.datastax.driver.core.ResultSet |
query(String cql)
Executes the provided CQL query and returns the
ResultSet . |
<T> T |
query(String cql,
PreparedStatementBinder preparedStatementBinder,
ResultSetExtractor<T> resultSetExtractor)
Converts the CQL provided into a
CachedPreparedStatementCreator . |
<T> T |
query(String cql,
PreparedStatementBinder preparedStatementBinder,
ResultSetExtractor<T> resultSetExtractor,
QueryOptions queryOptions)
Converts the CQL provided into a
CachedPreparedStatementCreator . |
void |
query(String cql,
PreparedStatementBinder preparedStatementBinder,
RowCallbackHandler rowCallbackHandler)
Converts the CQL provided into a
CachedPreparedStatementCreator . |
void |
query(String cql,
PreparedStatementBinder preparedStatementBinder,
RowCallbackHandler rowCallbackHandler,
QueryOptions queryOptions)
Converts the CQL provided into a
CachedPreparedStatementCreator . |
<T> List<T> |
query(String cql,
PreparedStatementBinder preparedStatementBinder,
RowMapper<T> rowMapper)
Converts the CQL provided into a
CachedPreparedStatementCreator . |
<T> List<T> |
query(String cql,
PreparedStatementBinder preparedStatementBinder,
RowMapper<T> rowMapper,
QueryOptions queryOptions)
Converts the CQL provided into a
CachedPreparedStatementCreator . |
com.datastax.driver.core.ResultSet |
query(String cql,
QueryOptions queryOptions)
Executes the provided CQL query with the given
QueryOptions and returns the ResultSet . |
<T> T |
query(String cql,
ResultSetExtractor<T> resultSetExtractor)
Executes the provided CQL Query, and extracts the results with the ResultSetExtractor.
|
<T> T |
query(String cql,
ResultSetExtractor<T> resultSetExtractor,
QueryOptions queryOptions)
Executes the provided CQL Query, and extracts the results with the ResultSetExtractor.
|
void |
query(String cql,
RowCallbackHandler rowCallbackHandler)
Executes the provided CQL Query, and then processes the results with the
RowCallbackHandler . |
void |
query(String cql,
RowCallbackHandler rowCallbackHandler,
QueryOptions queryOptions)
Executes the provided CQL Query, and then processes the results with the
RowCallbackHandler . |
<T> List<T> |
query(String cql,
RowMapper<T> rowMapper)
Executes the provided CQL Query, and maps all Rows returned with the supplied RowMapper.
|
<T> List<T> |
query(String cql,
RowMapper<T> rowMapper,
QueryOptions queryOptions)
Executes the provided CQL Query, and maps all Rows returned with the supplied RowMapper.
|
com.datastax.driver.core.ResultSetFuture |
queryAsynchronously(com.datastax.driver.core.querybuilder.Select select)
Executes the provided CQL Select and returns the ResultSetFuture for user processing.
|
Cancellable |
queryAsynchronously(com.datastax.driver.core.querybuilder.Select select,
AsynchronousQueryListener listener)
Executes the provided CQL Select with the provided listener.
|
Cancellable |
queryAsynchronously(com.datastax.driver.core.querybuilder.Select select,
AsynchronousQueryListener listener,
Executor executor)
Executes the provided Select Query with the provided listener and executor.
|
Cancellable |
queryAsynchronously(com.datastax.driver.core.querybuilder.Select select,
Runnable listener)
Executes the provided CQL Select with the provided
Runnable , which is started after the query has
completed. |
Cancellable |
queryAsynchronously(com.datastax.driver.core.querybuilder.Select select,
Runnable listener,
Executor executor)
Executes the provided CQL Select with the provided Executor and Runnable implementations.
|
com.datastax.driver.core.ResultSetFuture |
queryAsynchronously(String cql)
Executes the provided CQL Query and returns the ResultSetFuture for user processing.
|
Cancellable |
queryAsynchronously(String cql,
AsynchronousQueryListener listener)
Executes the provided CQL Query with the provided listener.
|
Cancellable |
queryAsynchronously(String cql,
AsynchronousQueryListener listener,
Executor executor)
Executes the provided CQL Query with the provided listener and executor.
|
Cancellable |
queryAsynchronously(String cql,
AsynchronousQueryListener listener,
QueryOptions queryOptions)
Executes the provided CQL Query with the provided Listener and Query Options.
|
Cancellable |
queryAsynchronously(String cql,
AsynchronousQueryListener listener,
QueryOptions queryOptions,
Executor executor)
Executes the provided CQL Query with the provided Listener, Executor and Query Options.
|
com.datastax.driver.core.ResultSetFuture |
queryAsynchronously(String cql,
QueryOptions queryOptions)
Executes the provided CQL Query and returns the ResultSetFuture for user processing.
|
<T> T |
queryAsynchronously(String cql,
ResultSetExtractor<T> resultSetExtractor,
Long timeout,
TimeUnit timeUnit)
Executes the provided CQL Query, and extracts the results with the ResultSetExtractor.
|
<T> T |
queryAsynchronously(String cql,
ResultSetExtractor<T> resultSetExtractor,
Long timeout,
TimeUnit timeUnit,
QueryOptions options)
Executes the provided CQL Query, and extracts the results with the ResultSetExtractor.
|
<T> T |
queryAsynchronously(String cql,
ResultSetFutureExtractor<T> resultSetFutureExtractor) |
<T> T |
queryAsynchronously(String cql,
ResultSetFutureExtractor<T> resultSetFutureExtractor,
QueryOptions queryOptions) |
Cancellable |
queryAsynchronously(String cql,
Runnable listener)
Executes the provided CQL Query with the provided
Runnable , which is started after the query has completed. |
Cancellable |
queryAsynchronously(String cql,
Runnable listener,
Executor executor)
Executes the provided CQL Query with the provided Executor and Runnable implementations.
|
Cancellable |
queryAsynchronously(String cql,
Runnable listener,
QueryOptions queryOptions)
Executes the provided CQL Query with the Runnable implementations using the Query Options.
|
Cancellable |
queryAsynchronously(String cql,
Runnable listener,
QueryOptions queryOptions,
Executor executor)
Executes the provided CQL Query with the provided Executor and Runnable implementations.
|
<T> List<T> |
queryForList(com.datastax.driver.core.querybuilder.Select select,
Class<T> elementType)
Executes the provided Select Query and returns all values in the first column of the Results as a List of the Type
in the second argument.
|
<T> List<T> |
queryForList(String cql,
Class<T> elementType)
Executes the provided CQL and returns all values in the first column of the Results as a List of the Type in the
second argument.
|
<T> Cancellable |
queryForListAsynchronously(com.datastax.driver.core.querybuilder.Select select,
Class<T> requiredType,
QueryForListListener<T> listener)
Executes the provided
Select query asynchronously and returns all values in the first column of the results
as a List of the type in the second argument. |
<T> Cancellable |
queryForListAsynchronously(String select,
Class<T> requiredType,
QueryForListListener<T> listener)
Executes the provided
Select query asynchronously and returns all values in the first column of the results
as a List of the type in the second argument. |
List<Map<String,Object>> |
queryForListOfMap(com.datastax.driver.core.querybuilder.Select select)
Executes the provided Select Query and converts the results to a basic List of Maps.
|
List<Map<String,Object>> |
queryForListOfMap(String cql)
Executes the provided CQL and converts the results to a basic List of Maps.
|
Cancellable |
queryForListOfMapAsynchronously(com.datastax.driver.core.querybuilder.Select select,
QueryForListListener<Map<String,Object>> listener)
|
Cancellable |
queryForListOfMapAsynchronously(String cql,
QueryForListListener<Map<String,Object>> listener)
|
Cancellable |
queryForListOfMapAsynchronously(String cql,
QueryForListListener<Map<String,Object>> listener,
QueryOptions queryOptions)
|
Map<String,Object> |
queryForMap(com.datastax.driver.core.querybuilder.Select select)
Executes the provided Select Query and maps ONE Row to a basic Map of Strings and Objects.
|
Map<String,Object> |
queryForMap(String cql)
Executes the provided CQL Query and maps ONE Row to a basic Map of Strings and Objects.
|
Cancellable |
queryForMapAsynchronously(com.datastax.driver.core.querybuilder.Select select,
QueryForMapListener listener)
Executes the provided
Select query asynchronously and maps the first row to a Map
<String,Object>. |
Cancellable |
queryForMapAsynchronously(String cql,
QueryForMapListener listener)
Executes the provided CQL query asynchronously and maps the first row to a
Map <String,Object>. |
Cancellable |
queryForMapAsynchronously(String cql,
QueryForMapListener listener,
QueryOptions queryOptions)
Executes the provided CQL query asynchronously and maps the first row to a
Map <String,Object>. |
<T> T |
queryForObject(com.datastax.driver.core.querybuilder.Select select,
Class<T> requiredType)
Executes the provided Select query and tries to return the first column of the first Row as a Class
|
<T> T |
queryForObject(com.datastax.driver.core.querybuilder.Select select,
RowMapper<T> rowMapper)
Executes the provided Select Query, and maps ONE Row returned with the supplied RowMapper.
|
<T> T |
queryForObject(String cql,
Class<T> requiredType)
Executes the provided query and tries to return the first column of the first Row as a Class
|
<T> T |
queryForObject(String cql,
RowMapper<T> rowMapper)
Executes the provided CQL Query, and maps ONE Row returned with the supplied RowMapper.
|
<T> Cancellable |
queryForObjectAsynchronously(com.datastax.driver.core.querybuilder.Select select,
Class<T> requiredType,
QueryForObjectListener<T> listener)
Executes the provided
Select query and returns the first column of the first Row as an object of type
T . |
<T> Cancellable |
queryForObjectAsynchronously(com.datastax.driver.core.querybuilder.Select select,
RowMapper<T> rowMapper,
QueryForObjectListener<T> listener)
Executes the provided
Select query, and maps the first row returned with the supplied RowMapper . |
<T> Cancellable |
queryForObjectAsynchronously(String cql,
Class<T> requiredType,
QueryForObjectListener<T> listener)
Executes the provided select CQL query and returns the first column of the first Row as an object of type
T . |
<T> Cancellable |
queryForObjectAsynchronously(String cql,
Class<T> requiredType,
QueryForObjectListener<T> listener,
QueryOptions options)
Executes the provided select CQL query and returns the first column of the first Row as an object of type
T . |
<T> Cancellable |
queryForObjectAsynchronously(String cql,
RowMapper<T> rowMapper,
QueryForObjectListener<T> listener)
Executes the provided string CQL query, and maps the first row returned with the supplied
RowMapper . |
<T> Cancellable |
queryForObjectAsynchronously(String cql,
RowMapper<T> rowMapper,
QueryForObjectListener<T> listener,
QueryOptions options)
Executes the provided string CQL query, and maps the first row returned with the supplied
RowMapper . |
protected long |
selectCount(com.datastax.driver.core.querybuilder.Select select) |
protected Map<String,Object> |
toMap(com.datastax.driver.core.Row row) |
protected RuntimeException |
translateExceptionIfPossible(Throwable t)
|
protected static RuntimeException |
translateExceptionIfPossible(Throwable t,
PersistenceExceptionTranslator exceptionTranslator)
Tries to convert the given
RuntimeException into a DataAccessException but returns the original
exception if the conversation failed. |
void |
truncate(CqlIdentifier tableName)
Delete all rows in the table
|
void |
truncate(String tableName)
Delete all rows in the table
|
afterPropertiesSet, getExceptionTranslator, getSession, logDebug, setExceptionTranslator, setSession
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getSession
protected static final Executor RUN_RUNNABLE_EXECUTOR
protected static final ResultSetExtractor<com.datastax.driver.core.ResultSet> RESULT_SET_RETURNING_EXTRACTOR
public CqlTemplate()
CqlTemplate
. A Cassandra Session
is required before use.CqlTemplate(Session)
public CqlTemplate(com.datastax.driver.core.Session session)
CqlTemplate
initialized with the given Session
.session
- Cassandra Session
used by this template to perform CQL operations. Must not be
null.Session
,
CassandraAccessor.setSession(Session)
protected <T extends com.datastax.driver.core.Statement> T logStatement(T statement)
public static com.datastax.driver.core.PreparedStatement addPreparedStatementOptions(com.datastax.driver.core.PreparedStatement preparedStatement, QueryOptions queryOptions)
QueryOptions
to Cassandra PreparedStatement
s.preparedStatement
- the Cassandra PreparedStatement
to execute.queryOptions
- query options (e.g. consistency level) to add to the Cassandra PreparedStatement
.public static <T extends com.datastax.driver.core.Statement> T addQueryOptions(T statement, QueryOptions queryOptions)
QueryOptions
to all types of queries.statement
- CQL Statement
to execute.queryOptions
- query options (e.g. consistency level) to add to the CQL statement.Statement
.public static com.datastax.driver.core.querybuilder.Insert addWriteOptions(com.datastax.driver.core.querybuilder.Insert insert, WriteOptions writeOptions)
WriteOptions
options to Insert
CQL statements.insert
- Insert
CQL statement to execute.writeOptions
- write options (e.g. consistency level) to add to the CQL statement.Insert
.public static com.datastax.driver.core.querybuilder.Update addWriteOptions(com.datastax.driver.core.querybuilder.Update update, WriteOptions writeOptions)
WriteOptions
options to Update
CQL statements.update
- Update
CQL statement to execute.writeOptions
- write options (e.g. consistency level) to add to the CQL statement.Update
.protected <T> T doExecute(SessionCallback<T> callback)
Session
.T
- Class type of the callback return value.callback
- SessionCallback
to execute in the context of a Cassandra Session
.protected com.datastax.driver.core.ResultSet doExecuteQueryReturnResultSet(String query)
protected com.datastax.driver.core.ResultSet doExecuteQueryReturnResultSet(com.datastax.driver.core.querybuilder.Select select)
public <T> T execute(SessionCallback<T> sessionCallback)
CqlOperations
SessionCallback
in the current Template Session. The implementation of
SessionCallback can decide whether or not to execute()
or executeAsync()
the operation.execute
in interface CqlOperations
public void execute(String cql)
CqlOperations
execute
in interface CqlOperations
public void execute(String cql, QueryOptions options)
CqlOperations
execute
in interface CqlOperations
options
- may be nullpublic void execute(com.datastax.driver.core.Statement statement)
CqlOperations
execute
in interface CqlOperations
statement
- The Statement
to executepublic com.datastax.driver.core.ResultSetFuture queryAsynchronously(String cql)
CqlOperations
queryAsynchronously
in interface CqlOperations
cql
- The Querypublic <T> T queryAsynchronously(String cql, ResultSetExtractor<T> resultSetExtractor, Long timeout, TimeUnit timeUnit)
CqlOperations
queryAsynchronously
in interface CqlOperations
cql
- The QueryresultSetExtractor
- The implementation for extracting the ResultSettimeout
- Time to wait for resultstimeUnit
- Time unit to wait for resultspublic <T> T queryAsynchronously(String cql, ResultSetExtractor<T> resultSetExtractor, Long timeout, TimeUnit timeUnit, QueryOptions options)
CqlOperations
queryAsynchronously
in interface CqlOperations
cql
- The QueryresultSetExtractor
- The implementation for extracting the ResultSettimeout
- Time to wait for resultstimeUnit
- Time unit to wait for resultsoptions
- Query Optionspublic com.datastax.driver.core.ResultSetFuture queryAsynchronously(String cql, QueryOptions queryOptions)
CqlOperations
queryAsynchronously
in interface CqlOperations
cql
- The QueryqueryOptions
- Query Optionspublic Cancellable queryAsynchronously(String cql, Runnable listener)
CqlOperations
Runnable
, which is started after the query has completed.
A more useful method than this one is CqlOperations.queryAsynchronously(String, AsynchronousQueryListener)
, where you're
given the ResultSetFuture
after the query has been executed.queryAsynchronously
in interface CqlOperations
cql
- The Querylistener
- Runnable
listener for handling the query in a separate threadCancellable
that can be used to cancel the query.CqlOperations.queryAsynchronously(String, AsynchronousQueryListener)
public Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener)
CqlOperations
Runnable
. The AsynchronousQueryListener
gives you access to the ResultSetFuture
once the
query is completed for optimal flexibility.queryAsynchronously
in interface CqlOperations
cql
- The Querylistener
- AsynchronousQueryListener
for handling the query's ResultSetFuture
in a separate
threadCancellable
that can be used to cancel the query.public Cancellable queryAsynchronously(String cql, Runnable listener, QueryOptions queryOptions)
CqlOperations
queryAsynchronously
in interface CqlOperations
cql
- The Querylistener
- Runnable Listener for handling the query in a separate threadqueryOptions
- Query OptionCancellable
that can be used to cancel the query.public Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener, QueryOptions queryOptions)
CqlOperations
AsynchronousQueryListener
gives you access to the
ResultSetFuture
once the query is completed for optimal flexibility.queryAsynchronously
in interface CqlOperations
cql
- The Querylistener
- Runnable Listener for handling the query in a separate threadqueryOptions
- Query OptionCancellable
that can be used to cancel the query.public Cancellable queryAsynchronously(String cql, Runnable listener, Executor executor)
CqlOperations
queryAsynchronously
in interface CqlOperations
cql
- The Querylistener
- Runnable Listener for handling the query in a separate threadexecutor
- To execute the Runnable ListenerCancellable
that can be used to cancel the query.public Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener, Executor executor)
CqlOperations
AsynchronousQueryListener
gives you access to the ResultSetFuture
once the query is completed for optimal flexibility.queryAsynchronously
in interface CqlOperations
cql
- The Querylistener
- Runnable Listener for handling the query in a separate threadexecutor
- To execute the Runnable ListenerCancellable
that can be used to cancel the query.public Cancellable queryAsynchronously(String cql, Runnable listener, QueryOptions queryOptions, Executor executor)
CqlOperations
queryAsynchronously
in interface CqlOperations
cql
- The Querylistener
- Runnable Listener for handling the query in a separate threadqueryOptions
- Query Optionexecutor
- To execute the Runnable ListenerCancellable
that can be used to cancel the query.public Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener, QueryOptions queryOptions, Executor executor)
CqlOperations
AsynchronousQueryListener
gives you access to the
ResultSetFuture
once the query is completed for optimal flexibility.queryAsynchronously
in interface CqlOperations
Cancellable
that can be used to cancel the query.public <T> T queryAsynchronously(String cql, ResultSetFutureExtractor<T> resultSetFutureExtractor)
public <T> T queryAsynchronously(String cql, ResultSetFutureExtractor<T> resultSetFutureExtractor, QueryOptions queryOptions)
public <T> T query(String cql, ResultSetExtractor<T> resultSetExtractor)
CqlOperations
query
in interface CqlOperations
cql
- The QueryresultSetExtractor
- The implementation for extracting the ResultSetpublic <T> T query(String cql, ResultSetExtractor<T> resultSetExtractor, QueryOptions queryOptions)
CqlOperations
query
in interface CqlOperations
cql
- The QueryresultSetExtractor
- The implementation for extracting the ResultSetqueryOptions
- Query Optionspublic void query(String cql, RowCallbackHandler rowCallbackHandler)
CqlOperations
RowCallbackHandler
.query
in interface CqlOperations
cql
- The QueryrowCallbackHandler
- The implementation for processing the rows returned.public void query(String cql, RowCallbackHandler rowCallbackHandler, QueryOptions queryOptions)
CqlOperations
RowCallbackHandler
.query
in interface CqlOperations
cql
- The QueryrowCallbackHandler
- The implementation for processing the rows returned.queryOptions
- Query Options Objectpublic <T> List<T> query(String cql, RowMapper<T> rowMapper, QueryOptions queryOptions)
CqlOperations
query
in interface CqlOperations
cql
- The QueryrowMapper
- The implementation for mapping all rowsqueryOptions
- Query Options Objectpublic com.datastax.driver.core.ResultSet query(String cql)
CqlOperations
ResultSet
.query
in interface CqlOperations
cql
- The queryResultSet
public com.datastax.driver.core.ResultSet query(String cql, QueryOptions queryOptions)
CqlOperations
QueryOptions
and returns the ResultSet
.query
in interface CqlOperations
cql
- The queryqueryOptions
- The QueryOptions
; may be null.ResultSet
public <T> List<T> query(String cql, RowMapper<T> rowMapper)
CqlOperations
query
in interface CqlOperations
cql
- The QueryrowMapper
- The implementation for mapping all rowspublic List<Map<String,Object>> queryForListOfMap(String cql)
CqlOperations
queryForListOfMap
in interface CqlOperations
cql
- The Querypublic <T> List<T> queryForList(String cql, Class<T> elementType)
CqlOperations
queryForList
in interface CqlOperations
cql
- The QueryelementType
- Type to cast the data values topublic Map<String,Object> queryForMap(String cql)
CqlOperations
queryForMap
in interface CqlOperations
cql
- The Querypublic <T> T queryForObject(String cql, Class<T> requiredType)
CqlOperations
queryForObject
in interface CqlOperations
cql
- The QueryrequiredType
- Valid Class that Cassandra Data Types can be converted to.public <T> T queryForObject(String cql, RowMapper<T> rowMapper)
CqlOperations
This expects only ONE row to be returned. More than one Row will cause an Exception to be thrown.
queryForObject
in interface CqlOperations
cql
- The QueryrowMapper
- The implementation for convert the Row to protected com.datastax.driver.core.ResultSet doExecute(String cql)
protected com.datastax.driver.core.ResultSet doExecute(String cql, QueryOptions queryOptions)
protected com.datastax.driver.core.ResultSet doExecute(com.datastax.driver.core.Statement statement)
statement
- The query to execute.protected com.datastax.driver.core.ResultSetFuture doExecuteAsync(com.datastax.driver.core.Statement statement)
protected Cancellable doExecuteAsync(com.datastax.driver.core.Statement statement, AsynchronousQueryListener listener)
protected Cancellable doExecuteAsync(com.datastax.driver.core.Statement statement, AsynchronousQueryListener listener, QueryOptions queryOptions)
protected Object firstColumnToObject(com.datastax.driver.core.Row row)
public List<RingMember> describeRing()
CqlOperations
RingMemberHostMapper
to provide the basics of the
Cassandra Ring topology.describeRing
in interface CqlOperations
protected Set<com.datastax.driver.core.Host> getHosts()
Session
.public <T> Collection<T> describeRing(HostMapper<T> hostMapper)
CqlOperations
HostMapper
implementation to process the
lists of hosts returned by the Cassandra Cluster Metadata.describeRing
in interface CqlOperations
hostMapper
- The implementation to use for host mapping.public com.datastax.driver.core.ResultSetFuture executeAsynchronously(String cql)
CqlOperations
executeAsynchronously
in interface CqlOperations
cql
- The CQL String to executeResultSetFuture
that can be used to cancel the query.public com.datastax.driver.core.ResultSetFuture executeAsynchronously(String cql, QueryOptions queryOptions)
CqlOperations
executeAsynchronously
in interface CqlOperations
cql
- The CQL String to executequeryOptions
- The QueryOptions
to use. Only applies to cql statements that can use QueryOptions.ResultSetFuture
that can be used to cancel the query.public Cancellable executeAsynchronously(String cql, Runnable listener)
CqlOperations
executeAsynchronously
in interface CqlOperations
cql
- The CQL String to executelistener
- The Runnable
to register with the ResultSetFuture
Cancellable
that can be used to cancel the query.for Reads
public Cancellable executeAsynchronously(String cql, Runnable listener, Executor executor)
CqlOperations
executeAsynchronously
in interface CqlOperations
cql
- The CQL String to executelistener
- The Runnable
to register with the ResultSetFuture
executor
- The Executor
to regsiter with the ResultSetFuture
Cancellable
that can be used to cancel the query.for Reads
public Cancellable executeAsynchronously(String cql, AsynchronousQueryListener listener)
CqlOperations
executeAsynchronously
in interface CqlOperations
cql
- The CQL String to executelistener
- The AsynchronousQueryListener
to register with the ResultSetFuture
Cancellable
that can be used to cancel the query.for Reads
public Cancellable executeAsynchronously(String cql, AsynchronousQueryListener listener, Executor executor)
CqlOperations
executeAsynchronously
in interface CqlOperations
cql
- The CQL String to executelistener
- The AsynchronousQueryListener
to register with the ResultSetFuture
executor
- The Executor
to regsiter with the ResultSetFuture
Cancellable
that can be used to cancel the query.for Reads
public com.datastax.driver.core.ResultSetFuture executeAsynchronously(com.datastax.driver.core.Statement statement)
CqlOperations
executeAsynchronously
in interface CqlOperations
statement
- The Statement
to executeResultSetFuture
that can be used to cancel the query.public Cancellable executeAsynchronously(com.datastax.driver.core.Statement statement, Runnable listener)
CqlOperations
executeAsynchronously
in interface CqlOperations
statement
- The Statement
to executeCancellable
that can be used to cancel the query.public Cancellable executeAsynchronously(com.datastax.driver.core.Statement statement, AsynchronousQueryListener listener)
CqlOperations
executeAsynchronously
in interface CqlOperations
statement
- The Statement
to executeCancellable
that can be used to cancel the query.public Cancellable executeAsynchronously(com.datastax.driver.core.Statement statement, Runnable listener, Executor executor)
CqlOperations
executeAsynchronously
in interface CqlOperations
statement
- The Statement
to executeCancellable
that can be used to cancel the query.public Cancellable executeAsynchronously(com.datastax.driver.core.Statement statement, AsynchronousQueryListener listener, Executor executor)
CqlOperations
executeAsynchronously
in interface CqlOperations
statement
- The Statement
to executeCancellable
that can be used to cancel the query.public void process(com.datastax.driver.core.ResultSet resultSet, RowCallbackHandler rowCallbackHandler)
CqlOperations
process
in interface CqlOperations
resultSet
- Results to processrowCallbackHandler
- RowCallbackHandler with the processing implementationpublic <T> List<T> process(com.datastax.driver.core.ResultSet resultSet, RowMapper<T> rowMapper)
CqlOperations
process
in interface CqlOperations
resultSet
- Results to processrowMapper
- RowMapper with the processing implementationpublic <T> T processOne(com.datastax.driver.core.ResultSet resultSet, RowMapper<T> rowMapper)
CqlOperations
ResultSet
with RowMapper
. This method is used internally to the template for core
operations, but is made available through this interface in the event you have a ResultSet
to process. The
ResultSet
could come from a ResultSetFuture
after an asynchronous query.processOne
in interface CqlOperations
resultSet
- ResultSet
to process, must not be null.rowMapper
- RowMapper
used to process the single row of the result set, must not be null.public <T> T processOne(com.datastax.driver.core.ResultSet resultSet, Class<T> requiredType)
CqlOperations
processOne
in interface CqlOperations
public Map<String,Object> processMap(com.datastax.driver.core.ResultSet resultSet)
CqlOperations
processMap
in interface CqlOperations
public <T> List<T> processList(com.datastax.driver.core.ResultSet resultSet, Class<T> elementType)
CqlOperations
processList
in interface CqlOperations
public List<Map<String,Object>> processListOfMap(com.datastax.driver.core.ResultSet resultSet)
CqlOperations
processListOfMap
in interface CqlOperations
protected RuntimeException translateExceptionIfPossible(Throwable t)
e
- the Exception
to translate.RuntimeException
.protected static RuntimeException translateExceptionIfPossible(Throwable t, PersistenceExceptionTranslator exceptionTranslator)
RuntimeException
into a DataAccessException
but returns the original
exception if the conversation failed. Thus allows safe re-throwing of the return value.e
- the exception to translateexceptionTranslator
- the PersistenceExceptionTranslator
to be used for translationpublic <T> T execute(PreparedStatementCreator preparedStatementCreator, PreparedStatementCallback<T> preparedStatementCallback)
CqlOperations
PreparedStatementCreator
to create a PreparedStatement
in the current
Session
, then passes that PreparedStatement
to the given PreparedStatementCallback
.execute
in interface CqlOperations
preparedStatementCreator
- The PreparedStatementCreator
preparedStatementCallback
- The callback that receives the PreparedStatement
PreparedStatementCallback
public <T> T execute(String cql, PreparedStatementCallback<T> callback)
CqlOperations
PreparedStatement
from the given CQL, invokes the PreparedStatementCallback
with that PreparedStatement
, then returns the value returned by the PreparedStatementCallback
.execute
in interface CqlOperations
cql
- The CQL statement from which to create and cache a PreparedStatement
callback
- The callback that is given the PreparedStatement
PreparedStatementCallback
public <T> T query(PreparedStatementCreator preparedStatementCreator, ResultSetExtractor<T> resultSetExtractor)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementresultSetExtractor
- Implementation for extracting from the ResultSetpublic <T> T query(PreparedStatementCreator preparedStatementCreator, ResultSetExtractor<T> resultSetExtractor, QueryOptions queryOptions)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementresultSetExtractor
- Implementation for extracting from the ResultSetqueryOptions
- The Query Options Objectpublic void query(PreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementrowCallbackHandler
- The implementation to process Resultspublic void query(PreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler, QueryOptions queryOptions)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementrowCallbackHandler
- The implementation to process ResultsqueryOptions
- The Query Options Objectpublic <T> List<T> query(PreparedStatementCreator preparedStatementCreator, RowMapper<T> rowMapper)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementrowMapper
- The implementation for mapping each Row returned.public <T> List<T> query(PreparedStatementCreator preparedStatementCreator, RowMapper<T> rowMapper, QueryOptions queryOptions)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementrowMapper
- The implementation for mapping each Row returned.queryOptions
- The Query Options Objectpublic <T> T query(String cql, PreparedStatementBinder preparedStatementBinder, ResultSetExtractor<T> resultSetExtractor)
CqlOperations
CachedPreparedStatementCreator
. Then, the PreparedStatementBinder will
bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are
processed with the ResultSetExtractor implementation provided by the Application Code. The can return any object,
including a List of Objects to support the ResultSet processing.query
in interface CqlOperations
cql
- The Query to PreparepreparedStatementBinder
- The Binding implementationresultSetExtractor
- The implementation for extracting the results of the query.public <T> T query(String cql, PreparedStatementBinder preparedStatementBinder, ResultSetExtractor<T> resultSetExtractor, QueryOptions queryOptions)
CqlOperations
CachedPreparedStatementCreator
. Then, the PreparedStatementBinder will
bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are
processed with the ResultSetExtractor implementation provided by the Application Code. The can return any object,
including a List of Objects to support the ResultSet processing.query
in interface CqlOperations
cql
- The Query to PreparepreparedStatementBinder
- The Binding implementationresultSetExtractor
- The implementation for extracting the results of the query.queryOptions
- The Query Options to apply to the PreparedStatementpublic void query(String cql, PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler)
CqlOperations
CachedPreparedStatementCreator
. Then, the PreparedStatementBinder will
bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are
processed with the RowCallbackHandler implementation provided and nothing is returned.query
in interface CqlOperations
cql
- The Query to PreparepreparedStatementBinder
- The Binding implementationrowCallbackHandler
- The RowCallbackHandler for processing the ResultSetpublic void query(String cql, PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler, QueryOptions queryOptions)
CqlOperations
CachedPreparedStatementCreator
. Then, the PreparedStatementBinder will
bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are
processed with the RowCallbackHandler implementation provided and nothing is returned.query
in interface CqlOperations
cql
- The Query to PreparepreparedStatementBinder
- The Binding implementationrowCallbackHandler
- The RowCallbackHandler for processing the ResultSetqueryOptions
- The Query Options Objectpublic <T> List<T> query(String cql, PreparedStatementBinder preparedStatementBinder, RowMapper<T> rowMapper)
CqlOperations
CachedPreparedStatementCreator
. Then, the PreparedStatementBinder will
bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are
processed with the RowMapper implementation provided and a List is returned with elements of Type query
in interface CqlOperations
cql
- The Query to PreparepreparedStatementBinder
- The Binding implementationrowMapper
- The implementation for Mapping a Row to Type public <T> List<T> query(String cql, PreparedStatementBinder preparedStatementBinder, RowMapper<T> rowMapper, QueryOptions queryOptions)
CqlOperations
CachedPreparedStatementCreator
. Then, the PreparedStatementBinder will
bind its values to the bind variables in the provided CQL String. The results of the PreparedStatement are
processed with the RowMapper implementation provided and a List is returned with elements of Type query
in interface CqlOperations
cql
- The Query to PreparepreparedStatementBinder
- The Binding implementationrowMapper
- The implementation for Mapping a Row to Type queryOptions
- The Query Options Objectpublic void ingest(String cql, RowIterator rowIterator, WriteOptions options)
CqlOperations
This is used internally by the other ingest() methods, but can be used if you want to write your own RowIterator. The Object[] length returned by the next() implementation must match the number of bind variables in the CQL.
ingest
in interface CqlOperations
cql
- The CQLrowIterator
- Implementation to provide the Object[] to be bound to the CQL.options
- The Query Options Objectpublic void ingest(String cql, RowIterator rowIterator)
CqlOperations
This is used internally by the other ingest() methods, but can be used if you want to write your own RowIterator. The Object[] length returned by the next() implementation must match the number of bind variables in the CQL.
ingest
in interface CqlOperations
cql
- The CQLrowIterator
- Implementation to provide the Object[] to be bound to the CQL.public void ingest(String cql, List<List<?>> rows)
CqlOperations
PreparedStatement
once, then all row values are bound to that PreparedStatement
and executed against the Session
.
The lengths of the nested List
s must not be less than the number of bind variables in the CQL.
ingest
in interface CqlOperations
cql
- The CQLrows
- The data to bind to the CQL statementpublic void ingest(String cql, List<List<?>> rows, WriteOptions writeOptions)
CqlOperations
The List> length must match the number of bind variables in the CQL.
ingest
in interface CqlOperations
cql
- The CQLrows
- List of List> with data to bind to the CQL.writeOptions
- The Query Options Objectpublic void ingest(String cql, Object[][] rows)
CqlOperations
PreparedStatement
once, then all row values are bound to that PreparedStatement
and executed against the Session
.
The lengths of the nested object arrays must not be less than the number of bind variables in the CQL.
ingest
in interface CqlOperations
cql
- The CQLrows
- The data to bind to the CQL statementpublic void ingest(String cql, Object[][] rows, WriteOptions writeOptions)
CqlOperations
PreparedStatement
once, then all row values are bound to that PreparedStatement
and executed against the Session
.
The lengths of the nested object arrays must not be less than the number of bind variables in the CQL.
ingest
in interface CqlOperations
cql
- The CQLrows
- The data to bind to the CQL statementwriteOptions
- The Query Options Objectpublic void truncate(String tableName)
CqlOperations
truncate
in interface CqlOperations
public void truncate(CqlIdentifier tableName)
CqlOperations
truncate
in interface CqlOperations
public <T> T query(PreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder, ResultSetExtractor<T> resultSetExtractor)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementpreparedStatementBinder
- The implementation to bind variables to valuesresultSetExtractor
- Implementation for extracting from the ResultSetpublic <T> T query(PreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder, ResultSetExtractor<T> resultSetExtractor, QueryOptions queryOptions)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementpreparedStatementBinder
- The implementation to bind variables to valuesresultSetExtractor
- Implementation for extracting from the ResultSetqueryOptions
- The Query Options Objectpublic void query(PreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler, QueryOptions queryOptions)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementpreparedStatementBinder
- The implementation to bind variables to valuesrowCallbackHandler
- The implementation to process ResultsqueryOptions
- The Query Options Objectpublic void query(PreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementpreparedStatementBinder
- The implementation to bind variables to valuesrowCallbackHandler
- The implementation to process Resultspublic <T> List<T> query(PreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder, RowMapper<T> rowMapper, QueryOptions queryOptions)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementpreparedStatementBinder
- The implementation to bind variables to valuesrowMapper
- The implementation for mapping each Row returned.queryOptions
- The Query Options Objectpublic <T> List<T> query(PreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder, RowMapper<T> rowMapper)
CqlOperations
query
in interface CqlOperations
preparedStatementCreator
- The implementation to create the PreparedStatementpreparedStatementBinder
- The implementation to bind variables to valuesrowMapper
- The implementation for mapping each Row returned.public com.datastax.driver.core.ResultSet execute(AlterKeyspaceSpecification specification)
CqlOperations
execute
in interface CqlOperations
specification
- The specification to execute; must not be null.public com.datastax.driver.core.ResultSet execute(CreateKeyspaceSpecification specification)
CqlOperations
execute
in interface CqlOperations
specification
- The specification to execute; must not be null.public com.datastax.driver.core.ResultSet execute(DropKeyspaceSpecification specification)
CqlOperations
execute
in interface CqlOperations
specification
- The specification to execute; must not be null.public com.datastax.driver.core.ResultSet execute(AlterTableSpecification specification)
CqlOperations
execute
in interface CqlOperations
specification
- The specification to execute; must not be null.public com.datastax.driver.core.ResultSet execute(CreateTableSpecification specification)
CqlOperations
execute
in interface CqlOperations
specification
- The specification to execute; must not be null.public com.datastax.driver.core.ResultSet execute(DropTableSpecification specification)
CqlOperations
execute
in interface CqlOperations
specification
- The specification to execute; must not be null.public com.datastax.driver.core.ResultSet execute(CreateIndexSpecification specification)
CqlOperations
execute
in interface CqlOperations
specification
- The specification to execute; must not be null.public com.datastax.driver.core.ResultSet execute(DropIndexSpecification specification)
CqlOperations
execute
in interface CqlOperations
specification
- The specification to execute; must not be null.public void execute(com.datastax.driver.core.querybuilder.Batch batch)
CqlOperations
execute
in interface CqlOperations
public void execute(com.datastax.driver.core.querybuilder.Delete delete)
CqlOperations
execute
in interface CqlOperations
public void execute(com.datastax.driver.core.querybuilder.Insert insert)
CqlOperations
execute
in interface CqlOperations
public void execute(com.datastax.driver.core.querybuilder.Truncate truncate)
CqlOperations
execute
in interface CqlOperations
public void execute(com.datastax.driver.core.querybuilder.Update update)
CqlOperations
execute
in interface CqlOperations
public long count(String tableName)
CqlOperations
count
in interface CqlOperations
public long count(CqlIdentifier tableName)
CqlOperations
count
in interface CqlOperations
protected long selectCount(com.datastax.driver.core.querybuilder.Select select)
public com.datastax.driver.core.ResultSetFuture executeAsynchronously(com.datastax.driver.core.querybuilder.Batch batch)
CqlOperations
executeAsynchronously
in interface CqlOperations
ResultSetFuture
that can be used to cancel the query.public com.datastax.driver.core.ResultSetFuture executeAsynchronously(com.datastax.driver.core.querybuilder.Delete delete)
CqlOperations
executeAsynchronously
in interface CqlOperations
ResultSetFuture
that can be used to cancel the query.public com.datastax.driver.core.ResultSetFuture executeAsynchronously(com.datastax.driver.core.querybuilder.Insert insert)
CqlOperations
executeAsynchronously
in interface CqlOperations
ResultSetFuture
that can be used to cancel the query.public com.datastax.driver.core.ResultSetFuture executeAsynchronously(com.datastax.driver.core.querybuilder.Truncate truncate)
CqlOperations
executeAsynchronously
in interface CqlOperations
ResultSetFuture
that can be used to cancel the query.public com.datastax.driver.core.ResultSetFuture executeAsynchronously(com.datastax.driver.core.querybuilder.Update update)
CqlOperations
executeAsynchronously
in interface CqlOperations
ResultSetFuture
that can be used to cancel the query.public Cancellable executeAsynchronously(com.datastax.driver.core.querybuilder.Batch batch, AsynchronousQueryListener listener)
executeAsynchronously
in interface CqlOperations
public Cancellable executeAsynchronously(com.datastax.driver.core.querybuilder.Delete delete, AsynchronousQueryListener listener)
executeAsynchronously
in interface CqlOperations
public Cancellable executeAsynchronously(com.datastax.driver.core.querybuilder.Insert insert, AsynchronousQueryListener listener)
executeAsynchronously
in interface CqlOperations
public Cancellable executeAsynchronously(com.datastax.driver.core.querybuilder.Truncate truncate, AsynchronousQueryListener listener)
executeAsynchronously
in interface CqlOperations
public Cancellable executeAsynchronously(com.datastax.driver.core.querybuilder.Update update, AsynchronousQueryListener listener)
executeAsynchronously
in interface CqlOperations
public com.datastax.driver.core.ResultSetFuture queryAsynchronously(com.datastax.driver.core.querybuilder.Select select)
CqlOperations
queryAsynchronously
in interface CqlOperations
public Cancellable queryAsynchronously(com.datastax.driver.core.querybuilder.Select select, AsynchronousQueryListener listener)
CqlOperations
Runnable
. The AsynchronousQueryListener
gives you access to the ResultSetFuture
once the
query is completed for optimal flexibility.queryAsynchronously
in interface CqlOperations
select
- The Selectlistener
- AsynchronousQueryListener
for handling the query's ResultSetFuture
in a separate
threadCancellable
that can be used to cancel the query.public Cancellable queryAsynchronously(com.datastax.driver.core.querybuilder.Select select, AsynchronousQueryListener listener, Executor executor)
CqlOperations
AsynchronousQueryListener
gives you access to the ResultSetFuture
once the query is completed for optimal flexibility.queryAsynchronously
in interface CqlOperations
select
- The Select Querylistener
- Runnable Listener for handling the query in a separate threadexecutor
- To execute the Runnable ListenerCancellable
that can be used to cancel the query.public Cancellable queryAsynchronously(com.datastax.driver.core.querybuilder.Select select, Runnable listener)
CqlOperations
Runnable
, which is started after the query has
completed.
A more useful method than this one is CqlOperations.queryAsynchronously(Select, AsynchronousQueryListener)
, where you're
given the ResultSetFuture
after the query has been executed.queryAsynchronously
in interface CqlOperations
select
- The Select Querylistener
- Runnable
listener for handling the query in a separate threadCancellable
that can be used to cancel the query.CqlOperations.queryAsynchronously(Select, AsynchronousQueryListener)
public Cancellable queryAsynchronously(com.datastax.driver.core.querybuilder.Select select, Runnable listener, Executor executor)
CqlOperations
queryAsynchronously
in interface CqlOperations
select
- The Select Querylistener
- Runnable Listener for handling the query in a separate threadexecutor
- To execute the Runnable ListenerCancellable
that can be used to cancel the query.public com.datastax.driver.core.ResultSet query(com.datastax.driver.core.querybuilder.Select select)
CqlOperations
ResultSet
.query
in interface CqlOperations
select
- The Select QueryResultSet
public <T> T query(com.datastax.driver.core.querybuilder.Select select, ResultSetExtractor<T> resultSetExtractor)
CqlOperations
query
in interface CqlOperations
select
- The SelectQueryresultSetExtractor
- The implementation for extracting the ResultSetpublic void query(com.datastax.driver.core.querybuilder.Select select, RowCallbackHandler rowCallbackHandler)
CqlOperations
RowCallbackHandler
.query
in interface CqlOperations
select
- The Select QueryrowCallbackHandler
- The implementation for processing the rows returned.public <T> List<T> query(com.datastax.driver.core.querybuilder.Select select, RowMapper<T> rowMapper)
CqlOperations
query
in interface CqlOperations
select
- The Select QueryrowMapper
- The implementation for mapping all rowspublic <T> T queryForObject(com.datastax.driver.core.querybuilder.Select select, RowMapper<T> rowMapper)
CqlOperations
This expects only ONE row to be returned. More than one Row will cause an Exception to be thrown.
queryForObject
in interface CqlOperations
select
- The Select QueryrowMapper
- The implementation for convert the Row to public <T> T queryForObject(com.datastax.driver.core.querybuilder.Select select, Class<T> requiredType)
CqlOperations
queryForObject
in interface CqlOperations
select
- The Select QueryrequiredType
- Valid Class that Cassandra Data Types can be converted to.public Map<String,Object> queryForMap(com.datastax.driver.core.querybuilder.Select select)
CqlOperations
queryForMap
in interface CqlOperations
select
- The Select Querypublic <T> List<T> queryForList(com.datastax.driver.core.querybuilder.Select select, Class<T> elementType)
CqlOperations
queryForList
in interface CqlOperations
select
- The Select QueryelementType
- Type to cast the data values topublic List<Map<String,Object>> queryForListOfMap(com.datastax.driver.core.querybuilder.Select select)
CqlOperations
queryForListOfMap
in interface CqlOperations
select
- The Select Querypublic <T> Cancellable queryForListAsynchronously(com.datastax.driver.core.querybuilder.Select select, Class<T> requiredType, QueryForListListener<T> listener)
CqlOperations
Select
query asynchronously and returns all values in the first column of the results
as a List
of the type in the second argument.queryForListAsynchronously
in interface CqlOperations
select
- The Select
queryrequiredType
- The type to cast the data values tolistener
- The listener to receive the results asynchronously. Must not be null
.Cancellable
to cancel the query if necessarypublic <T> Cancellable queryForListAsynchronously(String select, Class<T> requiredType, QueryForListListener<T> listener)
CqlOperations
Select
query asynchronously and returns all values in the first column of the results
as a List
of the type in the second argument.queryForListAsynchronously
in interface CqlOperations
select
- The select query CQLrequiredType
- The type to cast the data values tolistener
- The listener to receive the results asynchronously. Must not be null
.Cancellable
to cancel the query if necessarypublic Cancellable queryForListOfMapAsynchronously(com.datastax.driver.core.querybuilder.Select select, QueryForListListener<Map<String,Object>> listener)
CqlOperations
Select
query and converts the results to a List
of Map
s. Each element
in the List
represents a row returned from the query. Each row's column(s) are put into a Map
as
values keyed by column name.queryForListOfMapAsynchronously
in interface CqlOperations
select
- The Select
query. Must not be null
.listener
- The listener that will receive the results upon query completion. Must not be null
.Cancellable
that can be used to cancel the query. Must not be null
.public Cancellable queryForListOfMapAsynchronously(String cql, QueryForListListener<Map<String,Object>> listener)
CqlOperations
List
of Map
s. Each element in
the List
represents a row returned from the query. Each row's column(s) are put into a Map
as
values keyed by column name.queryForListOfMapAsynchronously
in interface CqlOperations
listener
- The listener that will receive the results upon query completion. Must not be null
.Cancellable
that can be used to cancel the query. Must not be null
.public Cancellable queryForListOfMapAsynchronously(String cql, QueryForListListener<Map<String,Object>> listener, QueryOptions queryOptions)
CqlOperations
List
of Map
s. Each element in
the List
represents a row returned from the query. Each row's column(s) are put into a Map
as
values keyed by column name.queryForListOfMapAsynchronously
in interface CqlOperations
listener
- The listener that will receive the results upon query completion. Must not be null
.queryOptions
- The QueryOptions
to use. May be null
.Cancellable
that can be used to cancel the query. Must not be null
.public Cancellable queryForMapAsynchronously(String cql, QueryForMapListener listener)
CqlOperations
Map
<String,Object>.
Additional rows are ignored.queryForMapAsynchronously
in interface CqlOperations
cql
- The select query CQL. Must not be null
or blank.listener
- The QueryForMapListener
that will recieve the results upon query completion. Must not be
null
.Cancellable
that can be used to cancel the query if necessary. Must not be null
.public Cancellable queryForMapAsynchronously(String cql, QueryForMapListener listener, QueryOptions queryOptions)
CqlOperations
Map
<String,Object>.
Additional rows are ignored.queryForMapAsynchronously
in interface CqlOperations
cql
- The select query CQL. Must not be null
or blank.listener
- The QueryForMapListener
that will recieve the results upon query completion. Must not be
null
.queryOptions
- The QueryOptions
to use. May be null
.Cancellable
that can be used to cancel the query if necessary. Must not be null
.public Cancellable queryForMapAsynchronously(com.datastax.driver.core.querybuilder.Select select, QueryForMapListener listener)
CqlOperations
Select
query asynchronously and maps the first row to a Map
<String,Object>. Additional rows are ignored.queryForMapAsynchronously
in interface CqlOperations
listener
- The QueryForMapListener
that will recieve the results upon query completion. Must not be
null
.Cancellable
that can be used to cancel the query if necessary. Must not be null
.public <T> Cancellable queryForObjectAsynchronously(com.datastax.driver.core.querybuilder.Select select, Class<T> requiredType, QueryForObjectListener<T> listener)
CqlOperations
Select
query and returns the first column of the first Row as an object of type
T
.queryForObjectAsynchronously
in interface CqlOperations
select
- The Select
queryrequiredType
- Type that Cassandra data types can be converted to.Cancellable
that can be used to cancel the query if necessary.public <T> Cancellable queryForObjectAsynchronously(String cql, Class<T> requiredType, QueryForObjectListener<T> listener)
CqlOperations
T
.queryForObjectAsynchronously
in interface CqlOperations
cql
- The select query CQL. Must not be null
or blank.requiredType
- The type to convert the first column of the first row to. Must not be null
.Cancellable
that can be used to cancel the query if necessary. Must not be null
.public <T> Cancellable queryForObjectAsynchronously(String cql, Class<T> requiredType, QueryForObjectListener<T> listener, QueryOptions options)
CqlOperations
T
.queryForObjectAsynchronously
in interface CqlOperations
cql
- The select query CQL. Must not be null
or blank.requiredType
- The type to convert the first column of the first row to. Must not be null
.options
- The QueryOptions
to use. May be null
.Cancellable
that can be used to cancel the query if necessary. Must not be null
.public <T> Cancellable queryForObjectAsynchronously(String cql, RowMapper<T> rowMapper, QueryForObjectListener<T> listener)
CqlOperations
RowMapper
.queryForObjectAsynchronously
in interface CqlOperations
cql
- The string query CQL.rowMapper
- The RowMapper
to convert the row into an object of type T
.listener
- The listener that receives the results upon completion.Cancellable
that can be used to cancel the query.public <T> Cancellable queryForObjectAsynchronously(String cql, RowMapper<T> rowMapper, QueryForObjectListener<T> listener, QueryOptions options)
CqlOperations
RowMapper
.queryForObjectAsynchronously
in interface CqlOperations
cql
- The string query CQL.rowMapper
- The RowMapper
to convert the row into an object of type T
.listener
- The listener that receives the results upon completion.options
- The QueryOptions
to use. May be null
.Cancellable
that can be used to cancel the query.public <T> Cancellable queryForObjectAsynchronously(com.datastax.driver.core.querybuilder.Select select, RowMapper<T> rowMapper, QueryForObjectListener<T> listener)
CqlOperations
Select
query, and maps the first row returned with the supplied RowMapper
.queryForObjectAsynchronously
in interface CqlOperations
select
- The Select
query to execute.rowMapper
- The RowMapper
to convert the row into an object of type T
.listener
- The listener that receives the results upon completion.Cancellable
that can be used to cancel the query.public com.datastax.driver.core.ResultSet getResultSetUninterruptibly(com.datastax.driver.core.ResultSetFuture resultSetFuture)
CqlOperations
ResultSetFuture.getUninterruptibly()
but translates exceptions if any
are thrown.getResultSetUninterruptibly
in interface CqlOperations
resultSetFuture
- The ResultSetFuture
from which to get the ResultSet
.ResultSet
public com.datastax.driver.core.ResultSet getResultSetUninterruptibly(com.datastax.driver.core.ResultSetFuture resultSetFuture, long milliseconds)
CqlOperations
ResultSetFuture.getUninterruptibly()
but translates exceptions if any
are thrown.getResultSetUninterruptibly
in interface CqlOperations
resultSetFuture
- The ResultSetFuture
from which to get the ResultSet
.ResultSet
public com.datastax.driver.core.ResultSet getResultSetUninterruptibly(com.datastax.driver.core.ResultSetFuture resultSetFuture, long timeout, TimeUnit timeUnit)
CqlOperations
ResultSetFuture.getUninterruptibly()
but translates exceptions if any
are thrown.getResultSetUninterruptibly
in interface CqlOperations
resultSetFuture
- The ResultSetFuture
from which to get the ResultSet
.timeout
- The timeout to wait. A nonpositive value means wait indefinitely.timeUnit
- The TimeUnit
of the timeout.ResultSet
Copyright © 2011-2015–2017 Pivotal Software, Inc.. All rights reserved.