diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/CqlOperations.java b/spring-cql/src/main/java/org/springframework/cassandra/core/CqlOperations.java index 5925f9228..8d2c3c67b 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/CqlOperations.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/CqlOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,7 @@ import com.datastax.driver.core.querybuilder.Update; * * @author David Webb * @author Matthew Adams + * @author John Blum */ public interface CqlOperations { @@ -322,7 +323,8 @@ public interface CqlOperations { * @param options Query Options * @return */ - T queryAsynchronously(String cql, ResultSetExtractor rse, Long timeout, TimeUnit timeUnit, QueryOptions options); + T queryAsynchronously(String cql, ResultSetExtractor rse, Long timeout, TimeUnit timeUnit, + QueryOptions options); /** * Executes the provided CQL Query and returns the ResultSetFuture for user processing. @@ -664,8 +666,8 @@ public interface CqlOperations { * @return A {@link Cancellable} that can be used to cancel the query. * @throws DataAccessException */ - Cancellable queryForObjectAsynchronously(Select select, RowMapper rowMapper, QueryForObjectListener listener) - throws DataAccessException; + Cancellable queryForObjectAsynchronously(Select select, RowMapper rowMapper, + QueryForObjectListener listener) throws DataAccessException; /** * Executes the provided CQL Query, and maps ONE Row returned with the supplied RowMapper. @@ -694,17 +696,14 @@ public interface CqlOperations { T queryForObject(Select select, RowMapper rowMapper) throws DataAccessException; /** - * Process {@link ResultSet} with {@link 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 {@link ResultSet} - * to process. The {@link ResultSet} could come from a {@link ResultSetFuture} after an asynchronous query. + * Process {@link ResultSet} with {@link 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 {@link ResultSet} to process. The + * {@link ResultSet} could come from a {@link ResultSetFuture} after an asynchronous query. * - * @param resultSet {@link ResultSet} to process. - * @param rowMapper {@link RowMapper} used to process the single row of the result set. - * @throws IllegalArgumentException if {@link ResultSet} is null. + * @param resultSet {@link ResultSet} to process, must not be {@literal null}. + * @param rowMapper {@link RowMapper} used to process the single row of the result set, must not be {@literal null}. * @throws IncorrectResultSizeDataAccessException if no rows are found, or more than 1 row is found. * @throws DataAccessException if a Cassandra driver error occurs. - * @see org.springframework.cassandra.core.RowMapper - * @see com.datastax.driver.core.ResultSet */ T processOne(ResultSet resultSet, RowMapper rowMapper) throws DataAccessException; diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java b/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java index e1796588f..e9bf58586 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.cassandra.core; import static org.springframework.cassandra.core.cql.CqlIdentifier.*; @@ -80,13 +79,14 @@ import com.datastax.driver.core.querybuilder.Update; /** * This is the central class in the Cassandra core package. {@link 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 + * 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. *

+ * * @author David Webb * @author Matthew Adams * @author Ryan Scheidter @@ -105,20 +105,18 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } }; - protected static final ResultSetExtractor RESULT_SET_RETURNING_EXTRACTOR = - new ResultSetExtractor() { - @Override - public ResultSet extractData(ResultSet resultSet) throws DriverException, DataAccessException { - return resultSet; - } - }; + protected static final ResultSetExtractor RESULT_SET_RETURNING_EXTRACTOR = new ResultSetExtractor() { + + @Override + public ResultSet extractData(ResultSet resultSet) { + return resultSet; + } + }; - /* (non-Javadoc) */ protected String logCql(String cql) { return logCql("executing CQL [{}]", cql); } - /* (non-Javadoc) */ protected String logCql(String message, String cql) { logDebug(message, cql); return cql; @@ -134,9 +132,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { public static Statement addQueryOptions(Statement statement, QueryOptions queryOptions) { if (queryOptions != null) { + if (queryOptions.getConsistencyLevel() != null) { statement.setConsistencyLevel(ConsistencyLevelResolver.resolve(queryOptions.getConsistencyLevel())); } + if (queryOptions.getRetryPolicy() != null) { statement.setRetryPolicy(RetryPolicyResolver.resolve(queryOptions.getRetryPolicy())); } @@ -155,6 +155,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { public static Insert addWriteOptions(Insert insert, WriteOptions writeOptions) { if (writeOptions != null) { + addQueryOptions(insert, writeOptions); if (writeOptions.getTtl() != null) { @@ -175,6 +176,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { public static Update addWriteOptions(Update update, WriteOptions writeOptions) { if (writeOptions != null) { + addQueryOptions(update, writeOptions); if (writeOptions.getTtl() != null) { @@ -195,13 +197,13 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { QueryOptions queryOptions) { if (queryOptions != null) { + if (queryOptions.getConsistencyLevel() != null) { - preparedStatement.setConsistencyLevel(ConsistencyLevelResolver.resolve( - queryOptions.getConsistencyLevel())); + preparedStatement.setConsistencyLevel(ConsistencyLevelResolver.resolve(queryOptions.getConsistencyLevel())); } + if (queryOptions.getRetryPolicy() != null) { - preparedStatement.setRetryPolicy(RetryPolicyResolver.resolve( - queryOptions.getRetryPolicy())); + preparedStatement.setRetryPolicy(RetryPolicyResolver.resolve(queryOptions.getRetryPolicy())); } } @@ -209,19 +211,17 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } /** - * Constructs an uninitialized instance of {@link CqlTemplate}. A Cassandra {@link Session} - * is required before use. + * Constructs an uninitialized instance of {@link CqlTemplate}. A Cassandra {@link Session} is required before use. * * @see #CqlTemplate(Session) */ - public CqlTemplate() { - } + public CqlTemplate() {} /** * Constructs an instance of {@link CqlTemplate} initialized with the given {@link Session}. * - * @param session Cassandra {@link Session} used by this template to perform CQL operations. - * Must not be {@literal null}. + * @param session Cassandra {@link Session} used by this template to perform CQL operations. Must not be + * {@literal null}. * @see com.datastax.driver.core.Session * @see #setSession(Session) */ @@ -250,49 +250,53 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public T execute(SessionCallback sessionCallback) throws DataAccessException { + public T execute(SessionCallback sessionCallback) { return doExecute(sessionCallback); } @Override - public void execute(String cql) throws DataAccessException { + public void execute(String cql) { execute(cql, (QueryOptions) null); } @Override - public void execute(String cql, QueryOptions options) throws DataAccessException { + public void execute(String cql, QueryOptions options) { doExecute(cql, options); } @Override - public void execute(Statement statement) throws DataAccessException { + public void execute(Statement statement) { doExecute(statement); } @Override public ResultSetFuture queryAsynchronously(final String cql) { + return execute(new SessionCallback() { + @Override - public ResultSetFuture doInSession(Session session) throws DataAccessException { + public ResultSetFuture doInSession(Session session) { return session.executeAsync(logCql("async execute CQL [{}]", cql)); } }); } @Override - public T queryAsynchronously(String cql, ResultSetExtractor resultSetExtractor, - Long timeout, TimeUnit timeUnit) { + public T queryAsynchronously(String cql, ResultSetExtractor resultSetExtractor, Long timeout, + TimeUnit timeUnit) { return queryAsynchronously(cql, resultSetExtractor, timeout, timeUnit, null); } @Override - public T queryAsynchronously(final String cql, final ResultSetExtractor resultSetExtractor, - final Long timeout, final TimeUnit timeUnit, final QueryOptions options) { + public T queryAsynchronously(final String cql, final ResultSetExtractor resultSetExtractor, final Long timeout, + final TimeUnit timeUnit, final QueryOptions options) { return resultSetExtractor.extractData(execute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { + Statement statement = addQueryOptions(new SimpleStatement(logCql(cql)), options); ResultSetFuture resultSetFuture = session.executeAsync(statement); @@ -301,11 +305,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { return resultSetFuture.get(timeout, timeUnit); } catch (TimeoutException e) { throw new QueryTimeoutException(String.format( - "timeout occurred in [%1$d %2$s] while asynchronously executing CQL [%3$s]", - timeout, timeUnit, cql), e); + "timeout occurred in [%1$d %2$s] while asynchronously executing CQL [%3$s]", timeout, timeUnit, cql), e); } catch (InterruptedException e) { throw translateExceptionIfPossible(e); } catch (ExecutionException e) { + if (e.getCause() instanceof Exception) { throw translateExceptionIfPossible((Exception) e.getCause()); } @@ -317,9 +321,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public ResultSetFuture queryAsynchronously(final String cql, final QueryOptions queryOptions) { + return execute(new SessionCallback() { + @Override - public ResultSetFuture doInSession(Session session) throws DataAccessException { + public ResultSetFuture doInSession(Session session) { return session.executeAsync(addQueryOptions(new SimpleStatement(logCql(cql)), queryOptions)); } }); @@ -360,15 +366,14 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { final Executor executor) { return execute(new SessionCallback() { + @Override - public Cancellable doInSession(Session session) throws DataAccessException { - Statement statement = addQueryOptions(new SimpleStatement(logCql("async execute CQL [{}]", cql)), - queryOptions); + public Cancellable doInSession(Session session) { + + Statement statement = addQueryOptions(new SimpleStatement(logCql("async execute CQL [{}]", cql)), queryOptions); ResultSetFuture resultSetFuture = session.executeAsync(statement); - resultSetFuture.addListener(listener, executor); - return new ResultSetFutureCancellable(resultSetFuture); } }); @@ -379,10 +384,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { final QueryOptions queryOptions, final Executor executor) { return execute(new SessionCallback() { + @Override - public Cancellable doInSession(Session session) throws DataAccessException { - Statement statement = addQueryOptions(new SimpleStatement(logCql("async execute CQL [{}]", cql)), - queryOptions); + public Cancellable doInSession(Session session) { + + Statement statement = addQueryOptions(new SimpleStatement(logCql("async execute CQL [{}]", cql)), queryOptions); final ResultSetFuture resultSetFuture = session.executeAsync(statement); @@ -401,32 +407,30 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @SuppressWarnings("unused") - public T queryAsynchronously(String cql, ResultSetFutureExtractor resultSetFutureExtractor) - throws DataAccessException { - + public T queryAsynchronously(String cql, ResultSetFutureExtractor resultSetFutureExtractor) { return queryAsynchronously(cql, resultSetFutureExtractor, null); } public T queryAsynchronously(final String cql, ResultSetFutureExtractor resultSetFutureExtractor, - final QueryOptions queryOptions) throws DataAccessException { + final QueryOptions queryOptions) { return resultSetFutureExtractor.extractData(execute(new SessionCallback() { + @Override - public ResultSetFuture doInSession(Session session) throws DataAccessException { - return session.executeAsync(addQueryOptions(new SimpleStatement( - logCql("async execute CQL [{}]", cql)), queryOptions)); + public ResultSetFuture doInSession(Session session) { + return session + .executeAsync(addQueryOptions(new SimpleStatement(logCql("async execute CQL [{}]", cql)), queryOptions)); } })); } @Override - public T query(String cql, ResultSetExtractor resultSetExtractor) throws DataAccessException { + public T query(String cql, ResultSetExtractor resultSetExtractor) { return query(cql, resultSetExtractor, null); } @Override - public T query(String cql, ResultSetExtractor resultSetExtractor, QueryOptions queryOptions) - throws DataAccessException { + public T query(String cql, ResultSetExtractor resultSetExtractor, QueryOptions queryOptions) { Assert.notNull(cql, "CQL must not be null"); @@ -434,21 +438,17 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public void query(String cql, RowCallbackHandler rowCallbackHandler) throws DataAccessException { + public void query(String cql, RowCallbackHandler rowCallbackHandler) { query(cql, rowCallbackHandler, null); } @Override - public void query(String cql, RowCallbackHandler rowCallbackHandler, QueryOptions queryOptions) - throws DataAccessException { - + public void query(String cql, RowCallbackHandler rowCallbackHandler, QueryOptions queryOptions) { process(doExecute(cql, queryOptions), rowCallbackHandler); } @Override - public List query(String cql, RowMapper rowMapper, QueryOptions queryOptions) - throws DataAccessException { - + public List query(String cql, RowMapper rowMapper, QueryOptions queryOptions) { return process(doExecute(cql, queryOptions), rowMapper); } @@ -463,32 +463,32 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public List query(String cql, RowMapper rowMapper) throws DataAccessException { + public List query(String cql, RowMapper rowMapper) { return query(cql, rowMapper, null); } @Override - public List> queryForListOfMap(String cql) throws DataAccessException { + public List> queryForListOfMap(String cql) { return processListOfMap(doExecute(cql, null)); } @Override - public List queryForList(String cql, Class elementType) throws DataAccessException { + public List queryForList(String cql, Class elementType) { return processList(doExecute(cql, null), elementType); } @Override - public Map queryForMap(String cql) throws DataAccessException { + public Map queryForMap(String cql) { return processMap(doExecute(cql, null)); } @Override - public T queryForObject(String cql, Class requiredType) throws DataAccessException { + public T queryForObject(String cql, Class requiredType) { return processOne(doExecute(cql, null), requiredType); } @Override - public T queryForObject(String cql, RowMapper rowMapper) throws DataAccessException { + public T queryForObject(String cql, RowMapper rowMapper) { return processOne(doExecute(cql, null), rowMapper); } @@ -507,9 +507,12 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { * @param statement The query to execute. */ protected ResultSet doExecute(final Statement statement) { + return doExecute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { + logDebug("execute [{}]", statement); return session.execute(statement); } @@ -517,9 +520,12 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } protected ResultSetFuture doExecuteAsync(final Statement statement) { + return doExecute(new SessionCallback() { + @Override - public ResultSetFuture doInSession(Session session) throws DataAccessException { + public ResultSetFuture doInSession(Session session) { + logDebug("async execute [{}]", statement); return session.executeAsync(statement); } @@ -534,8 +540,9 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { final QueryOptions queryOptions) { return doExecute(new SessionCallback() { + @Override - public Cancellable doInSession(Session session) throws DataAccessException { + public Cancellable doInSession(Session session) { logDebug("async execute [{}]", statement); final ResultSetFuture resultSetFuture = session.executeAsync(addQueryOptions(statement, queryOptions)); @@ -555,6 +562,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } protected Object firstColumnToObject(Row row) { + Iterator columnDefinitions = row.getColumnDefinitions().iterator(); return (columnDefinitions.hasNext() ? columnToObject(row, columnDefinitions.next()) : null); } @@ -566,6 +574,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } protected Map toMap(Row row) { + Map map = null; if (row != null) { @@ -581,7 +590,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public List describeRing() throws DataAccessException { + public List describeRing() { return new ArrayList(describeRing(new RingMemberHostMapper())); } @@ -589,63 +598,69 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { * Requests the set of hosts in the Cassandra cluster from the current {@link Session}. */ protected Set getHosts() { + return doExecute(new SessionCallback>() { + @Override - public Set doInSession(Session session) throws DataAccessException { + public Set doInSession(Session session) { return session.getCluster().getMetadata().getAllHosts(); } }); } @Override - public Collection describeRing(HostMapper hostMapper) throws DataAccessException { + public Collection describeRing(HostMapper hostMapper) { return hostMapper.mapHosts(getHosts()); } @Override - public ResultSetFuture executeAsynchronously(String cql) throws DataAccessException { + public ResultSetFuture executeAsynchronously(String cql) { return executeAsynchronously(cql, (QueryOptions) null); } @Override - public ResultSetFuture executeAsynchronously(String cql, QueryOptions queryOptions) throws DataAccessException { + public ResultSetFuture executeAsynchronously(String cql, QueryOptions queryOptions) { return doExecuteAsync(addQueryOptions(new SimpleStatement(logCql(cql)), queryOptions)); } @Override - public Cancellable executeAsynchronously(String cql, Runnable listener) throws DataAccessException { + public Cancellable executeAsynchronously(String cql, Runnable listener) { return executeAsynchronously(cql, listener, RUN_RUNNABLE_EXECUTOR); } @Override - public Cancellable executeAsynchronously(final String cql, final Runnable listener, final Executor executor) - throws DataAccessException { + public Cancellable executeAsynchronously(final String cql, final Runnable listener, final Executor executor) { return execute(new SessionCallback() { + @Override - public Cancellable doInSession(Session session) throws DataAccessException { + public Cancellable doInSession(Session session) { + Statement statement = new SimpleStatement(logCql("async execute CQL [{}]", cql)); + ResultSetFuture resultSetFuture = session.executeAsync(statement); resultSetFuture.addListener(listener, executor); + return new ResultSetFutureCancellable(resultSetFuture); } }); } @Override - public Cancellable executeAsynchronously(String cql, AsynchronousQueryListener listener) - throws DataAccessException { + public Cancellable executeAsynchronously(String cql, AsynchronousQueryListener listener) { return executeAsynchronously(cql, listener, RUN_RUNNABLE_EXECUTOR); } @Override public Cancellable executeAsynchronously(final String cql, final AsynchronousQueryListener listener, - final Executor executor) throws DataAccessException { + final Executor executor) { return execute(new SessionCallback() { + @Override - public Cancellable doInSession(Session session) throws DataAccessException { + public Cancellable doInSession(Session session) { + Statement statement = new SimpleStatement(logCql("async execute CQL [{}]", cql)); final ResultSetFuture resultSetFuture = session.executeAsync(statement); @@ -665,32 +680,35 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public ResultSetFuture executeAsynchronously(Statement statement) throws DataAccessException { + public ResultSetFuture executeAsynchronously(Statement statement) { return doExecuteAsync(statement); } @Override - public Cancellable executeAsynchronously(Statement statement, Runnable listener) throws DataAccessException { + public Cancellable executeAsynchronously(Statement statement, Runnable listener) { return executeAsynchronously(statement, listener, RUN_RUNNABLE_EXECUTOR); } @Override - public Cancellable executeAsynchronously(Statement statement, AsynchronousQueryListener listener) - throws DataAccessException { + public Cancellable executeAsynchronously(Statement statement, AsynchronousQueryListener listener) { return executeAsynchronously(statement, listener, RUN_RUNNABLE_EXECUTOR); } @Override public Cancellable executeAsynchronously(final Statement statement, final Runnable listener, - final Executor executor) throws DataAccessException { + final Executor executor) { return execute(new SessionCallback() { + @Override - public Cancellable doInSession(Session session) throws DataAccessException { + public Cancellable doInSession(Session session) { + logDebug("executing [{}]", statement); + final ResultSetFuture resultSetFuture = session.executeAsync(statement); resultSetFuture.addListener(listener, executor); + return new ResultSetFutureCancellable(resultSetFuture); } }); @@ -698,11 +716,13 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public Cancellable executeAsynchronously(final Statement statement, final AsynchronousQueryListener listener, - final Executor executor) throws DataAccessException { + final Executor executor) { return execute(new SessionCallback() { + @Override - public Cancellable doInSession(Session session) throws DataAccessException { + public Cancellable doInSession(Session session) { + logDebug("executing [{}]", statement); final ResultSetFuture resultSetFuture = session.executeAsync(statement); @@ -722,7 +742,8 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public void process(ResultSet resultSet, RowCallbackHandler rowCallbackHandler) throws DataAccessException { + public void process(ResultSet resultSet, RowCallbackHandler rowCallbackHandler) { + try { for (Row row : resultSet.all()) { rowCallbackHandler.processRow(row); @@ -733,8 +754,10 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public List process(ResultSet resultSet, RowMapper rowMapper) throws DataAccessException { + public List process(ResultSet resultSet, RowMapper rowMapper) { + try { + List rows = resultSet.all(); List mappedRows = new ArrayList(rows.size()); @@ -751,10 +774,13 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public T processOne(ResultSet resultSet, RowMapper rowMapper) throws DataAccessException { - Assert.notNull(resultSet, "ResultSet cannot be null"); + public T processOne(ResultSet resultSet, RowMapper rowMapper) { + + Assert.notNull(resultSet, "ResultSet must not be null"); + Assert.notNull(rowMapper, "RowMapper must not be null"); try { + Row row = resultSet.one(); if (row == null) { @@ -773,10 +799,12 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override @SuppressWarnings("unchecked") - public T processOne(ResultSet resultSet, Class requiredType) throws DataAccessException { - Assert.notNull(resultSet, "ResultSet cannot be null"); + public T processOne(ResultSet resultSet, Class requiredType) { + + Assert.notNull(resultSet, "ResultSet must not be null"); try { + Row row = resultSet.one(); if (row == null) { @@ -794,13 +822,14 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public Map processMap(ResultSet resultSet) throws DataAccessException { + public Map processMap(ResultSet resultSet) { return (resultSet != null ? toMap(resultSet.one()) : null); } @Override @SuppressWarnings("unchecked") - public List processList(ResultSet resultSet, Class elementType) throws DataAccessException { + public List processList(ResultSet resultSet, Class elementType) { + List rows = resultSet.all(); List list = new ArrayList(rows.size()); @@ -812,7 +841,8 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public List> processListOfMap(ResultSet resultSet) throws DataAccessException { + public List> processListOfMap(ResultSet resultSet) { + List rows = resultSet.all(); List> list = new ArrayList>(rows.size()); @@ -828,14 +858,15 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { */ @SuppressWarnings("all") protected RuntimeException translateExceptionIfPossible(RuntimeException e) { + RuntimeException resolved = getExceptionTranslator().translateExceptionIfPossible(e); return (resolved != null ? resolved : e); } @SuppressWarnings("all") protected RuntimeException translateExceptionIfPossible(Exception e) { - return (e instanceof RuntimeException ? translateExceptionIfPossible((RuntimeException) e) : - new CassandraUncategorizedDataAccessException("Caught Uncategorized Exception", e)); + return (e instanceof RuntimeException ? translateExceptionIfPossible((RuntimeException) e) + : new CassandraUncategorizedDataAccessException("Caught Uncategorized Exception", e)); } @Override @@ -843,8 +874,10 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { PreparedStatementCallback preparedStatementCallback) { try { + PreparedStatement preparedStatement = preparedStatementCreator.createPreparedStatement(getSession()); logDebug("executing [{}]", preparedStatement); + return preparedStatementCallback.doInPreparedStatement(preparedStatement); } catch (DriverException dx) { throw translateExceptionIfPossible(dx); @@ -857,99 +890,83 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public T query(PreparedStatementCreator preparedStatementCreator, ResultSetExtractor resultSetExtractor) - throws DataAccessException { - + public T query(PreparedStatementCreator preparedStatementCreator, ResultSetExtractor resultSetExtractor) { return query(preparedStatementCreator, resultSetExtractor, null); } @Override public T query(PreparedStatementCreator preparedStatementCreator, ResultSetExtractor resultSetExtractor, - QueryOptions queryOptions) throws DataAccessException { - + QueryOptions queryOptions) { return query(preparedStatementCreator, null, resultSetExtractor, queryOptions); } @Override - public void query(PreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler) - throws DataAccessException { - + public void query(PreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler) { query(preparedStatementCreator, rowCallbackHandler, null); } @Override public void query(PreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler, - QueryOptions queryOptions) throws DataAccessException { - + QueryOptions queryOptions) { query(preparedStatementCreator, null, rowCallbackHandler, queryOptions); } @Override - public List query(PreparedStatementCreator preparedStatementCreator, RowMapper rowMapper) - throws DataAccessException { - + public List query(PreparedStatementCreator preparedStatementCreator, RowMapper rowMapper) { return query(preparedStatementCreator, rowMapper, null); } @Override public List query(PreparedStatementCreator preparedStatementCreator, RowMapper rowMapper, - QueryOptions queryOptions) throws DataAccessException { - + QueryOptions queryOptions) { return query(preparedStatementCreator, null, rowMapper, queryOptions); } @Override public T query(String cql, PreparedStatementBinder preparedStatementBinder, - ResultSetExtractor resultSetExtractor) throws DataAccessException { - + ResultSetExtractor resultSetExtractor) { return query(cql, preparedStatementBinder, resultSetExtractor, null); } @Override public T query(String cql, PreparedStatementBinder preparedStatementBinder, - ResultSetExtractor resultSetExtractor, QueryOptions queryOptions) throws DataAccessException { + ResultSetExtractor resultSetExtractor, QueryOptions queryOptions) { - return query(new CachedPreparedStatementCreator(logCql(cql)), - preparedStatementBinder, resultSetExtractor, queryOptions); + return query(new CachedPreparedStatementCreator(logCql(cql)), preparedStatementBinder, resultSetExtractor, + queryOptions); } @Override public void query(String cql, PreparedStatementBinder preparedStatementBinder, - RowCallbackHandler rowCallbackHandler) throws DataAccessException { - + RowCallbackHandler rowCallbackHandler) { query(cql, preparedStatementBinder, rowCallbackHandler, null); } @Override - public void query(String cql, PreparedStatementBinder preparedStatementBinder, - RowCallbackHandler rowCallbackHandler, QueryOptions queryOptions) throws DataAccessException { + public void query(String cql, PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler, + QueryOptions queryOptions) { - query(new CachedPreparedStatementCreator(logCql(cql)), preparedStatementBinder, rowCallbackHandler, - queryOptions); + query(new CachedPreparedStatementCreator(logCql(cql)), preparedStatementBinder, rowCallbackHandler, queryOptions); } @Override - public List query(String cql, PreparedStatementBinder preparedStatementBinder, RowMapper rowMapper) - throws DataAccessException { - + public List query(String cql, PreparedStatementBinder preparedStatementBinder, RowMapper rowMapper) { return query(cql, preparedStatementBinder, rowMapper, null); } @Override public List query(String cql, PreparedStatementBinder preparedStatementBinder, RowMapper rowMapper, - QueryOptions queryOptions) throws DataAccessException { - + QueryOptions queryOptions) { return query(new CachedPreparedStatementCreator(logCql(cql)), preparedStatementBinder, rowMapper, queryOptions); } @Override public void ingest(String cql, RowIterator rowIterator, WriteOptions options) { - CachedPreparedStatementCreator cachedPreparedStatementCreator = - new CachedPreparedStatementCreator(logCql(cql)); + CachedPreparedStatementCreator cachedPreparedStatementCreator = new CachedPreparedStatementCreator(logCql(cql)); PreparedStatement preparedStatement = addPreparedStatementOptions( - cachedPreparedStatementCreator.createPreparedStatement(getSession()), options); + cachedPreparedStatementCreator.createPreparedStatement(getSession()), options); Session session = getSession(); @@ -970,6 +987,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public void ingest(String cql, final List> rows, WriteOptions writeOptions) { + Assert.notNull(rows); Assert.notEmpty(rows); @@ -997,12 +1015,14 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public void ingest(String cql, final Object[][] rows, WriteOptions writeOptions) { + ingest(cql, new RowIterator() { int index = 0; @Override public Object[] next() { + if (!hasNext()) { throw new NoSuchElementException("No more elements"); } @@ -1017,19 +1037,18 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public void truncate(String tableName) throws DataAccessException { + public void truncate(String tableName) { truncate(cqlId(tableName)); } @Override - public void truncate(CqlIdentifier tableName) throws DataAccessException { + public void truncate(CqlIdentifier tableName) { doExecute(QueryBuilder.truncate(logCql(tableName.toCql()))); } @Override - public T query(PreparedStatementCreator preparedStatementCreator, - PreparedStatementBinder preparedStatementBinder, ResultSetExtractor resultSetExtractor) - throws DataAccessException { + public T query(PreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder, + ResultSetExtractor resultSetExtractor) { return query(preparedStatementCreator, preparedStatementBinder, resultSetExtractor, null); } @@ -1037,16 +1056,17 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public T query(PreparedStatementCreator preparedStatementCreator, final PreparedStatementBinder preparedStatementBinder, final ResultSetExtractor resultSetExtractor, - final QueryOptions queryOptions) throws DataAccessException { + final QueryOptions queryOptions) { Assert.notNull(resultSetExtractor, "ResultSetExtractor must not be null"); return execute(preparedStatementCreator, new PreparedStatementCallback() { + @Override - public T doInPreparedStatement(PreparedStatement preparedStatement) throws DriverException { + public T doInPreparedStatement(PreparedStatement preparedStatement) { + BoundStatement boundStatement = (preparedStatementBinder != null - ? preparedStatementBinder.bindValues(preparedStatement) - : preparedStatement.bind()); + ? preparedStatementBinder.bindValues(preparedStatement) : preparedStatement.bind()); return resultSetExtractor.extractData(doExecute(addQueryOptions(boundStatement, queryOptions))); } @@ -1056,16 +1076,17 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public void query(PreparedStatementCreator preparedStatementCreator, final PreparedStatementBinder preparedStatementBinder, final RowCallbackHandler rowCallbackHandler, - final QueryOptions queryOptions) throws DataAccessException { + final QueryOptions queryOptions) { Assert.notNull(rowCallbackHandler, "RowCallbackHandler must not be null"); execute(preparedStatementCreator, new PreparedStatementCallback() { + @Override - public Object doInPreparedStatement(PreparedStatement preparedStatement) throws DriverException { + public Object doInPreparedStatement(PreparedStatement preparedStatement) { + BoundStatement boundStatement = (preparedStatementBinder != null - ? preparedStatementBinder.bindValues(preparedStatement) - : preparedStatement.bind()); + ? preparedStatementBinder.bindValues(preparedStatement) : preparedStatement.bind()); process(doExecute(addQueryOptions(boundStatement, queryOptions)), rowCallbackHandler); @@ -1075,9 +1096,8 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public void query(PreparedStatementCreator preparedStatementCreator, - PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler) - throws DataAccessException { + public void query(PreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder, + RowCallbackHandler rowCallbackHandler) { query(preparedStatementCreator, preparedStatementBinder, rowCallbackHandler, null); } @@ -1085,16 +1105,17 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public List query(PreparedStatementCreator preparedStatementCreator, final PreparedStatementBinder preparedStatementBinder, final RowMapper rowMapper, - final QueryOptions queryOptions) throws DataAccessException { + final QueryOptions queryOptions) { Assert.notNull(rowMapper, "RowMapper must not be null"); return execute(preparedStatementCreator, new PreparedStatementCallback>() { + @Override - public List doInPreparedStatement(PreparedStatement preparedStatement) throws DriverException { + public List doInPreparedStatement(PreparedStatement preparedStatement) { + BoundStatement boundStatement = (preparedStatementBinder != null - ? preparedStatementBinder.bindValues(preparedStatement) - : preparedStatement.bind()); + ? preparedStatementBinder.bindValues(preparedStatement) : preparedStatement.bind()); return process(doExecute(addQueryOptions(boundStatement, queryOptions)), rowMapper); } @@ -1103,16 +1124,17 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public List query(PreparedStatementCreator preparedStatementCreator, - PreparedStatementBinder preparedStatementBinder, RowMapper rowMapper) throws DataAccessException { - + PreparedStatementBinder preparedStatementBinder, RowMapper rowMapper) { return query(preparedStatementCreator, preparedStatementBinder, rowMapper, null); } @Override public ResultSet execute(final AlterKeyspaceSpecification specification) { + return execute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { return session.execute(logCql(AlterKeyspaceCqlGenerator.toCql(specification))); } }); @@ -1120,9 +1142,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public ResultSet execute(final CreateKeyspaceSpecification specification) { + return execute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { return session.execute(logCql(CreateKeyspaceCqlGenerator.toCql(specification))); } }); @@ -1130,9 +1154,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public ResultSet execute(final DropKeyspaceSpecification specification) { + return execute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { return session.execute(logCql(DropKeyspaceCqlGenerator.toCql(specification))); } }); @@ -1140,9 +1166,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public ResultSet execute(final AlterTableSpecification specification) { + return execute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { return session.execute(logCql(AlterTableCqlGenerator.toCql(specification))); } }); @@ -1150,9 +1178,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public ResultSet execute(final CreateTableSpecification specification) { + return execute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { return session.execute(logCql(CreateTableCqlGenerator.toCql(specification))); } }); @@ -1160,9 +1190,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public ResultSet execute(final DropTableSpecification specification) { + return execute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { return session.execute(logCql(DropTableCqlGenerator.toCql(specification))); } }); @@ -1170,9 +1202,11 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public ResultSet execute(final CreateIndexSpecification specification) { + return execute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { return session.execute(logCql(CreateIndexCqlGenerator.toCql(specification))); } }); @@ -1180,36 +1214,38 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public ResultSet execute(final DropIndexSpecification specification) { + return execute(new SessionCallback() { + @Override - public ResultSet doInSession(Session session) throws DataAccessException { + public ResultSet doInSession(Session session) { return session.execute(logCql(DropIndexCqlGenerator.toCql(specification))); } }); } @Override - public void execute(Batch batch) throws DataAccessException { + public void execute(Batch batch) { doExecute(batch); } @Override - public void execute(Delete delete) throws DataAccessException { + public void execute(Delete delete) { doExecute(delete); } @Override - public void execute(Insert insert) throws DataAccessException { + public void execute(Insert insert) { doExecute(insert); } @Override - public void execute(Truncate truncate) throws DataAccessException { + public void execute(Truncate truncate) { doExecute(truncate); } @Override - public void execute(Update update) throws DataAccessException { + public void execute(Update update) { doExecute(update); } @@ -1224,14 +1260,17 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } protected long selectCount(final Select select) { + return query(select, new ResultSetExtractor() { + @Override - public Long extractData(ResultSet resultSet) throws DriverException, DataAccessException { + public Long extractData(ResultSet resultSet) { + Row row = resultSet.one(); if (row == null) { - throw new InvalidDataAccessApiUsageException(String.format( - "count query [%1$s] did not return any results", select)); + throw new InvalidDataAccessApiUsageException( + String.format("count query [%1$s] did not return any results", select)); } return row.getLong(0); @@ -1240,70 +1279,65 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public ResultSetFuture executeAsynchronously(Batch batch) throws DataAccessException { + public ResultSetFuture executeAsynchronously(Batch batch) { return doExecuteAsync(batch); } @Override - public ResultSetFuture executeAsynchronously(Delete delete) throws DataAccessException { + public ResultSetFuture executeAsynchronously(Delete delete) { return doExecuteAsync(delete); } @Override - public ResultSetFuture executeAsynchronously(Insert insert) throws DataAccessException { + public ResultSetFuture executeAsynchronously(Insert insert) { return doExecuteAsync(insert); } @Override - public ResultSetFuture executeAsynchronously(Truncate truncate) throws DataAccessException { + public ResultSetFuture executeAsynchronously(Truncate truncate) { return doExecuteAsync(truncate); } @Override - public ResultSetFuture executeAsynchronously(Update update) throws DataAccessException { + public ResultSetFuture executeAsynchronously(Update update) { return doExecuteAsync(update); } @Override - public Cancellable executeAsynchronously(Batch batch, AsynchronousQueryListener listener) - throws DataAccessException { - + public Cancellable executeAsynchronously(Batch batch, AsynchronousQueryListener listener) { return doExecuteAsync(batch, listener); } @Override - public Cancellable executeAsynchronously(Delete delete, AsynchronousQueryListener listener) - throws DataAccessException { - + public Cancellable executeAsynchronously(Delete delete, AsynchronousQueryListener listener) { return doExecuteAsync(delete, listener); } @Override - public Cancellable executeAsynchronously(Insert insert, AsynchronousQueryListener listener) - throws DataAccessException { + public Cancellable executeAsynchronously(Insert insert, AsynchronousQueryListener listener) { return doExecuteAsync(insert, listener); } @Override - public Cancellable executeAsynchronously(Truncate truncate, AsynchronousQueryListener listener) - throws DataAccessException { + public Cancellable executeAsynchronously(Truncate truncate, AsynchronousQueryListener listener) { return doExecuteAsync(truncate, listener); } @Override - public Cancellable executeAsynchronously(Update update, AsynchronousQueryListener listener) - throws DataAccessException { + public Cancellable executeAsynchronously(Update update, AsynchronousQueryListener listener) { return doExecuteAsync(update, listener); } @Override public ResultSetFuture queryAsynchronously(final Select select) { + return execute(new SessionCallback() { @Override - public ResultSetFuture doInSession(Session session) throws DataAccessException { + public ResultSetFuture doInSession(Session session) { + logDebug("async query [{}]", select); return session.executeAsync(select); } @@ -1320,13 +1354,16 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { final Executor executor) { return execute(new SessionCallback() { + @Override - public Cancellable doInSession(Session session) throws DataAccessException { + public Cancellable doInSession(Session session) { + logDebug("async query [{}]", select); final ResultSetFuture resultSetFuture = session.executeAsync(select); Runnable wrapper = new Runnable() { + @Override public void run() { listener.onQueryComplete(resultSetFuture); @@ -1347,12 +1384,17 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public Cancellable queryAsynchronously(final Select select, final Runnable listener, final Executor executor) { + return execute(new SessionCallback() { + @Override - public Cancellable doInSession(Session session) throws DataAccessException { + public Cancellable doInSession(Session session) { + logDebug("async query [{}]", select); + ResultSetFuture resultSetFuture = session.executeAsync(select); resultSetFuture.addListener(listener, executor); + return new ResultSetFutureCancellable(resultSetFuture); } }); @@ -1364,57 +1406,61 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public T query(Select select, ResultSetExtractor resultSetExtractor) throws DataAccessException { + public T query(Select select, ResultSetExtractor resultSetExtractor) { + Assert.notNull(select); + return resultSetExtractor.extractData(doExecute(select)); } @Override - public void query(Select select, RowCallbackHandler rowCallbackHandler) throws DataAccessException { + public void query(Select select, RowCallbackHandler rowCallbackHandler) { process(doExecute(select), rowCallbackHandler); } @Override - public List query(Select select, RowMapper rowMapper) throws DataAccessException { + public List query(Select select, RowMapper rowMapper) { return process(doExecute(select), rowMapper); } @Override - public T queryForObject(Select select, RowMapper rowMapper) throws DataAccessException { + public T queryForObject(Select select, RowMapper rowMapper) { return processOne(doExecute(select), rowMapper); } @Override - public T queryForObject(Select select, Class requiredType) throws DataAccessException { + public T queryForObject(Select select, Class requiredType) { return processOne(doExecute(select), requiredType); } @Override - public Map queryForMap(Select select) throws DataAccessException { + public Map queryForMap(Select select) { return processMap(doExecute(select)); } @Override - public List queryForList(Select select, Class elementType) throws DataAccessException { + public List queryForList(Select select, Class elementType) { return processList(doExecute(select), elementType); } @Override - public List> queryForListOfMap(Select select) throws DataAccessException { + public List> queryForListOfMap(Select select) { return processListOfMap(doExecute(select)); } @Override public Cancellable queryForListAsynchronously(Select select, final Class requiredType, - final QueryForListListener listener) throws DataAccessException { + final QueryForListListener listener) { - Assert.notNull(select, "Select cannot be null"); - Assert.notNull(requiredType, "Required type cannot be null"); - Assert.notNull(listener, "Listener cannot be null"); + Assert.notNull(select, "Select must not be null"); + Assert.notNull(requiredType, "Required type must not be null"); + Assert.notNull(listener, "Listener must not be null"); return doExecuteAsync(select, new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture resultSetFuture) { + try { listener.onQueryComplete(processList(resultSetFuture.getUninterruptibly(), requiredType)); } catch (Exception e) { @@ -1426,15 +1472,17 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public Cancellable queryForListAsynchronously(String select, final Class requiredType, - final QueryForListListener listener) throws DataAccessException { + final QueryForListListener listener) { - Assert.hasText(select, "Select cannot be null"); - Assert.notNull(requiredType, "Required type cannot be null"); - Assert.notNull(listener, "Listener cannot be null"); + Assert.hasText(select, "Select must not be null"); + Assert.notNull(requiredType, "Required type must not be null"); + Assert.notNull(listener, "Listener must not be null"); return doExecuteAsync(new SimpleStatement(logCql(select)), new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture resultSetFuture) { + try { listener.onQueryComplete(processList(resultSetFuture.getUninterruptibly(), requiredType)); } catch (Exception e) { @@ -1446,11 +1494,13 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public Cancellable queryForListOfMapAsynchronously(Select select, - final QueryForListListener> listener) throws DataAccessException { + final QueryForListListener> listener) { return doExecuteAsync(select, new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture resultSetFuture) { + try { listener.onQueryComplete(processListOfMap(resultSetFuture.getUninterruptibly())); } catch (Exception e) { @@ -1462,19 +1512,20 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public Cancellable queryForListOfMapAsynchronously(String cql, - final QueryForListListener> listener) throws DataAccessException { + final QueryForListListener> listener) { return queryForListOfMapAsynchronously(cql, listener, null); } @Override public Cancellable queryForListOfMapAsynchronously(String cql, - final QueryForListListener> listener, QueryOptions queryOptions) - throws DataAccessException { + final QueryForListListener> listener, QueryOptions queryOptions) { return doExecuteAsync(new SimpleStatement(logCql(cql)), new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture rsf) { + try { listener.onQueryComplete(processListOfMap(rsf.getUninterruptibly())); } catch (Exception e) { @@ -1485,19 +1536,20 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public Cancellable queryForMapAsynchronously(String cql, QueryForMapListener listener) - throws DataAccessException { + public Cancellable queryForMapAsynchronously(String cql, QueryForMapListener listener) { return queryForMapAsynchronously(cql, listener, null); } @Override public Cancellable queryForMapAsynchronously(String cql, final QueryForMapListener listener, - final QueryOptions queryOptions) throws DataAccessException { + final QueryOptions queryOptions) { return doExecuteAsync(new SimpleStatement(logCql(cql)), new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture resultSetFuture) { + try { listener.onQueryComplete(processMap(resultSetFuture.getUninterruptibly())); } catch (Exception e) { @@ -1508,12 +1560,13 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public Cancellable queryForMapAsynchronously(Select select, final QueryForMapListener listener) - throws DataAccessException { + public Cancellable queryForMapAsynchronously(Select select, final QueryForMapListener listener) { return doExecuteAsync(select, new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture resultSetFuture) { + try { listener.onQueryComplete(processMap(resultSetFuture.getUninterruptibly())); } catch (Exception e) { @@ -1525,11 +1578,13 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public Cancellable queryForObjectAsynchronously(Select select, final Class requiredType, - final QueryForObjectListener listener) throws DataAccessException { + final QueryForObjectListener listener) { return doExecuteAsync(select, new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture resultSetFuture) { + try { listener.onQueryComplete(processOne(resultSetFuture.getUninterruptibly(), requiredType)); } catch (Exception e) { @@ -1541,18 +1596,20 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public Cancellable queryForObjectAsynchronously(String cql, Class requiredType, - QueryForObjectListener listener) throws DataAccessException { + QueryForObjectListener listener) { return queryForObjectAsynchronously(cql, requiredType, listener, null); } @Override public Cancellable queryForObjectAsynchronously(String cql, final Class requiredType, - final QueryForObjectListener listener, QueryOptions options) throws DataAccessException { + final QueryForObjectListener listener, QueryOptions options) { return doExecuteAsync(new SimpleStatement(logCql(cql)), new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture resultSetFuture) { + try { listener.onQueryComplete(processOne(resultSetFuture.getUninterruptibly(), requiredType)); } catch (Exception e) { @@ -1564,18 +1621,20 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public Cancellable queryForObjectAsynchronously(String cql, RowMapper rowMapper, - QueryForObjectListener listener) throws DataAccessException { + QueryForObjectListener listener) { return queryForObjectAsynchronously(cql, rowMapper, listener, null); } @Override public Cancellable queryForObjectAsynchronously(String cql, final RowMapper rowMapper, - final QueryForObjectListener listener, QueryOptions options) throws DataAccessException { + final QueryForObjectListener listener, QueryOptions options) { return doExecuteAsync(new SimpleStatement(logCql(cql)), new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture resultSetFuture) { + try { listener.onQueryComplete(processOne(resultSetFuture.getUninterruptibly(), rowMapper)); } catch (Exception e) { @@ -1587,11 +1646,13 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public Cancellable queryForObjectAsynchronously(Select select, final RowMapper rowMapper, - final QueryForObjectListener listener) throws DataAccessException { + final QueryForObjectListener listener) { return doExecuteAsync(select, new AsynchronousQueryListener() { + @Override public void onQueryComplete(ResultSetFuture resultSetFuture) { + try { listener.onQueryComplete(processOne(resultSetFuture.getUninterruptibly(), rowMapper)); } catch (Exception e) { @@ -1613,11 +1674,12 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { @Override public ResultSet getResultSetUninterruptibly(ResultSetFuture resultSetFuture, long timeout, TimeUnit timeUnit) { + try { timeUnit = (timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS); return (timeout > 0 ? resultSetFuture.getUninterruptibly(timeout, timeUnit) - : resultSetFuture.getUninterruptibly()); + : resultSetFuture.getUninterruptibly()); } catch (Exception e) { throw translateExceptionIfPossible(e); } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java index 54da6bc12..4ecb69875 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors + * Copyright 2016 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.cassandra.core; import static org.hamcrest.Matchers.*; @@ -41,11 +40,10 @@ import com.datastax.driver.core.Session; * {@link CqlTemplate} class. * * @author John Blum - * @see org.springframework.cassandra.core.CqlTemplate - * @since 1.5.0 */ // TODO: add many more unit tests until SUT test coverage is 100%! @RunWith(MockitoJUnitRunner.class) +@SuppressWarnings("unchecked") public class CqlTemplateUnitTests { @Rule public ExpectedException exception = ExpectedException.none(); @@ -59,9 +57,12 @@ public class CqlTemplateUnitTests { template = new CqlTemplate(mockSession); } + /** + * @see DATACASS-286 + */ @Test - @SuppressWarnings("unchecked") public void firstColumnToObjectReturnsColumnValue() { + final Row mockRow = mock(Row.class); ColumnDefinitions mockColumnDefinitions = mock(ColumnDefinitions.class); Iterator mockIterator = mock(Iterator.class); @@ -73,8 +74,10 @@ public class CqlTemplateUnitTests { when(mockIterator.next()).thenReturn(mockColumnDefinition); template = new CqlTemplate() { + @Override T columnToObject(Row row, ColumnDefinitions.Definition columnDefinition) { + assertThat(row, is(sameInstance(mockRow))); assertThat(columnDefinition, is(sameInstance(mockColumnDefinition))); return (T) "test"; @@ -90,9 +93,12 @@ public class CqlTemplateUnitTests { verifyZeroInteractions(mockColumnDefinition); } + /** + * @see DATACASS-286 + */ @Test - @SuppressWarnings("unchecked") public void firstColumnToObjectReturnsNull() { + Row mockRow = mock(Row.class); ColumnDefinitions mockColumnDefinitions = mock(ColumnDefinitions.class); Iterator mockIterator = mock(Iterator.class); @@ -109,9 +115,12 @@ public class CqlTemplateUnitTests { verify(mockIterator, never()).next(); } + /** + * @see DATACASS-286 + */ @Test - @SuppressWarnings("unchecked") public void processOneIsSuccessful() { + ResultSet mockResultSet = mock(ResultSet.class); Row mockRow = mock(Row.class); RowMapper mockRowMapper = mock(RowMapper.class); @@ -128,14 +137,19 @@ public class CqlTemplateUnitTests { verifyZeroInteractions(mockRow); } + /** + * @see DATACASS-286 + */ @Test public void processOneThrowsIncorrectResultSetSizeDataAccessExceptionWhenNoRowsFound() { + ResultSet mockResultSet = mock(ResultSet.class); RowMapper mockRowMapper = mock(RowMapper.class); when(mockResultSet.one()).thenReturn(null); try { + exception.expect(IncorrectResultSizeDataAccessException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage(containsString("expected 1, actual 0")); @@ -149,8 +163,12 @@ public class CqlTemplateUnitTests { } } + /** + * @see DATACASS-286 + */ @Test public void processOneThrowsIncorrectResultSetSizeDataAccessExceptionWhenTooManyRowsFound() { + ResultSet mockResultSet = mock(ResultSet.class); Row mockRow = mock(Row.class); RowMapper mockRowMapper = mock(RowMapper.class); @@ -159,6 +177,7 @@ public class CqlTemplateUnitTests { when(mockResultSet.isExhausted()).thenReturn(false); try { + exception.expect(IncorrectResultSizeDataAccessException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage("ResultSet size exceeds 1"); @@ -173,14 +192,18 @@ public class CqlTemplateUnitTests { } } + /** + * @see DATACASS-286 + */ @Test public void processOnePassingNullResultSetThrowsIllegalArgumentException() { + RowMapper mockRowMapper = mock(RowMapper.class); try { + exception.expect(IllegalArgumentException.class); exception.expectCause(is(nullValue(Throwable.class))); - exception.expectMessage("ResultSet cannot be null"); template.processOne(null, mockRowMapper); } finally { @@ -188,9 +211,12 @@ public class CqlTemplateUnitTests { } } + /** + * @see DATACASS-286 + */ @Test - @SuppressWarnings("unchecked") public void processOneWithRequiredTypeIsSuccessful() { + ResultSet mockResultSet = mock(ResultSet.class); final Row mockRow = mock(Row.class); @@ -201,27 +227,32 @@ public class CqlTemplateUnitTests { @Override protected Object firstColumnToObject(Row row) { assertThat(row, is(equalTo(mockRow))); - return 1l; + return 1L; } }; Number value = template.processOne(mockResultSet, Long.class); assertThat(value, is(instanceOf(Long.class))); - assertThat(value.longValue(), is(equalTo(1l))); + assertThat(value.longValue(), is(equalTo(1L))); verify(mockResultSet, times(1)).one(); verify(mockResultSet, times(1)).isExhausted(); verifyZeroInteractions(mockRow); } + /** + * @see DATACASS-286 + */ @Test public void processOneWithRequiredTypeThrowsIncorrectResultSetSizeDataAccessExceptionWhenNoRowsFound() { + ResultSet mockResultSet = mock(ResultSet.class); when(mockResultSet.one()).thenReturn(null); try { + exception.expect(IncorrectResultSizeDataAccessException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage(containsString("expected 1, actual 0")); @@ -234,8 +265,12 @@ public class CqlTemplateUnitTests { } } + /** + * @see DATACASS-286 + */ @Test public void processOneWithRequiredTypeThrowsIncorrectResultSetSizeDataAccessExceptionWhenTooManyRowsFound() { + ResultSet mockResultSet = mock(ResultSet.class); Row mockRow = mock(Row.class); @@ -243,6 +278,7 @@ public class CqlTemplateUnitTests { when(mockResultSet.isExhausted()).thenReturn(false); try { + exception.expect(IncorrectResultSizeDataAccessException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage(containsString("ResultSet size exceeds 1")); @@ -256,11 +292,14 @@ public class CqlTemplateUnitTests { } } + /** + * @see DATACASS-286 + */ @Test public void processOneWithRequiredTypePassingNullResultSetThrowsIllegalArgumentException() { + exception.expect(IllegalArgumentException.class); exception.expectCause(is(nullValue(Throwable.class))); - exception.expectMessage(is(equalTo("ResultSet cannot be null"))); template.processOne(null, String.class); } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/support/CassandraAccessorUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/support/CassandraAccessorUnitTests.java index 8362c4938..a095d6781 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/support/CassandraAccessorUnitTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/support/CassandraAccessorUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2016 the original author or authors + * Copyright 2016 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.springframework.cassandra.support; import static org.hamcrest.Matchers.*; @@ -34,8 +33,6 @@ import com.datastax.driver.core.Session; * {@link CassandraAccessor} class. * * @author John Blum - * @see org.springframework.cassandra.support.CassandraAccessor - * @since 1.5.0 */ @RunWith(MockitoJUnitRunner.class) public class CassandraAccessorUnitTests { @@ -53,8 +50,12 @@ public class CassandraAccessorUnitTests { cassandraAccessor = new CassandraAccessor(); } + /** + * @see DATACASS-286 + */ @Test public void afterPropertiesSetWithUnitializedSessionThrowsIllegalStateException() { + exception.expect(IllegalStateException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage("Session must not be null"); @@ -62,14 +63,22 @@ public class CassandraAccessorUnitTests { cassandraAccessor.afterPropertiesSet(); } + /** + * @see DATACASS-286 + */ @Test public void setAndGetExceptionTranslator() { + cassandraAccessor.setExceptionTranslator(mockExceptionTranslator); assertThat(cassandraAccessor.getExceptionTranslator(), is(sameInstance(mockExceptionTranslator))); } + /** + * @see DATACASS-286 + */ @Test public void setExceptionTranslatorToNullThrowsIllegalArgumentException() { + exception.expect(IllegalArgumentException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage(is(equalTo("CassandraExceptionTranslator must not be null"))); @@ -77,19 +86,30 @@ public class CassandraAccessorUnitTests { cassandraAccessor.setExceptionTranslator(null); } + /** + * @see DATACASS-286 + */ @Test public void getUninitializedExceptionTranslatorReturnsDefault() { assertThat(cassandraAccessor.getExceptionTranslator(), is(equalTo(cassandraAccessor.exceptionTranslator))); } + /** + * @see DATACASS-286 + */ @Test public void setAndGetSession() { + cassandraAccessor.setSession(mockSession); assertThat(cassandraAccessor.getSession(), is(sameInstance(mockSession))); } + /** + * @see DATACASS-286 + */ @Test public void setSessionToNullThrowsIllegalArgumentException() { + exception.expect(IllegalArgumentException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage(is(equalTo("Session must not be null"))); @@ -97,8 +117,12 @@ public class CassandraAccessorUnitTests { cassandraAccessor.setSession(null); } + /** + * @see DATACASS-286 + */ @Test public void getUninitializedSessionThrowsIllegalStateException() { + exception.expect(IllegalStateException.class); exception.expectCause(is(nullValue(Throwable.class))); exception.expectMessage(is(equalTo("Session was not properly initialized"))); diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraOperations.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraOperations.java index 3610d929e..4dfad200a 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraOperations.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraOperations.java @@ -1,12 +1,12 @@ /* - * Copyright 2013-2014 the original author or authors - * + * Copyright 2013-2016 the original author or authors + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,7 +30,7 @@ import com.datastax.driver.core.querybuilder.Select; /** * Operations for interacting with Cassandra. These operations are used by the Repository implementation, but can also * be used directly when that is desired by the developer. - * + * * @author Alex Shvid * @author David Webb * @author Matthew Adams @@ -39,7 +39,7 @@ public interface CassandraOperations extends CqlOperations { /** * The table name used for the specified class by this template. - * + * * @param entityClass must not be {@literal null}. * @return */ @@ -47,7 +47,7 @@ public interface CassandraOperations extends CqlOperations { /** * Execute query and convert ResultSet to the list of entities - * + * * @param query must not be {@literal null}. * @param type must not be {@literal null}, mapped entity type. * @return @@ -56,7 +56,7 @@ public interface CassandraOperations extends CqlOperations { /** * Execute the Select Query and convert to the list of entities - * + * * @param select must not be {@literal null}. * @param type must not be {@literal null}, mapped entity type. * @return @@ -67,7 +67,7 @@ public interface CassandraOperations extends CqlOperations { /** * Execute CQL and convert ResultSet to the entity - * + * * @param query must not be {@literal null}. * @param type must not be {@literal null}, mapped entity type. * @return @@ -76,7 +76,7 @@ public interface CassandraOperations extends CqlOperations { /** * Executes the {@link Select} query asynchronously. - * + * * @param select The {@link Select} query to execute. * @param type The type of entity to retrieve. * @return A {@link Cancellable} that can be used to cancel the query. @@ -85,7 +85,7 @@ public interface CassandraOperations extends CqlOperations { /** * Executes the string CQL query asynchronously. - * + * * @param select The string query CQL to execute. * @param type The type of entity to retrieve. * @return A {@link Cancellable} that can be used to cancel the query. @@ -94,7 +94,7 @@ public interface CassandraOperations extends CqlOperations { /** * Executes the {@link Select} query asynchronously. - * + * * @param select The {@link Select} query to execute. * @param type The type of entity to retrieve. * @param options The {@link QueryOptions} to use. @@ -105,7 +105,7 @@ public interface CassandraOperations extends CqlOperations { /** * Executes the string CQL query asynchronously. - * + * * @param select The string query CQL to execute. * @param type The type of entity to retrieve. * @param options The {@link QueryOptions} to use. @@ -116,7 +116,7 @@ public interface CassandraOperations extends CqlOperations { /** * Execute Select query and convert ResultSet to the entity - * + * * @param query must not be {@literal null}. * @param type must not be {@literal null}, mapped entity type. * @return @@ -129,7 +129,7 @@ public interface CassandraOperations extends CqlOperations { /** * Insert the given entity. - * + * * @param entity The entity to insert * @return The entity given */ @@ -137,7 +137,7 @@ public interface CassandraOperations extends CqlOperations { /** * Insert the given entity. - * + * * @param entity The entity to insert * @param options The {@link WriteOptions} to use. * @return The entity given @@ -146,7 +146,7 @@ public interface CassandraOperations extends CqlOperations { /** * Insert the given list of entities. - * + * * @param entities The entities to insert. * @return The entities given. */ @@ -154,7 +154,7 @@ public interface CassandraOperations extends CqlOperations { /** * Insert the given list of entities. - * + * * @param entities The entities to insert. * @param options The {@link WriteOptions} to use. * @return The entities given. @@ -163,7 +163,7 @@ public interface CassandraOperations extends CqlOperations { /** * Inserts the given entity asynchronously. - * + * * @param entity The entity to insert * @return The entity given * @see #insertAsynchronously(Object, WriteListener) @@ -175,7 +175,7 @@ public interface CassandraOperations extends CqlOperations { /** * Inserts the given entity asynchronously. - * + * * @param entity The entity to insert * @return The entity given * @see #insertAsynchronously(Object, WriteOptions) @@ -187,7 +187,7 @@ public interface CassandraOperations extends CqlOperations { /** * Inserts the given entity asynchronously. - * + * * @param entity The entity to insert * @param listener The listener to receive notification of completion * @return A {@link Cancellable} enabling the cancellation of the operation @@ -196,7 +196,7 @@ public interface CassandraOperations extends CqlOperations { /** * Inserts the given entity asynchronously. - * + * * @param entity The entity to insert * @param listener The listener to receive notification of completion * @param options The {@link WriteOptions} to use @@ -206,7 +206,7 @@ public interface CassandraOperations extends CqlOperations { /** * Inserts the given entities asynchronously in a batch. - * + * * @param entity The entities to insert * @return The entities given * @see #insertAsynchronously(List, WriteListener) @@ -218,7 +218,7 @@ public interface CassandraOperations extends CqlOperations { /** * Inserts the given entities asynchronously in a batch. - * + * * @param entity The entities to insert * @return The entities given * @see #insertAsynchronously(List, WriteListener, WriteOptions) @@ -230,7 +230,7 @@ public interface CassandraOperations extends CqlOperations { /** * Inserts the given entities asynchronously in a batch. - * + * * @param entity The entities to insert * @param listener The listener to receive notification of completion * @return A {@link Cancellable} enabling the cancellation of the operation @@ -239,7 +239,7 @@ public interface CassandraOperations extends CqlOperations { /** * Inserts the given entities asynchronously in a batch. - * + * * @param entity The entities to insert * @param listener The listener to receive notification of completion * @param options The {@link WriteOptions} to use @@ -249,7 +249,7 @@ public interface CassandraOperations extends CqlOperations { /** * Update the given entity. - * + * * @param entity The entity to update * @return The entity given */ @@ -257,7 +257,7 @@ public interface CassandraOperations extends CqlOperations { /** * Update the given entity. - * + * * @param entity The entity to update * @param options The {@link WriteOptions} to use. * @return The entity given @@ -266,7 +266,7 @@ public interface CassandraOperations extends CqlOperations { /** * Update the given list of entities. - * + * * @param entities The entities to update. * @return The entities given. */ @@ -274,7 +274,7 @@ public interface CassandraOperations extends CqlOperations { /** * Update the given list of entities. - * + * * @param entities The entities to update. * @param options The {@link WriteOptions} to use. * @return The entities given. @@ -283,7 +283,7 @@ public interface CassandraOperations extends CqlOperations { /** * Updates the given entity asynchronously. - * + * * @param entity The entity to update * @return The entity given * @see #updateAsynchronously(Object, WriteListener) @@ -295,7 +295,7 @@ public interface CassandraOperations extends CqlOperations { /** * Updates the given entity asynchronously. - * + * * @param entity The entity to update * @return The entity given * @see #updateAsynchronously(Object, WriteOptions) @@ -307,7 +307,7 @@ public interface CassandraOperations extends CqlOperations { /** * Updates the given entity asynchronously. - * + * * @param entity The entity to update * @param listener The listener to receive notification of completion * @return A {@link Cancellable} enabling the cancellation of the operation @@ -316,7 +316,7 @@ public interface CassandraOperations extends CqlOperations { /** * Updates the given entity asynchronously. - * + * * @param entity The entity to update * @param listener The listener to receive notification of completion * @param options The {@link WriteOptions} to use @@ -326,7 +326,7 @@ public interface CassandraOperations extends CqlOperations { /** * Updates the given entities asynchronously in a batch. - * + * * @param entity The entities to update * @return The entities given * @see #updateAsynchronously(List, WriteListener) @@ -338,7 +338,7 @@ public interface CassandraOperations extends CqlOperations { /** * Updates the given entities asynchronously in a batch. - * + * * @param entity The entities to update * @return The entities given * @see #updateAsynchronously(List, WriteListener, WriteOptions) @@ -350,7 +350,7 @@ public interface CassandraOperations extends CqlOperations { /** * Updates the given entities asynchronously in a batch. - * + * * @param entity The entities to update * @param listener The listener to receive notification of completion * @return A {@link Cancellable} enabling the cancellation of the operation @@ -359,7 +359,7 @@ public interface CassandraOperations extends CqlOperations { /** * Updates the given entities asynchronously in a batch. - * + * * @param entity The entities to update * @param listener The listener to receive notification of completion * @param options The {@link WriteOptions} to use @@ -369,7 +369,7 @@ public interface CassandraOperations extends CqlOperations { /** * Remove the given object from the table by id. - * + * * @param object */ void delete(T entity); @@ -383,7 +383,7 @@ public interface CassandraOperations extends CqlOperations { /** * Remove the given object from the table by id. - * + * * @param object */ void delete(List entities); @@ -397,14 +397,14 @@ public interface CassandraOperations extends CqlOperations { /** * Remove the given object from the table by id. - * + * * @param entity The object to delete */ Cancellable deleteAsynchronously(T entity); /** * Remove the given object from the table by id. - * + * * @param entity The object to delete * @param options The {@link QueryOptions} to use */ @@ -412,7 +412,7 @@ public interface CassandraOperations extends CqlOperations { /** * Remove the given object from the table by id. - * + * * @param entity The object to delete * @param listener The {@link DeletionListener} to receive notification upon completion */ @@ -420,7 +420,7 @@ public interface CassandraOperations extends CqlOperations { /** * Remove the given object from the table by id. - * + * * @param entity The object to delete * @param listener The {@link DeletionListener} to receive notification upon completion * @param options The {@link QueryOptions} to use @@ -429,14 +429,14 @@ public interface CassandraOperations extends CqlOperations { /** * Remove the given objects from the table by id. - * + * * @param entities The objects to delete */ Cancellable deleteAsynchronously(List entities); /** * Remove the given objects from the table by id. - * + * * @param entities The objects to delete * @param listener The {@link DeletionListener} to receive notification upon completion */ @@ -444,7 +444,7 @@ public interface CassandraOperations extends CqlOperations { /** * Remove the given objects from the table by id. - * + * * @param entities The objects to delete * @param options The {@link QueryOptions} to use */ @@ -452,7 +452,7 @@ public interface CassandraOperations extends CqlOperations { /** * Remove the given objects from the table by id. - * + * * @param entities The objects to delete * @param listener The {@link DeletionListener} to receive notification upon completion * @param options The {@link QueryOptions} to use @@ -461,7 +461,7 @@ public interface CassandraOperations extends CqlOperations { /** * Returns the underlying {@link CassandraConverter}. - * + * * @return */ CassandraConverter getConverter(); diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java index 4af90b4c3..23fe62e4c 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/CassandraTemplate.java @@ -67,6 +67,7 @@ import com.datastax.driver.core.querybuilder.Update; * @author Matthew T. Adams * @author Oliver Gierke * @author Mark Paluch + * @author John Blum * @see CqlTemplate * @see CassandraOperations */ @@ -100,13 +101,12 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation setConverter(resolveConverter(converter)); } - /* (non-Javadoc) */ private static CassandraConverter resolveConverter(CassandraConverter cassandraConverter) { return (cassandraConverter != null ? cassandraConverter : getDefaultCassandraConverter()); } - /* (non-Javadoc) */ private static CassandraConverter getDefaultCassandraConverter() { + MappingCassandraConverter mappingCassandraConverter = new MappingCassandraConverter(); mappingCassandraConverter.afterPropertiesSet(); return mappingCassandraConverter;