diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java b/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java index f6a7ca656..b728de101 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/config/CassandraCqlClusterFactoryBean.java @@ -336,10 +336,10 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean, Ini private static Compression convertCompressionType(CompressionType type) { switch (type) { - case NONE: - return Compression.NONE; - case SNAPPY: - return Compression.SNAPPY; + case NONE: + return Compression.NONE; + case SNAPPY: + return Compression.SNAPPY; } throw new IllegalArgumentException("unknown compression type " + type); } diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/KeyspaceActionSpecificationFactoryBean.java b/spring-cql/src/main/java/org/springframework/cassandra/config/KeyspaceActionSpecificationFactoryBean.java index 5e8fdff3a..c64df1b17 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/config/KeyspaceActionSpecificationFactoryBean.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/config/KeyspaceActionSpecificationFactoryBean.java @@ -35,13 +35,11 @@ import org.springframework.cassandra.core.keyspace.Option; import org.springframework.util.Assert; /** - * A single keyspace XML Element can result in multiple actions. Example: {@literal CREATE_DROP}. - * - * This FactoryBean inspects the action required to satisfy the keyspace element, and then returns a Set of atomic + * A single keyspace XML Element can result in multiple actions. Example: {@literal CREATE_DROP}. This FactoryBean + * inspects the action required to satisfy the keyspace element, and then returns a Set of atomic * {@link KeyspaceActionSpecification} required to satisfy the configuration action. * * @author David Webb - * */ public class KeyspaceActionSpecificationFactoryBean implements FactoryBean>>, InitializingBean, DisposableBean { @@ -74,14 +72,14 @@ public class KeyspaceActionSpecificationFactoryBean implements FactoryBean - * */ public class MultiLevelListFlattenerFactoryBean implements FactoryBean> { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/MultiLevelSetFlattenerFactoryBean.java b/spring-cql/src/main/java/org/springframework/cassandra/config/MultiLevelSetFlattenerFactoryBean.java index 012adeec8..a695deb1b 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/config/MultiLevelSetFlattenerFactoryBean.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/config/MultiLevelSetFlattenerFactoryBean.java @@ -27,7 +27,6 @@ import org.springframework.beans.factory.FactoryBean; * * @author David Webb * @param - * */ public class MultiLevelSetFlattenerFactoryBean implements FactoryBean> { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/xml/ParsingUtils.java b/spring-cql/src/main/java/org/springframework/cassandra/config/xml/ParsingUtils.java index 2bc664afe..97adf3dc8 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/config/xml/ParsingUtils.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/config/xml/ParsingUtils.java @@ -244,7 +244,6 @@ public class ParsingUtils { * null or empty, and defaultValue is null or empty, then no property is added and this method * silently returns. * @param reference If true, this method will add the property as a reference, else as a value. - * * @see BeanDefinitionBuilder#addPropertyReference(String, String) * @see BeanDefinitionBuilder#addPropertyValue(String, Object) */ diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/AsynchronousQueryListener.java b/spring-cql/src/main/java/org/springframework/cassandra/core/AsynchronousQueryListener.java index 1b82f0229..ecbf904fa 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/AsynchronousQueryListener.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/AsynchronousQueryListener.java @@ -21,14 +21,14 @@ import com.datastax.driver.core.ResultSetFuture; * Interface used to give an implementation access to a {@link ResultSetFuture} after the query has completed. * * @author David Webb + * @author Matthew T. Adams */ public interface AsynchronousQueryListener { /** - * Called upon Query Completion. + * Called upon query completion. * - * @param rsf The {@link ResultSetFuture}. Since this isn't called until the asynchronous query completes, it can be - * immediately interrogated. + * @param rsf The {@link ResultSetFuture}. Called when the query operation is completed. */ public void onQueryComplete(ResultSetFuture rsf); } diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/CachedPreparedStatementCreator.java b/spring-cql/src/main/java/org/springframework/cassandra/core/CachedPreparedStatementCreator.java index dbdd7c752..5c9019a70 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/CachedPreparedStatementCreator.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/CachedPreparedStatementCreator.java @@ -28,13 +28,10 @@ import com.datastax.driver.core.exceptions.DriverException; /** * This Prepared Statement Creator maintains a cache of all prepared statements for the duration of this life of the - * container. - * - * When preparing statements with Cassandra, each Statement should be prepared once and only once due to the overhead of - * preparing the statement. + * container. When preparing statements with Cassandra, each Statement should be prepared once and only once due to the + * overhead of preparing the statement. * * @author David Webb - * */ public class CachedPreparedStatementCreator implements PreparedStatementCreator { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryCancellor.java b/spring-cql/src/main/java/org/springframework/cassandra/core/Cancellable.java similarity index 86% rename from spring-cql/src/main/java/org/springframework/cassandra/core/QueryCancellor.java rename to spring-cql/src/main/java/org/springframework/cassandra/core/Cancellable.java index a4ec1b975..b599c3ed3 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryCancellor.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/Cancellable.java @@ -20,7 +20,10 @@ package org.springframework.cassandra.core; * * @author Matthew T. Adams */ -public interface QueryCancellor { +public interface Cancellable { - void cancelQuery(boolean mayInterruptIfRunning); + /** + * Cancels the query operation that this cancellable came from. + */ + void cancel(); } diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/CassandraUncategorizedDataAccessException.java b/spring-cql/src/main/java/org/springframework/cassandra/core/CassandraUncategorizedDataAccessException.java index 262972668..6656db25e 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/CassandraUncategorizedDataAccessException.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/CassandraUncategorizedDataAccessException.java @@ -21,7 +21,6 @@ import org.springframework.dao.UncategorizedDataAccessException; * Wrapper for all non RuntimeExceptions throws by the Cassandra Driver * * @author David Webb - * */ public class CassandraUncategorizedDataAccessException extends UncategorizedDataAccessException { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevel.java b/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevel.java index 116ba04c2..098962e58 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevel.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevel.java @@ -19,7 +19,6 @@ package org.springframework.cassandra.core; * Generic Consistency Levels associated with Cassandra. * * @author David Webb - * */ public enum ConsistencyLevel { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevelResolver.java b/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevelResolver.java index fc2fe577d..15ae95ed5 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevelResolver.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevelResolver.java @@ -19,15 +19,13 @@ package org.springframework.cassandra.core; * Determine driver consistency level based on ConsistencyLevel * * @author David Webb - * */ public final class ConsistencyLevelResolver { /** * No instances allowed */ - private ConsistencyLevelResolver() { - } + private ConsistencyLevelResolver() {} /** * Decode the generic spring data cassandra enum to the type required by the DataStax Driver. @@ -43,41 +41,41 @@ public final class ConsistencyLevelResolver { * Determine the driver level based on our enum */ switch (level) { - case ONE: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.ONE; - break; - case LOCAL_ONE: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.LOCAL_ONE; - break; - case ALL: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.ALL; - break; - case ANY: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.ANY; - break; - case EACH_QUOROM: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.EACH_QUORUM; - break; - case LOCAL_QUOROM: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.LOCAL_QUORUM; - break; - case QUOROM: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.QUORUM; - break; - case THREE: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.THREE; - break; - case TWO: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.TWO; - break; - case SERIAL: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.SERIAL; - break; - case LOCAL_SERIAL: - resolvedLevel = com.datastax.driver.core.ConsistencyLevel.LOCAL_SERIAL; - break; - default: - break; + case ONE: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.ONE; + break; + case LOCAL_ONE: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.LOCAL_ONE; + break; + case ALL: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.ALL; + break; + case ANY: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.ANY; + break; + case EACH_QUOROM: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.EACH_QUORUM; + break; + case LOCAL_QUOROM: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.LOCAL_QUORUM; + break; + case QUOROM: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.QUORUM; + break; + case THREE: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.THREE; + break; + case TWO: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.TWO; + break; + case SERIAL: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.SERIAL; + break; + case LOCAL_SERIAL: + resolvedLevel = com.datastax.driver.core.ConsistencyLevel.LOCAL_SERIAL; + break; + default: + break; } return resolvedLevel; 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 5f9263564..a936b1c00 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 @@ -52,6 +52,36 @@ import com.datastax.driver.core.querybuilder.Update; */ public interface CqlOperations { + /** + * Convenient method that delegates to {@link ResultSetFuture#getUninterruptibly()} but translates exceptions if any + * are thrown. + * + * @param rsf The {@link ResultSetFuture} from which to get the {@link ResultSet}. + * @return The {@link ResultSet} + */ + ResultSet getResultSetUninterruptibly(ResultSetFuture rsf); + + /** + * Convenient method that delegates to {@link ResultSetFuture#getUninterruptibly()} but translates exceptions if any + * are thrown. + * + * @param rsf The {@link ResultSetFuture} from which to get the {@link ResultSet}. + * @param timeout The timeout to wait in milliseconds. A nonpositive value means wait indefinitely. + * @return The {@link ResultSet} + */ + ResultSet getResultSetUninterruptibly(ResultSetFuture rsf, long millis); + + /** + * Convenient method that delegates to {@link ResultSetFuture#getUninterruptibly()} but translates exceptions if any + * are thrown. + * + * @param rsf The {@link ResultSetFuture} from which to get the {@link ResultSet}. + * @param timeout The timeout to wait. A nonpositive value means wait indefinitely. + * @param unit The {@link TimeUnit} of the timeout. + * @return The {@link ResultSet} + */ + ResultSet getResultSetUninterruptibly(ResultSetFuture rsf, long timeout, TimeUnit unit); + /** * Executes the supplied {@link SessionCallback} in the current Template Session. The implementation of * SessionCallback can decide whether or not to execute() or executeAsync() the operation. @@ -140,10 +170,10 @@ public interface CqlOperations { * * @param cql The CQL String to execute * @param listener The {@link Runnable} to register with the {@link ResultSetFuture} - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. * @see queryAsyncronously for Reads */ - QueryCancellor executeAsynchronously(String cql, Runnable listener) throws DataAccessException; + Cancellable executeAsynchronously(String cql, Runnable listener) throws DataAccessException; /** * Executes the supplied Query Asynchronously and returns nothing. @@ -151,20 +181,20 @@ public interface CqlOperations { * @param cql The CQL String to execute * @param listener The {@link Runnable} to register with the {@link ResultSetFuture} * @param executor The {@link Executor} to regsiter with the {@link ResultSetFuture} - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. * @see queryAsyncronously for Reads */ - QueryCancellor executeAsynchronously(String cql, Runnable listener, Executor executor) throws DataAccessException; + Cancellable executeAsynchronously(String cql, Runnable listener, Executor executor) throws DataAccessException; /** * Executes the supplied Query Asynchronously and returns nothing. * * @param cql The CQL String to execute * @param listener The {@link AsynchronousQueryListener} to register with the {@link ResultSetFuture} - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. * @see queryAsyncronously for Reads */ - QueryCancellor executeAsynchronously(String cql, AsynchronousQueryListener listener) throws DataAccessException; + Cancellable executeAsynchronously(String cql, AsynchronousQueryListener listener) throws DataAccessException; /** * Executes the supplied Query Asynchronously and returns nothing. @@ -172,10 +202,10 @@ public interface CqlOperations { * @param cql The CQL String to execute * @param listener The {@link AsynchronousQueryListener} to register with the {@link ResultSetFuture} * @param executor The {@link Executor} to regsiter with the {@link ResultSetFuture} - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. * @see queryAsyncronously for Reads */ - QueryCancellor executeAsynchronously(String cql, AsynchronousQueryListener listener, Executor executor) + Cancellable executeAsynchronously(String cql, AsynchronousQueryListener listener, Executor executor) throws DataAccessException; /** @@ -218,6 +248,16 @@ public interface CqlOperations { */ ResultSetFuture executeAsynchronously(Batch batch) throws DataAccessException; + Cancellable executeAsynchronously(Truncate truncate, AsynchronousQueryListener listener) throws DataAccessException; + + Cancellable executeAsynchronously(Delete delete, AsynchronousQueryListener listener) throws DataAccessException; + + Cancellable executeAsynchronously(Insert insert, AsynchronousQueryListener listener) throws DataAccessException; + + Cancellable executeAsynchronously(Update update, AsynchronousQueryListener listener) throws DataAccessException; + + Cancellable executeAsynchronously(Batch batch, AsynchronousQueryListener listener) throws DataAccessException; + /** * Executes the supplied CQL Query Asynchronously and returns nothing. * @@ -230,34 +270,33 @@ public interface CqlOperations { * Executes the supplied CQL Query Asynchronously and returns nothing. * * @param query The {@link Statement} to execute - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor executeAsynchronously(Statement query, Runnable runnable) throws DataAccessException; + Cancellable executeAsynchronously(Statement query, Runnable runnable) throws DataAccessException; /** * Executes the supplied CQL Query Asynchronously and returns nothing. * * @param query The {@link Statement} to execute - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor executeAsynchronously(Statement query, AsynchronousQueryListener listener) throws DataAccessException; + Cancellable executeAsynchronously(Statement query, AsynchronousQueryListener listener) throws DataAccessException; /** * Executes the supplied CQL Query Asynchronously and returns nothing. * * @param query The {@link Statement} to execute - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor executeAsynchronously(Statement query, Runnable runnable, Executor executor) - throws DataAccessException; + Cancellable executeAsynchronously(Statement query, Runnable runnable, Executor executor) throws DataAccessException; /** * Executes the supplied CQL Query Asynchronously and returns nothing. * * @param query The {@link Statement} to execute - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor executeAsynchronously(Statement query, AsynchronousQueryListener listener, Executor executor) + Cancellable executeAsynchronously(Statement query, AsynchronousQueryListener listener, Executor executor) throws DataAccessException; /** @@ -317,10 +356,10 @@ public interface CqlOperations { * * @param cql The Query * @param listener {@link Runnable} listener for handling the query in a separate thread - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. * @see #queryAsynchronously(String, AsynchronousQueryListener) */ - QueryCancellor queryAsynchronously(String cql, Runnable listener); + Cancellable queryAsynchronously(String cql, Runnable listener); /** * Executes the provided CQL Select with the provided {@link Runnable}, which is started after the query has @@ -331,10 +370,10 @@ public interface CqlOperations { * * @param select The Select Query * @param listener {@link Runnable} listener for handling the query in a separate thread - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. * @see #queryAsynchronously(Select, AsynchronousQueryListener) */ - QueryCancellor queryAsynchronously(Select select, Runnable listener); + Cancellable queryAsynchronously(Select select, Runnable listener); /** * Executes the provided CQL Query with the provided listener. This is preferred over the same method that takes a @@ -344,9 +383,9 @@ public interface CqlOperations { * @param cql The Query * @param listener {@link AsynchronousQueryListener} for handling the query's {@link ResultSetFuture} in a separate * thread - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(String cql, AsynchronousQueryListener listener); + Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener); /** * Executes the provided CQL Select with the provided listener. This is preferred over the same method that takes a @@ -356,9 +395,9 @@ public interface CqlOperations { * @param select The Select * @param listener {@link AsynchronousQueryListener} for handling the query's {@link ResultSetFuture} in a separate * thread - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(Select select, AsynchronousQueryListener listener); + Cancellable queryAsynchronously(Select select, AsynchronousQueryListener listener); /** * Executes the provided CQL Query with the Runnable implementations using the Query Options. @@ -366,9 +405,9 @@ public interface CqlOperations { * @param cql The Query * @param options Query Option * @param listener Runnable Listener for handling the query in a separate thread - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(String cql, Runnable listener, QueryOptions options); + Cancellable queryAsynchronously(String cql, Runnable listener, QueryOptions options); /** * Executes the provided CQL Query with the provided Listener and Query Options. This is preferred over the same @@ -378,9 +417,9 @@ public interface CqlOperations { * @param cql The Query * @param options Query Option * @param listener Runnable Listener for handling the query in a separate thread - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(String cql, AsynchronousQueryListener listener, QueryOptions options); + Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener, QueryOptions options); /** * Executes the provided CQL Query with the provided Executor and Runnable implementations. @@ -388,9 +427,9 @@ public interface CqlOperations { * @param cql The Query * @param listener Runnable Listener for handling the query in a separate thread * @param executor To execute the Runnable Listener - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(String cql, Runnable listener, Executor executor); + Cancellable queryAsynchronously(String cql, Runnable listener, Executor executor); /** * Executes the provided CQL Select with the provided Executor and Runnable implementations. @@ -398,9 +437,9 @@ public interface CqlOperations { * @param select The Select Query * @param listener Runnable Listener for handling the query in a separate thread * @param executor To execute the Runnable Listener - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(Select select, Runnable listener, Executor executor); + Cancellable queryAsynchronously(Select select, Runnable listener, Executor executor); /** * Executes the provided CQL Query with the provided listener and executor. This is preferred over the same method @@ -411,9 +450,9 @@ public interface CqlOperations { * @param options Query Option * @param listener Runnable Listener for handling the query in a separate thread * @param executor To execute the Runnable Listener - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(String cql, AsynchronousQueryListener listener, Executor executor); + Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener, Executor executor); /** * Executes the provided Select Query with the provided listener and executor. This is preferred over the same method @@ -423,9 +462,9 @@ public interface CqlOperations { * @param select The Select Query * @param listener Runnable Listener for handling the query in a separate thread * @param executor To execute the Runnable Listener - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(Select select, AsynchronousQueryListener listener, Executor executor); + Cancellable queryAsynchronously(Select select, AsynchronousQueryListener listener, Executor executor); /** * Executes the provided CQL Query with the provided Executor and Runnable implementations. @@ -434,9 +473,9 @@ public interface CqlOperations { * @param options Query Option * @param listener Runnable Listener for handling the query in a separate thread * @param executor To execute the Runnable Listener - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(String cql, Runnable listener, QueryOptions options, Executor executor); + Cancellable queryAsynchronously(String cql, Runnable listener, QueryOptions options, Executor executor); /** * Executes the provided CQL Query with the provided Listener, Executor and Query Options. This is preferred over the @@ -447,9 +486,9 @@ public interface CqlOperations { * @param listener * @param options * @param executor - * @return A {@link QueryCancellor} that can be used to cancel the query. + * @return A {@link Cancellable} that can be used to cancel the query. */ - QueryCancellor queryAsynchronously(String cql, AsynchronousQueryListener listener, QueryOptions options, + Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener, QueryOptions options, Executor executor); /** @@ -590,6 +629,43 @@ public interface CqlOperations { */ List process(ResultSet resultSet, RowMapper rowMapper) throws DataAccessException; + /** + * Executes the provided string CQL query, and maps the first row returned with the supplied {@link RowMapper}. + * + * @param cql The string query CQL. + * @param rowMapper The {@link RowMapper} to convert the row into an object of type T. + * @param listener The listener that receives the results upon completion. + * @return A {@link Cancellable} that can be used to cancel the query. + * @throws DataAccessException + */ + Cancellable queryForObjectAsynchronously(String cql, RowMapper rowMapper, QueryForObjectListener listener) + throws DataAccessException; + + /** + * Executes the provided string CQL query, and maps the first row returned with the supplied {@link RowMapper}. + * + * @param cql The string query CQL. + * @param rowMapper The {@link RowMapper} to convert the row into an object of type T. + * @param listener The listener that receives the results upon completion. + * @param options The {@link QueryOptions} to use. May be null. + * @return A {@link Cancellable} that can be used to cancel the query. + * @throws DataAccessException + */ + Cancellable queryForObjectAsynchronously(String cql, RowMapper rowMapper, QueryForObjectListener listener, + QueryOptions options) throws DataAccessException; + + /** + * Executes the provided {@link Select} query, and maps the first row returned with the supplied {@link RowMapper}. + * + * @param select The {@link Select} query to execute. + * @param rowMapper The {@link RowMapper} to convert the row into an object of type T. + * @param listener The listener that receives the results upon completion. + * @return A {@link Cancellable} that can be used to cancel the query. + * @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. *

@@ -638,6 +714,43 @@ public interface CqlOperations { */ T queryForObject(String cql, Class requiredType) throws DataAccessException; + /** + * Executes the provided {@link Select} query and returns the first column of the first Row as an object of type + * T. + * + * @param select The {@link Select} query + * @param requiredType Type that Cassandra data types can be converted to. + * @return A {@link Cancellable} that can be used to cancel the query if necessary. + * @throws DataAccessException + */ + Cancellable queryForObjectAsynchronously(Select select, Class requiredType, QueryForObjectListener listener) + throws DataAccessException; + + /** + * Executes the provided select CQL query and returns the first column of the first Row as an object of type + * T. + * + * @param cql The select query CQL. Must not be null or blank. + * @param requiredType The type to convert the first column of the first row to. Must not be null. + * @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be null. + * @throws DataAccessException + */ + Cancellable queryForObjectAsynchronously(String cql, Class requiredType, QueryForObjectListener listener) + throws DataAccessException; + + /** + * Executes the provided select CQL query and returns the first column of the first Row as an object of type + * T. + * + * @param cql The select query CQL. Must not be null or blank. + * @param requiredType The type to convert the first column of the first row to. Must not be null. + * @param options The {@link QueryOptions} to use. May be null. + * @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be null. + * @throws DataAccessException + */ + Cancellable queryForObjectAsynchronously(String cql, Class requiredType, QueryForObjectListener listener, + QueryOptions options) throws DataAccessException; + /** * Executes the provided Select query and tries to return the first column of the first Row as a Class. * @@ -680,6 +793,44 @@ public interface CqlOperations { */ Map queryForMap(Select select) throws DataAccessException; + /** + * Executes the provided CQL query asynchronously and maps the first row to a {@link Map}<String,Object>. + * Additional rows are ignored. + * + * @param cql The select query CQL. Must not be null or blank. + * @param listener The {@link QueryForMapListener} that will recieve the results upon query completion. Must not be + * null. + * @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be null. + * @throws DataAccessException + */ + Cancellable queryForMapAsynchronously(String cql, QueryForMapListener listener) throws DataAccessException; + + /** + * Executes the provided CQL query asynchronously and maps the first row to a {@link Map}<String,Object>. + * Additional rows are ignored. + * + * @param cql The select query CQL. Must not be null or blank. + * @param listener The {@link QueryForMapListener} that will recieve the results upon query completion. Must not be + * null. + * @param options The {@link QueryOptions} to use. May be null. + * @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be null. + * @throws DataAccessException + */ + Cancellable queryForMapAsynchronously(String cql, QueryForMapListener listener, QueryOptions options) + throws DataAccessException; + + /** + * Executes the provided {@link Select} query asynchronously and maps the first row to a {@link Map} + * <String,Object>. Additional rows are ignored. + * + * @param cql The select query CQL. Must not be null or blank. + * @param listener The {@link QueryForMapListener} that will recieve the results upon query completion. Must not be + * null. + * @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be null. + * @throws DataAccessException + */ + Cancellable queryForMapAsynchronously(Select select, QueryForMapListener listener) throws DataAccessException; + /** * Process a ResultSet with ONE Row and convert to a Map. This is used internal to the Template for core * operations, but is made available through Operations in the event you have a ResultSet to process. The ResultsSet @@ -713,6 +864,32 @@ public interface CqlOperations { */ List queryForList(Select select, Class elementType) throws DataAccessException; + /** + * Executes the provided {@link Select} query asynchronously and returns all values in the first column of the results + * as a {@link List} of the type in the second argument. + * + * @param select The {@link Select} query + * @param elementType The type to cast the data values to + * @param listener The listener to receive the results asynchronously. Must not be null. + * @return {@link Cancellable} to cancel the query if necessary + * @throws DataAccessException + */ + Cancellable queryForListAsynchronously(Select select, Class elementType, QueryForListListener listener) + throws DataAccessException; + + /** + * Executes the provided {@link Select} query asynchronously and returns all values in the first column of the results + * as a {@link List} of the type in the second argument. + * + * @param select The select query CQL + * @param elementType The type to cast the data values to + * @param listener The listener to receive the results asynchronously. Must not be null. + * @return {@link Cancellable} to cancel the query if necessary + * @throws DataAccessException + */ + Cancellable queryForListAsynchronously(String select, Class elementType, QueryForListListener listener) + throws DataAccessException; + /** * Process a ResultSet and convert the first column of the results to a List. This is used internal to the Template * for core operations, but is made available through Operations in the event you have a ResultSet to process. The @@ -735,6 +912,46 @@ public interface CqlOperations { */ List> queryForListOfMap(String cql) throws DataAccessException; + /** + * Executes the provided {@link Select} query and converts the results to a {@link List} of {@link Map}s. Each element + * in the {@link List} represents a row returned from the query. Each row's column(s) are put into a {@link Map} as + * values keyed by column name. + * + * @param select The {@link Select} query. Must not be null. + * @param listener The listener that will receive the results upon query completion. Must not be null. + * @return A {@link Cancellable} that can be used to cancel the query. Must not be null. + * @throws DataAccessException + */ + Cancellable queryForListOfMapAsynchronously(Select select, QueryForListListener> listener) + throws DataAccessException; + + /** + * Executes the provided select CQL query and converts the results to a {@link List} of {@link Map}s. Each element in + * the {@link List} represents a row returned from the query. Each row's column(s) are put into a {@link Map} as + * values keyed by column name. + * + * @param select The select query CQL. Must not be null or blank. + * @param listener The listener that will receive the results upon query completion. Must not be null. + * @return A {@link Cancellable} that can be used to cancel the query. Must not be null. + * @throws DataAccessException + */ + Cancellable queryForListOfMapAsynchronously(String cql, QueryForListListener> listener) + throws DataAccessException; + + /** + * Executes the provided select CQL query and converts the results to a {@link List} of {@link Map}s. Each element in + * the {@link List} represents a row returned from the query. Each row's column(s) are put into a {@link Map} as + * values keyed by column name. + * + * @param select The select query CQL. Must not be null or blank. + * @param listener The listener that will receive the results upon query completion. Must not be null. + * @param options The {@link QueryOptions} to use. May be null. + * @return A {@link Cancellable} that can be used to cancel the query. Must not be null. + * @throws DataAccessException + */ + Cancellable queryForListOfMapAsynchronously(String cql, QueryForListListener> listener, + QueryOptions options) throws DataAccessException; + /** * Executes the provided Select Query and converts the results to a basic List of Maps. Each element in the List * represents a Row returned from the Query. Each Row's columns are put into the map as column/value. 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 c6b73bf91..f76336abd 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 @@ -279,7 +279,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor queryAsynchronously(String cql, Runnable listener) { + public Cancellable queryAsynchronously(String cql, Runnable listener) { return queryAsynchronously(cql, listener, new Executor() { @Override public void execute(Runnable command) { @@ -289,7 +289,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor queryAsynchronously(String cql, AsynchronousQueryListener listener) { + public Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener) { return queryAsynchronously(cql, listener, new Executor() { @Override public void execute(Runnable command) { @@ -299,7 +299,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor queryAsynchronously(String cql, Runnable listener, QueryOptions options) { + public Cancellable queryAsynchronously(String cql, Runnable listener, QueryOptions options) { return queryAsynchronously(cql, listener, options, new Executor() { @Override public void execute(Runnable command) { @@ -309,7 +309,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor queryAsynchronously(String cql, AsynchronousQueryListener listener, QueryOptions options) { + public Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener, QueryOptions options) { return queryAsynchronously(cql, listener, options, new Executor() { @Override public void execute(Runnable command) { @@ -319,36 +319,36 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor queryAsynchronously(String cql, Runnable listener, Executor executor) { + public Cancellable queryAsynchronously(String cql, Runnable listener, Executor executor) { return queryAsynchronously(cql, listener, null, executor); } @Override - public QueryCancellor queryAsynchronously(String cql, AsynchronousQueryListener listener, Executor executor) { + public Cancellable queryAsynchronously(String cql, AsynchronousQueryListener listener, Executor executor) { return queryAsynchronously(cql, listener, null, executor); } @Override - public QueryCancellor queryAsynchronously(final String cql, final Runnable listener, final QueryOptions options, + public Cancellable queryAsynchronously(final String cql, final Runnable listener, final QueryOptions options, final Executor executor) { - return execute(new SessionCallback() { + return execute(new SessionCallback() { @Override - public QueryCancellor doInSession(Session s) throws DataAccessException { + public Cancellable doInSession(Session s) throws DataAccessException { Statement statement = new SimpleStatement(cql); addQueryOptions(statement, options); ResultSetFuture rsf = s.executeAsync(statement); rsf.addListener(listener, executor); - return new BasicQueryCancellor(rsf); + return new ResultSetFutureCancellable(rsf); } }); } @Override - public QueryCancellor queryAsynchronously(final String cql, final AsynchronousQueryListener listener, + public Cancellable queryAsynchronously(final String cql, final AsynchronousQueryListener listener, final QueryOptions options, final Executor executor) { - return execute(new SessionCallback() { + return execute(new SessionCallback() { @Override - public QueryCancellor doInSession(Session s) throws DataAccessException { + public Cancellable doInSession(Session s) throws DataAccessException { Statement statement = new SimpleStatement(cql); addQueryOptions(statement, options); final ResultSetFuture rsf = s.executeAsync(statement); @@ -359,7 +359,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } }; rsf.addListener(wrapper, executor); - return new BasicQueryCancellor(rsf); + return new ResultSetFutureCancellable(rsf); } }); } @@ -518,6 +518,48 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { }); } + protected Cancellable doExecuteAsync(final Statement q, final AsynchronousQueryListener listener) { + return doExecuteAsync(q, listener, null); + } + + protected Cancellable doExecuteAsync(final Statement q, final AsynchronousQueryListener listener, + final QueryOptions options) { + + return doExecute(new SessionCallback() { + + @Override + public Cancellable doInSession(Session s) throws DataAccessException { + + if (log.isDebugEnabled()) { + log.debug("asynchronously executing [{}]", q.toString()); + } + + if (options != null) { + addQueryOptions(q, options); + } + + final ResultSetFuture rsf = s.executeAsync(q); + + if (listener != null) { + rsf.addListener(new Runnable() { + + @Override + public void run() { + listener.onQueryComplete(rsf); + } + }, new Executor() { + + @Override + public void execute(Runnable command) { + command.run(); + } + }); + } + return new ResultSetFutureCancellable(rsf); + } + }); + } + /** * @param row * @return @@ -588,7 +630,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor executeAsynchronously(String cql, Runnable listener) throws DataAccessException { + public Cancellable executeAsynchronously(String cql, Runnable listener) throws DataAccessException { return executeAsynchronously(cql, listener, new Executor() { @Override public void execute(Runnable command) { @@ -598,23 +640,22 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor executeAsynchronously(final String cql, final Runnable listener, final Executor executor) + public Cancellable executeAsynchronously(final String cql, final Runnable listener, final Executor executor) throws DataAccessException { - return execute(new SessionCallback() { + return execute(new SessionCallback() { @Override - public QueryCancellor doInSession(Session s) throws DataAccessException { + public Cancellable doInSession(Session s) throws DataAccessException { Statement statement = new SimpleStatement(cql); final ResultSetFuture rsf = s.executeAsync(statement); rsf.addListener(listener, executor); - return new BasicQueryCancellor(rsf); + return new ResultSetFutureCancellable(rsf); } }); } @Override - public QueryCancellor executeAsynchronously(String cql, AsynchronousQueryListener listener) - throws DataAccessException { + public Cancellable executeAsynchronously(String cql, AsynchronousQueryListener listener) throws DataAccessException { return executeAsynchronously(cql, listener, new Executor() { @Override @@ -625,12 +666,12 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor executeAsynchronously(final String cql, final AsynchronousQueryListener listener, + public Cancellable executeAsynchronously(final String cql, final AsynchronousQueryListener listener, final Executor executor) throws DataAccessException { - return execute(new SessionCallback() { + return execute(new SessionCallback() { @Override - public QueryCancellor doInSession(Session s) throws DataAccessException { + public Cancellable doInSession(Session s) throws DataAccessException { Statement statement = new SimpleStatement(cql); final ResultSetFuture rsf = s.executeAsync(statement); Runnable wrapper = new Runnable() { @@ -640,7 +681,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } }; rsf.addListener(wrapper, executor); - return new BasicQueryCancellor(rsf); + return new ResultSetFutureCancellable(rsf); } }); } @@ -651,7 +692,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor executeAsynchronously(Statement query, Runnable listener) throws DataAccessException { + public Cancellable executeAsynchronously(Statement query, Runnable listener) throws DataAccessException { return executeAsynchronously(query, listener, new Executor() { @Override public void execute(Runnable command) { @@ -661,7 +702,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor executeAsynchronously(Statement query, AsynchronousQueryListener listener) + public Cancellable executeAsynchronously(Statement query, AsynchronousQueryListener listener) throws DataAccessException { return executeAsynchronously(query, listener, new Executor() { @Override @@ -672,34 +713,36 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor executeAsynchronously(final Statement query, final Runnable listener, final Executor executor) + public Cancellable executeAsynchronously(final Statement query, final Runnable listener, final Executor executor) throws DataAccessException { - return execute(new SessionCallback() { + return execute(new SessionCallback() { @Override - public QueryCancellor doInSession(Session s) throws DataAccessException { + public Cancellable doInSession(Session s) throws DataAccessException { final ResultSetFuture rsf = s.executeAsync(query); rsf.addListener(listener, executor); - return new BasicQueryCancellor(rsf); + return new ResultSetFutureCancellable(rsf); } }); } @Override - public QueryCancellor executeAsynchronously(final Statement query, final AsynchronousQueryListener listener, + public Cancellable executeAsynchronously(final Statement query, final AsynchronousQueryListener listener, final Executor executor) throws DataAccessException { - return execute(new SessionCallback() { + return execute(new SessionCallback() { @Override - public QueryCancellor doInSession(Session s) throws DataAccessException { + public Cancellable doInSession(Session s) throws DataAccessException { final ResultSetFuture rsf = s.executeAsync(query); - Runnable wrapper = new Runnable() { - @Override - public void run() { - listener.onQueryComplete(rsf); - } - }; - rsf.addListener(wrapper, executor); - return new BasicQueryCancellor(rsf); + if (listener != null) { + Runnable wrapper = new Runnable() { + @Override + public void run() { + listener.onQueryComplete(rsf); + } + }; + rsf.addListener(wrapper, executor); + } + return new ResultSetFutureCancellable(rsf); } }); } @@ -1231,6 +1274,35 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { return doExecuteAsync(batch); } + @Override + public Cancellable executeAsynchronously(Truncate truncate, AsynchronousQueryListener listener) + throws DataAccessException { + return doExecuteAsync(truncate, listener); + } + + @Override + public Cancellable executeAsynchronously(Delete delete, AsynchronousQueryListener listener) + throws DataAccessException { + return doExecuteAsync(delete, listener); + } + + @Override + public Cancellable executeAsynchronously(Insert insert, AsynchronousQueryListener listener) + throws DataAccessException { + return doExecuteAsync(insert, listener); + } + + @Override + public Cancellable executeAsynchronously(Update update, AsynchronousQueryListener listener) + throws DataAccessException { + return doExecuteAsync(update, listener); + } + + @Override + public Cancellable executeAsynchronously(Batch batch, AsynchronousQueryListener listener) throws DataAccessException { + return doExecuteAsync(batch, listener); + } + @Override public ResultSetFuture queryAsynchronously(final Select select) { return execute(new SessionCallback() { @@ -1242,7 +1314,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor queryAsynchronously(Select select, Runnable listener) { + public Cancellable queryAsynchronously(Select select, Runnable listener) { return queryAsynchronously(select, listener, new Executor() { @Override public void execute(Runnable command) { @@ -1252,7 +1324,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor queryAsynchronously(Select select, AsynchronousQueryListener listener) { + public Cancellable queryAsynchronously(Select select, AsynchronousQueryListener listener) { return queryAsynchronously(select, listener, new Executor() { @Override public void execute(Runnable command) { @@ -1262,12 +1334,12 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } @Override - public QueryCancellor queryAsynchronously(final Select select, final AsynchronousQueryListener listener, + public Cancellable queryAsynchronously(final Select select, final AsynchronousQueryListener listener, final Executor executor) { - return execute(new SessionCallback() { + return execute(new SessionCallback() { @Override - public QueryCancellor doInSession(Session s) throws DataAccessException { + public Cancellable doInSession(Session s) throws DataAccessException { final ResultSetFuture rsf = s.executeAsync(select); Runnable wrapper = new Runnable() { @Override @@ -1276,19 +1348,19 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { } }; rsf.addListener(wrapper, executor); - return new BasicQueryCancellor(rsf); + return new ResultSetFutureCancellable(rsf); } }); } @Override - public QueryCancellor queryAsynchronously(final Select select, final Runnable listener, final Executor executor) { - return execute(new SessionCallback() { + public Cancellable queryAsynchronously(final Select select, final Runnable listener, final Executor executor) { + return execute(new SessionCallback() { @Override - public QueryCancellor doInSession(Session s) throws DataAccessException { + public Cancellable doInSession(Session s) throws DataAccessException { ResultSetFuture rsf = s.executeAsync(select); rsf.addListener(listener, executor); - return new BasicQueryCancellor(rsf); + return new ResultSetFutureCancellable(rsf); } }); } @@ -1345,4 +1417,224 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { return processListOfMap(doExecute(select)); } + @Override + public Cancellable queryForListAsynchronously(Select select, final Class elementType, + final QueryForListListener listener) throws DataAccessException { + + Assert.notNull(select); + Assert.notNull(elementType); + Assert.notNull(listener); + + return doExecuteAsync(select, new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processList(rsf.getUninterruptibly(), elementType)); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }); + } + + @Override + public Cancellable queryForListAsynchronously(String select, final Class elementType, + final QueryForListListener listener) throws DataAccessException { + + Assert.hasText(select); + Assert.notNull(elementType); + Assert.notNull(listener); + + return doExecuteAsync(new SimpleStatement(select), new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processList(rsf.getUninterruptibly(), elementType)); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }); + } + + @Override + public Cancellable queryForListOfMapAsynchronously(Select select, + final QueryForListListener> listener) throws DataAccessException { + + return doExecuteAsync(select, new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processListOfMap(rsf.getUninterruptibly())); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }); + } + + @Override + public Cancellable queryForListOfMapAsynchronously(String cql, + final QueryForListListener> listener) throws DataAccessException { + return queryForListOfMapAsynchronously(cql, listener, null); + } + + @Override + public Cancellable queryForListOfMapAsynchronously(String cql, + final QueryForListListener> listener, QueryOptions options) throws DataAccessException { + + return doExecuteAsync(new SimpleStatement(cql), new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processListOfMap(rsf.getUninterruptibly())); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }, options); + } + + @Override + public Cancellable queryForMapAsynchronously(String cql, QueryForMapListener listener) throws DataAccessException { + return queryForMapAsynchronously(cql, listener, null); + } + + @Override + public Cancellable queryForMapAsynchronously(String cql, final QueryForMapListener listener, + final QueryOptions options) throws DataAccessException { + + return doExecuteAsync(new SimpleStatement(cql), new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processMap(rsf.getUninterruptibly())); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }, options); + } + + @Override + public Cancellable queryForMapAsynchronously(Select select, final QueryForMapListener listener) + throws DataAccessException { + + return doExecuteAsync(select, new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processMap(rsf.getUninterruptibly())); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }); + } + + @Override + public Cancellable queryForObjectAsynchronously(Select select, final Class requiredType, + final QueryForObjectListener listener) throws DataAccessException { + + return doExecuteAsync(select, new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processOne(rsf.getUninterruptibly(), requiredType)); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }); + } + + @Override + public Cancellable queryForObjectAsynchronously(String cql, Class requiredType, + QueryForObjectListener listener) throws DataAccessException { + return queryForObjectAsynchronously(cql, requiredType, listener, null); + } + + @Override + public Cancellable queryForObjectAsynchronously(String cql, final Class requiredType, + final QueryForObjectListener listener, QueryOptions options) throws DataAccessException { + + return doExecuteAsync(new SimpleStatement(cql), new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processOne(rsf.getUninterruptibly(), requiredType)); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }, options); + } + + @Override + public Cancellable queryForObjectAsynchronously(String cql, RowMapper rowMapper, + QueryForObjectListener listener) throws DataAccessException { + return queryForObjectAsynchronously(cql, rowMapper, listener, null); + } + + @Override + public Cancellable queryForObjectAsynchronously(String cql, final RowMapper rowMapper, + final QueryForObjectListener listener, QueryOptions options) throws DataAccessException { + + return doExecuteAsync(new SimpleStatement(cql), new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processOne(rsf.getUninterruptibly(), rowMapper)); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }, options); + } + + @Override + public Cancellable queryForObjectAsynchronously(Select select, final RowMapper rowMapper, + final QueryForObjectListener listener) throws DataAccessException { + + return doExecuteAsync(select, new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + listener.onQueryComplete(processOne(rsf.getUninterruptibly(), rowMapper)); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }); + } + + @Override + public ResultSet getResultSetUninterruptibly(ResultSetFuture rsf) { + return getResultSetUninterruptibly(rsf, 0, null); + } + + @Override + public ResultSet getResultSetUninterruptibly(ResultSetFuture rsf, long millis) { + return getResultSetUninterruptibly(rsf, millis, TimeUnit.MILLISECONDS); + } + + @Override + public ResultSet getResultSetUninterruptibly(ResultSetFuture rsf, long timeout, TimeUnit unit) { + try { + return timeout <= 0 ? rsf.getUninterruptibly() : rsf.getUninterruptibly(timeout, + unit == null ? TimeUnit.MILLISECONDS : unit); + } catch (Exception x) { + throw translateExceptionIfPossible(x); + } + } } diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementBinder.java b/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementBinder.java index 2766de45f..da3a25b4b 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementBinder.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementBinder.java @@ -21,7 +21,6 @@ import com.datastax.driver.core.exceptions.DriverException; /** * @author David Webb - * */ public interface PreparedStatementBinder { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementCallback.java b/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementCallback.java index c8e05b9dd..da855c45e 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementCallback.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementCallback.java @@ -22,7 +22,6 @@ import com.datastax.driver.core.exceptions.DriverException; /** * @author David Webb - * */ public interface PreparedStatementCallback { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementCreator.java b/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementCreator.java index 88ea09ac2..c46544fda 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementCreator.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/PreparedStatementCreator.java @@ -23,7 +23,6 @@ import com.datastax.driver.core.exceptions.DriverException; * Creates a PreparedStatement for the usage with the DataStax Java Driver * * @author David Webb - * */ public interface PreparedStatementCreator { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForListListener.java b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForListListener.java new file mode 100644 index 000000000..b787b7ca4 --- /dev/null +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForListListener.java @@ -0,0 +1,24 @@ +package org.springframework.cassandra.core; + +import java.util.List; + +import com.datastax.driver.core.ResultSet; + +/** + * Listener used to receive asynchronous results expected as a List<T>. + * + * @author Matthew T. Adams + * @param + */ +public interface QueryForListListener { + + /** + * Called upon query completion. + */ + void onQueryComplete(List results); + + /** + * Called if an exception is raised while getting or converting the {@link ResultSet}. + */ + void onException(Exception x); +} diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForListOfMapListener.java b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForListOfMapListener.java new file mode 100644 index 000000000..783625a7b --- /dev/null +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForListOfMapListener.java @@ -0,0 +1,10 @@ +package org.springframework.cassandra.core; + +import java.util.Map; + +/** + * Listener used to receive asynchronous results expected as a List<T>. + * + * @author Matthew T. Adams + */ +public interface QueryForListOfMapListener extends QueryForListListener> {} diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForMapListener.java b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForMapListener.java new file mode 100644 index 000000000..6b75ee0e4 --- /dev/null +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForMapListener.java @@ -0,0 +1,24 @@ +package org.springframework.cassandra.core; + +import java.util.Map; + +import com.datastax.driver.core.ResultSet; + +/** + * Listener used to receive asynchronous results expected as a List<Map<String,Object>>. + * + * @author Matthew T. Adams + * @param + */ +public interface QueryForMapListener { + + /** + * Called upon query completion. + */ + void onQueryComplete(Map results); + + /** + * Called if an exception is raised while getting or converting the {@link ResultSet}. + */ + void onException(Exception x); +} diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForObjectListener.java b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForObjectListener.java new file mode 100644 index 000000000..d4c1c8cb9 --- /dev/null +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryForObjectListener.java @@ -0,0 +1,22 @@ +package org.springframework.cassandra.core; + +import com.datastax.driver.core.ResultSet; + +/** + * Listener used to receive asynchronous results expected as an object of type T. + * + * @author Matthew T. Adams + * @param + */ +public interface QueryForObjectListener { + + /** + * Called upon query completion. + */ + void onQueryComplete(T result); + + /** + * Called if an exception is raised while getting or converting the {@link ResultSet}. + */ + void onException(Exception x); +} diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryOptions.java b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryOptions.java index a25481f75..2e8e107b7 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryOptions.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryOptions.java @@ -19,13 +19,19 @@ package org.springframework.cassandra.core; * Contains Query Options for Cassandra queries. This controls the Consistency Tuning and Retry Policy for a Query. * * @author David Webb - * */ public class QueryOptions { private ConsistencyLevel consistencyLevel; private RetryPolicy retryPolicy; + public QueryOptions() {} + + public QueryOptions(ConsistencyLevel consistencyLevel, RetryPolicy retryPolicy) { + setConsistencyLevel(consistencyLevel); + setRetryPolicy(retryPolicy); + } + /** * @return Returns the consistencyLevel. */ diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/ReservedKeyword.java b/spring-cql/src/main/java/org/springframework/cassandra/core/ReservedKeyword.java index 1b623552d..f1a5e6ba5 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/ReservedKeyword.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/ReservedKeyword.java @@ -8,11 +8,57 @@ import org.springframework.util.StringUtils; * * @see http://cassandra.apache.org/doc/cql3/CQL.html#appendixA - * * @author Matthew T. Adams */ public enum ReservedKeyword { - ADD, ALTER, AND, ANY, APPLY, ASC, AUTHORIZE, BATCH, BEGIN, BY, COLUMNFAMILY, CREATE, DELETE, DESC, DROP, EACH_QUORUM, FROM, GRANT, IN, INDEX, INSERT, INTO, KEYSPACE, LIMIT, LOCAL_ONE, LOCAL_QUORUM, MODIFY, NORECURSIVE, OF, ON, ONE, ORDER, PRIMARY, QUORUM, REVOKE, SCHEMA, SELECT, SET, TABLE, THREE, TOKEN, TRUNCATE, TWO, UPDATE, USE, USING, WHERE, WITH; + ADD, + ALTER, + AND, + ANY, + APPLY, + ASC, + AUTHORIZE, + BATCH, + BEGIN, + BY, + COLUMNFAMILY, + CREATE, + DELETE, + DESC, + DROP, + EACH_QUORUM, + FROM, + GRANT, + IN, + INDEX, + INSERT, + INTO, + KEYSPACE, + LIMIT, + LOCAL_ONE, + LOCAL_QUORUM, + MODIFY, + NORECURSIVE, + OF, + ON, + ONE, + ORDER, + PRIMARY, + QUORUM, + REVOKE, + SCHEMA, + SELECT, + SET, + TABLE, + THREE, + TOKEN, + TRUNCATE, + TWO, + UPDATE, + USE, + USING, + WHERE, + WITH; /** * @see ReservedKeyword#isReserved(String) diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/BasicQueryCancellor.java b/spring-cql/src/main/java/org/springframework/cassandra/core/ResultSetFutureCancellable.java similarity index 74% rename from spring-cql/src/main/java/org/springframework/cassandra/core/BasicQueryCancellor.java rename to spring-cql/src/main/java/org/springframework/cassandra/core/ResultSetFutureCancellable.java index 00f77d3d7..f204a9e3c 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/BasicQueryCancellor.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/ResultSetFutureCancellable.java @@ -18,20 +18,20 @@ package org.springframework.cassandra.core; import com.datastax.driver.core.ResultSetFuture; /** - * Convenient default implementation of a {@link QueryCancellor}. + * Convenient default implementation of a {@link Cancellable}. * * @author Matthew T. Adams */ -public class BasicQueryCancellor implements QueryCancellor { +public class ResultSetFutureCancellable implements Cancellable { ResultSetFuture rsf; - public BasicQueryCancellor(ResultSetFuture rsf) { + public ResultSetFutureCancellable(ResultSetFuture rsf) { this.rsf = rsf; } @Override - public void cancelQuery(boolean mayInterruptIfRunning) { - rsf.cancel(mayInterruptIfRunning); + public void cancel() { + rsf.cancel(true); } } diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicy.java b/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicy.java index e7577398d..6be251ff8 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicy.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicy.java @@ -19,7 +19,6 @@ package org.springframework.cassandra.core; * Retry Policies associated with Cassandra. * * @author David Webb - * */ public enum RetryPolicy { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicyResolver.java b/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicyResolver.java index 83b27529d..7ae94c918 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicyResolver.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicyResolver.java @@ -23,15 +23,13 @@ import com.datastax.driver.core.policies.FallthroughRetryPolicy; * Determine driver query retry policy * * @author David Webb - * */ public final class RetryPolicyResolver { /** * No instances allowed */ - private RetryPolicyResolver() { - } + private RetryPolicyResolver() {} /** * Decode the generic spring data cassandra enum to the type required by the DataStax Driver. @@ -47,18 +45,18 @@ public final class RetryPolicyResolver { * Determine the driver level based on our enum */ switch (policy) { - case DEFAULT: - resolvedPolicy = DefaultRetryPolicy.INSTANCE; - break; - case DOWNGRADING_CONSISTENCY: - resolvedPolicy = DowngradingConsistencyRetryPolicy.INSTANCE; - break; - case FALLTHROUGH: - resolvedPolicy = FallthroughRetryPolicy.INSTANCE; - break; - default: - resolvedPolicy = DefaultRetryPolicy.INSTANCE; - break; + case DEFAULT: + resolvedPolicy = DefaultRetryPolicy.INSTANCE; + break; + case DOWNGRADING_CONSISTENCY: + resolvedPolicy = DowngradingConsistencyRetryPolicy.INSTANCE; + break; + case FALLTHROUGH: + resolvedPolicy = FallthroughRetryPolicy.INSTANCE; + break; + default: + resolvedPolicy = DefaultRetryPolicy.INSTANCE; + break; } return resolvedPolicy; diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/RingMember.java b/spring-cql/src/main/java/org/springframework/cassandra/core/RingMember.java index 9470967ab..5fcc736b9 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/RingMember.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/RingMember.java @@ -21,7 +21,6 @@ import com.datastax.driver.core.Host; /** * @author David Webb - * */ public final class RingMember implements Serializable { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/RingMemberHostMapper.java b/spring-cql/src/main/java/org/springframework/cassandra/core/RingMemberHostMapper.java index bd4f8557d..e9c474801 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/RingMemberHostMapper.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/RingMemberHostMapper.java @@ -27,7 +27,6 @@ import com.datastax.driver.core.exceptions.DriverException; /** * @author David Webb * @param - * */ public class RingMemberHostMapper implements HostMapper { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/RowIterator.java b/spring-cql/src/main/java/org/springframework/cassandra/core/RowIterator.java index 60c6dc7dd..cac4f1afb 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/RowIterator.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/RowIterator.java @@ -15,10 +15,8 @@ */ package org.springframework.cassandra.core; - /** * @author David Webb - * */ public interface RowIterator { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/SessionCallback.java b/spring-cql/src/main/java/org/springframework/cassandra/core/SessionCallback.java index be3fbc324..130088e95 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/SessionCallback.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/SessionCallback.java @@ -23,7 +23,6 @@ import com.datastax.driver.core.Session; * Interface for operations on a Cassandra Session. * * @author David Webb - * * @param */ public interface SessionCallback { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/SimplePreparedStatementCreator.java b/spring-cql/src/main/java/org/springframework/cassandra/core/SimplePreparedStatementCreator.java index 4eb35f011..9880d6b2a 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/SimplePreparedStatementCreator.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/SimplePreparedStatementCreator.java @@ -23,13 +23,11 @@ import com.datastax.driver.core.exceptions.DriverException; /** * This Prepared Statement Creator simply prepares a statement from the CQL string. This should not be used in - * Production systems with high volume reads and writes. Use {@link CachedPreparedStatementCreator} - * - * When preparing statements with Cassandra, each Statement should be prepared once and only once due to the overhead of - * preparing the statement. + * Production systems with high volume reads and writes. Use {@link CachedPreparedStatementCreator} When preparing + * statements with Cassandra, each Statement should be prepared once and only once due to the overhead of preparing the + * statement. * * @author David Webb - * */ public class SimplePreparedStatementCreator implements PreparedStatementCreator { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/WriteOptions.java b/spring-cql/src/main/java/org/springframework/cassandra/core/WriteOptions.java index 00467c8cd..ef2448d4d 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/WriteOptions.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/WriteOptions.java @@ -17,12 +17,22 @@ package org.springframework.cassandra.core; /** * @author David Webb - * */ public class WriteOptions extends QueryOptions { private Integer ttl; + public WriteOptions() {} + + public WriteOptions(ConsistencyLevel consistencyLevel, RetryPolicy retryPolicy) { + this(consistencyLevel, retryPolicy, null); + } + + public WriteOptions(ConsistencyLevel consistencyLevel, RetryPolicy retryPolicy, Integer ttl) { + super(consistencyLevel, retryPolicy); + setTtl(ttl); + } + /** * @return Returns the ttl. */ diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/converter/AbstractResultSetConverter.java b/spring-cql/src/main/java/org/springframework/cassandra/core/converter/AbstractResultSetConverter.java index 8193a58df..bf6d2ea70 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/converter/AbstractResultSetConverter.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/converter/AbstractResultSetConverter.java @@ -24,7 +24,6 @@ import com.datastax.driver.core.ResultSet; * {@link IllegalArgumentException}. * * @author Matthew T. Adams - * * @param */ public abstract class AbstractResultSetConverter implements Converter { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/converter/AbstractResultSetToBasicFixedTypeConverter.java b/spring-cql/src/main/java/org/springframework/cassandra/core/converter/AbstractResultSetToBasicFixedTypeConverter.java index 29c6eb2b6..6cdfb3cf5 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/converter/AbstractResultSetToBasicFixedTypeConverter.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/converter/AbstractResultSetToBasicFixedTypeConverter.java @@ -7,7 +7,6 @@ import org.springframework.core.convert.support.DefaultConversionService; * Thin wrapper that allows subclasses to delegate conversion of the given value to a {@link DefaultConversionService}. * * @author Matthew T. Adams - * * @param */ public abstract class AbstractResultSetToBasicFixedTypeConverter extends AbstractResultSetConverter { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/converter/ResultSetToListConverter.java b/spring-cql/src/main/java/org/springframework/cassandra/core/converter/ResultSetToListConverter.java index aef37815d..991603b31 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/converter/ResultSetToListConverter.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/converter/ResultSetToListConverter.java @@ -15,8 +15,7 @@ public class ResultSetToListConverter implements Converter> rowConverter = new RowToMapConverter(); - public ResultSetToListConverter() { - } + public ResultSetToListConverter() {} public ResultSetToListConverter(Converter> rowConverter) { setRowConverter(rowConverter); diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/cql/CqlConstantType.java b/spring-cql/src/main/java/org/springframework/cassandra/core/cql/CqlConstantType.java index 9fea872e3..ff252ba9d 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/cql/CqlConstantType.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/cql/CqlConstantType.java @@ -5,8 +5,12 @@ import java.util.regex.Pattern; public enum CqlConstantType { - STRING(STRING_PATTERN), INTEGER(INTEGER_PATTERN), FLOAT(FLOAT_PATTERN), BOOLEAN(BOOLEAN_PATTERN), UUID(UUID_PATTERN), BLOB( - BLOB_PATTERN); + STRING(STRING_PATTERN), + INTEGER(INTEGER_PATTERN), + FLOAT(FLOAT_PATTERN), + BOOLEAN(BOOLEAN_PATTERN), + UUID(UUID_PATTERN), + BLOB(BLOB_PATTERN); private Pattern pattern; @@ -38,4 +42,4 @@ public enum CqlConstantType { public static final String BLOB_REGEX = "(?i)0[x](0-9a-f)+"; public static final Pattern BLOB_PATTERN = Pattern.compile(BLOB_REGEX); } -} \ No newline at end of file +} diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/cql/CqlIdentifier.java b/spring-cql/src/main/java/org/springframework/cassandra/core/cql/CqlIdentifier.java index a4fb3df47..4e9997836 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/cql/CqlIdentifier.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/cql/CqlIdentifier.java @@ -21,7 +21,6 @@ import com.datastax.driver.core.TableMetadata; * @see #toCql() * @see #toCql(StringBuilder) * @see #toString() - * * @author John McPeek * @author Matthew T. Adams */ diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/cql/KeyspaceIdentifier.java b/spring-cql/src/main/java/org/springframework/cassandra/core/cql/KeyspaceIdentifier.java index 062c4626a..4d5988cf5 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/cql/KeyspaceIdentifier.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/cql/KeyspaceIdentifier.java @@ -15,7 +15,6 @@ import org.springframework.util.Assert; * @see #toCql() * @see #toCql(StringBuilder) * @see #toString() - * * @author Matthew T. Adams */ public final class KeyspaceIdentifier implements Comparable { diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/cql/generator/CreateIndexCqlGenerator.java b/spring-cql/src/main/java/org/springframework/cassandra/core/cql/generator/CreateIndexCqlGenerator.java index 4b889036d..a151d4c4b 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/cql/generator/CreateIndexCqlGenerator.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/cql/generator/CreateIndexCqlGenerator.java @@ -43,8 +43,8 @@ public class CreateIndexCqlGenerator extends IndexNameCqlGenerator The subtype of the {@link IndexNameSpecification} - * * @author David Webb * @author Matthew T. Adams */ diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/KeyspaceOption.java b/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/KeyspaceOption.java index 011cf388d..bccc96e2c 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/KeyspaceOption.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/KeyspaceOption.java @@ -72,7 +72,6 @@ public enum KeyspaceOption implements Option { * Known Replication Strategy options. * * @author John McPeek - * */ public enum ReplicationStrategy { SIMPLE_STRATEGY("SimpleStrategy"), NETWORK_TOPOLOGY_STRATEGY("NetworkTopologyStrategy"); diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/KeyspaceSpecification.java b/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/KeyspaceSpecification.java index 79234dca9..eaef1ea6c 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/KeyspaceSpecification.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/KeyspaceSpecification.java @@ -23,5 +23,4 @@ package org.springframework.cassandra.core.keyspace; * @author Matthew T. Adams */ public class KeyspaceSpecification extends KeyspaceOptionsSpecification> implements - KeyspaceDescriptor { -} + KeyspaceDescriptor {} diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/TableOption.java b/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/TableOption.java index 74af2d3fe..c453cd985 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/TableOption.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/keyspace/TableOption.java @@ -20,9 +20,7 @@ import java.util.Map; /** * Enumeration that represents all known table options. If a table option is not listed here, but is supported by * Cassandra, use the method {@link CreateTableSpecification#with(String, Object, boolean, boolean)} to write the raw - * value. - * - * Implements {@link Option} via delegation, since {@link Enum}s can't extend anything. + * value. Implements {@link Option} via delegation, since {@link Enum}s can't extend anything. * * @author Matthew T. Adams * @see CompactionOption diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/util/CollectionUtils.java b/spring-cql/src/main/java/org/springframework/cassandra/core/util/CollectionUtils.java index ecb28a61b..ff9d4cf64 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/util/CollectionUtils.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/util/CollectionUtils.java @@ -39,4 +39,38 @@ public class CollectionUtils { return list; } + + public static List toList(Object thing) { + List list = new ArrayList(); + list.add(thing); + return list; + } + + public static List toList(Object thing1, Object thing2) { + List list = new ArrayList(); + list.add(thing1); + list.add(thing2); + return list; + } + + public static List toList(Object thing1, Object thing2, Object thing3) { + List list = new ArrayList(); + list.add(thing1); + list.add(thing2); + list.add(thing3); + return list; + } + + public static List toList(Object thing1, Object thing2, Object thing3, Object... rest) { + List list = new ArrayList(); + list.add(thing1); + list.add(thing2); + list.add(thing3); + if (rest != null) { + for (Object thing : rest) { + list.add(thing); + } + } + return list; + } } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractCqlTemplateIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractCqlTemplateIntegrationTest.java new file mode 100644 index 000000000..9618f00db --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/AbstractCqlTemplateIntegrationTest.java @@ -0,0 +1,20 @@ +package org.springframework.cassandra.test.integration; + +import org.springframework.cassandra.core.CqlOperations; +import org.springframework.cassandra.core.CqlTemplate; + +public class AbstractCqlTemplateIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest { + + protected CqlOperations t; + + { + t = new CqlTemplate(SESSION); + } + + public AbstractCqlTemplateIntegrationTest() {} + + public AbstractCqlTemplateIntegrationTest(String keyspace) { + super(keyspace); + } + +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/TestHostStateListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/TestHostStateListener.java index 8a43a9369..1085c9271 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/TestHostStateListener.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/TestHostStateListener.java @@ -23,7 +23,6 @@ import com.datastax.driver.core.Host.StateListener; /** * @author David Webb - * */ public class TestHostStateListener implements StateListener { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/TestLatencyTracker.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/TestLatencyTracker.java index 3d96d1d7e..6bce25fdd 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/TestLatencyTracker.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/TestLatencyTracker.java @@ -23,7 +23,6 @@ import com.datastax.driver.core.LatencyTracker; /** * @author David Webb - * */ public class TestLatencyTracker implements LatencyTracker { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest.java index 161504199..ad82dc446 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest.java @@ -27,7 +27,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.datastax.driver.core.Session; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "classpath:/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest-context.xml") +@ContextConfiguration( + locations = "classpath:/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest-context.xml") public class XmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest { public static final String KEYSPACE = "xmlconfigtest"; diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java index 2e54dbf6a..c9a86ac0e 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CqlTableSpecificationAssertions.java @@ -93,23 +93,23 @@ public class CqlTableSpecificationAssertions { switch (tableOption) { - case BLOOM_FILTER_FP_CHANCE: - case READ_REPAIR_CHANCE: - case DCLOCAL_READ_REPAIR_CHANCE: - assertEquals((Double) expected, (Double) actual, DELTA); - return; + case BLOOM_FILTER_FP_CHANCE: + case READ_REPAIR_CHANCE: + case DCLOCAL_READ_REPAIR_CHANCE: + assertEquals((Double) expected, (Double) actual, DELTA); + return; - case CACHING: - assertEquals(((String) expected).toUpperCase(), ((String) actual).toUpperCase()); - return; + case CACHING: + assertEquals(((String) expected).toUpperCase(), ((String) actual).toUpperCase()); + return; - case COMPACTION: - assertCompaction((Map) expected, (Map) actual); - return; + case COMPACTION: + assertCompaction((Map) expected, (Map) actual); + return; - case COMPRESSION: - assertCompression((Map) expected, (Map) actual); - return; + case COMPRESSION: + assertCompression((Map) expected, (Map) actual); + return; } log.info(actual.getClass().getName()); @@ -137,26 +137,26 @@ public class CqlTableSpecificationAssertions { @SuppressWarnings("unchecked") public static T getOptionFor(TableOption option, Class type, Options options) { switch (option) { - case BLOOM_FILTER_FP_CHANCE: - return (T) (Double) options.getBloomFilterFalsePositiveChance(); - case CACHING: - return (T) CqlStringUtils.singleQuote(options.getCaching()); - case COMMENT: - return (T) CqlStringUtils.singleQuote(options.getComment()); - case COMPACTION: - return (T) options.getCompaction(); - case COMPACT_STORAGE: - throw new Error(); // TODO: figure out - case COMPRESSION: - return (T) options.getCompression(); - case DCLOCAL_READ_REPAIR_CHANCE: - return (T) (Double) options.getLocalReadRepairChance(); - case GC_GRACE_SECONDS: - return (T) new Long(options.getGcGraceInSeconds()); - case READ_REPAIR_CHANCE: - return (T) (Double) options.getReadRepairChance(); - case REPLICATE_ON_WRITE: - return (T) (Boolean) options.getReplicateOnWrite(); + case BLOOM_FILTER_FP_CHANCE: + return (T) (Double) options.getBloomFilterFalsePositiveChance(); + case CACHING: + return (T) CqlStringUtils.singleQuote(options.getCaching()); + case COMMENT: + return (T) CqlStringUtils.singleQuote(options.getComment()); + case COMPACTION: + return (T) options.getCompaction(); + case COMPACT_STORAGE: + throw new Error(); // TODO: figure out + case COMPRESSION: + return (T) options.getCompression(); + case DCLOCAL_READ_REPAIR_CHANCE: + return (T) (Double) options.getLocalReadRepairChance(); + case GC_GRACE_SECONDS: + return (T) new Long(options.getGcGraceInSeconds()); + case READ_REPAIR_CHANCE: + return (T) (Double) options.getReadRepairChance(); + case REPLICATE_ON_WRITE: + return (T) (Boolean) options.getReplicateOnWrite(); } return null; } diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateIndexCqlGeneratorIntegrationTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateIndexCqlGeneratorIntegrationTests.java index bd26a00f8..dbbfc74ae 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateIndexCqlGeneratorIntegrationTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateIndexCqlGeneratorIntegrationTests.java @@ -36,7 +36,6 @@ public class CreateIndexCqlGeneratorIntegrationTests { * Integration test base class that knows how to do everything except instantiate the concrete unit test type T. * * @author Matthew T. Adams - * * @param The concrete unit test class to which this integration test corresponds. */ public static abstract class Base extends AbstractKeyspaceCreatingIntegrationTest { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java index e72854ea5..f225a8c4b 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/CreateTableCqlGeneratorIntegrationTests.java @@ -34,7 +34,6 @@ public class CreateTableCqlGeneratorIntegrationTests { * Integration test base class that knows how to do everything except instantiate the concrete unit test type T. * * @author Matthew T. Adams - * * @param The concrete unit test class to which this integration test corresponds. */ public static abstract class Base extends AbstractKeyspaceCreatingIntegrationTest { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/FunkyIdentifierIntegrationTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/FunkyIdentifierIntegrationTest.java index 645bdc507..e123a2ed4 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/FunkyIdentifierIntegrationTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/cql/generator/FunkyIdentifierIntegrationTest.java @@ -39,4 +39,4 @@ public class FunkyIdentifierIntegrationTest extends AbstractKeyspaceCreatingInte .partitionKeyColumn(name, DataType.text())).toCql()); } } -} \ No newline at end of file +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/Book.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/Book.java index af694034d..1a7d52f00 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/Book.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/Book.java @@ -19,7 +19,6 @@ package org.springframework.cassandra.test.integration.core.template; * Test POJO * * @author David Webb - * */ public class Book { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/BookListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/BookListener.java index 392e06933..bfc2ed141 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/BookListener.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/BookListener.java @@ -15,9 +15,8 @@ */ package org.springframework.cassandra.test.integration.core.template; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.cassandra.core.AsynchronousQueryListener; +import org.springframework.cassandra.test.unit.support.TestListener; import com.datastax.driver.core.ResultSetFuture; import com.datastax.driver.core.Row; @@ -26,18 +25,17 @@ import com.datastax.driver.core.Row; * Test Implementation of the {@link AsynchronousQueryListener} * * @author David Webb - * + * @author Matthew T. Adams */ -public class BookListener implements AsynchronousQueryListener { - - private static Logger log = LoggerFactory.getLogger(BookListener.class); +public class BookListener extends TestListener implements AsynchronousQueryListener { private Book book; private boolean done; @Override public void onQueryComplete(ResultSetFuture rsf) { - log.info("QueryCompleted"); + countDown(); + Row row; try { row = rsf.get().one(); @@ -51,8 +49,6 @@ public class BookListener implements AsynchronousQueryListener { book.setPages(row.getInt("pages")); done = true; - log.info("DONE"); - } /** diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/CQLOperationsTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/CQLOperationsTest.java index e40461721..188345b2a 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/CQLOperationsTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/CQLOperationsTest.java @@ -73,7 +73,6 @@ import static org.junit.Assert.assertTrue; * Unit Tests for CqlTemplate * * @author David Webb - * */ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { @@ -106,12 +105,8 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { @Before public void setupTemplate() { - log.info("Running setupTemplate()"); - if (cqlTemplate == null) { - log.info("null Template ... Initialzing DB test CQL"); - // CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet( // "cassandraOperationsTest-cql-dataload.cql", keyspace), CASSANDRA_CONFIG, CASSANDRA_HOST, // CASSANDRA_NATIVE_PORT); @@ -130,10 +125,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { * running. */ assertNotNull(ring); - - for (RingMember h : ring) { - log.info("ringTest Host -> " + h.address); - } } @Test @@ -424,7 +415,7 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { } @Test - public void queryAsynchronouslyWithListener() { + public void queryAsynchronouslyWithListener() throws InterruptedException { QueryOptions options = new QueryOptions(); options.setConsistencyLevel(ConsistencyLevel.ONE); @@ -433,25 +424,15 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { final String isbn = "999999999"; BookListener listener = new BookListener(); - cqlTemplate.queryAsynchronously("select * from book where isbn='" + isbn + "'", listener); - - // TODO Use better multi threading devices here. - while (!listener.isDone()) { - try { - Thread.sleep(100); - } catch (InterruptedException muted) { - } - } + listener.await(); Book book2 = getBook(isbn); - assertBook(listener.getBook(), book2); - } @Test - public void queryAsynchronouslyWithListenerAndExecutor() { + public void queryAsynchronouslyWithListenerAndExecutor() throws InterruptedException { QueryOptions options = new QueryOptions(); options.setConsistencyLevel(ConsistencyLevel.ONE); @@ -468,23 +449,14 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { command.run(); } }); - - // TODO Use better multi threading devices here. - while (!listener.isDone()) { - try { - Thread.sleep(100); - } catch (InterruptedException muted) { - } - } + listener.await(); Book book2 = getBook(isbn); - assertBook(listener.getBook(), book2); - } @Test - public void queryAsynchronouslyWithListenerAndExecutorAndOptions() { + public void queryAsynchronouslyWithListenerAndExecutorAndOptions() throws InterruptedException { QueryOptions options = new QueryOptions(); options.setConsistencyLevel(ConsistencyLevel.ONE); @@ -501,19 +473,10 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { command.run(); } }); - - // TODO Use better multi threading devices here. - while (!listener.isDone()) { - try { - Thread.sleep(100); - } catch (InterruptedException muted) { - } - } + listener.await(); Book book2 = getBook(isbn); - assertBook(listener.getBook(), book2); - } @Test @@ -589,7 +552,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { } }); - log.debug("Size of Book List -> " + books.size()); assertEquals(books.size(), 3); assertBook(books.get(0), getBook(books.get(0).getIsbn())); assertBook(books.get(1), getBook(books.get(1).getIsbn())); @@ -617,7 +579,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { } }); - log.debug("Size of Book List -> " + books.size()); assertEquals(books.size(), 3); assertBook(books.get(0), getBook(books.get(0).getIsbn())); assertBook(books.get(1), getBook(books.get(1).getIsbn())); @@ -725,8 +686,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { Map rsMap = cqlTemplate.queryForMap("select * from book where isbn in ('" + ISBN_NINES + "')"); - log.debug(rsMap.toString()); - Book b1 = objectToBook(rsMap.get("isbn"), rsMap.get("title"), rsMap.get("author"), rsMap.get("pages")); Book b2 = getBook(ISBN_NINES); @@ -746,8 +705,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { Map rsMap = cqlTemplate.processMap(rs); - log.debug("Size of Book List -> " + rsMap.size()); - Book b1 = objectToBook(rsMap.get("isbn"), rsMap.get("title"), rsMap.get("author"), rsMap.get("pages")); Book b2 = getBook(ISBN_NINES); @@ -765,8 +722,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { List titles = cqlTemplate.queryForList("select title from book where isbn in ('1234','2345','3456')", String.class); - log.debug(titles.toString()); - assertNotNull(titles); assertEquals(titles.size(), 3); @@ -786,8 +741,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { List titles = cqlTemplate.processList(rs, String.class); - log.debug(titles.toString()); - assertNotNull(titles); assertEquals(titles.size(), 3); } @@ -801,8 +754,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { List> results = cqlTemplate .queryForListOfMap("select * from book where isbn in ('1234','2345','3456')"); - log.debug(results.toString()); - assertEquals(results.size(), 3); } @@ -821,8 +772,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { List> results = cqlTemplate.processListOfMap(rs); - log.debug(results.toString()); - assertEquals(results.size(), 3); } @@ -981,8 +930,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { } }); - log.debug("Size of all Books -> " + books.size()); - assertTrue(books.size() > 0); } @@ -1004,10 +951,7 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { @Override public void processRow(Row row) throws DriverException { - Book b = rowToBook(row); - - log.debug("Title -> " + b.getTitle()); - + rowToBook(row); } }); @@ -1034,8 +978,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { } }); - log.debug("Size of all Books -> " + books.size()); - assertTrue(books.size() > 0); } @@ -1073,8 +1015,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { Book b2 = getBook(isbn); - log.debug("Book list Size -> " + books.size()); - assertEquals(books.size(), 1); assertBook(books.get(0), b2); } @@ -1144,8 +1084,6 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest { @Test public void insertAndTruncateQueryObjectTest() { - log.info("Starting Insert and Truncate Query Object Test"); - String tableName = "truncate_test"; CreateTableSpecification createTableSpec = new CreateTableSpecification(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AbstractAsynchronousTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AbstractAsynchronousTest.java new file mode 100644 index 000000000..703f21c86 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AbstractAsynchronousTest.java @@ -0,0 +1,5 @@ +package org.springframework.cassandra.test.integration.core.template.async; + +import org.springframework.cassandra.test.integration.AbstractCqlTemplateIntegrationTest; + +public abstract class AbstractAsynchronousTest extends AbstractCqlTemplateIntegrationTest {} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AsynchronousTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AsynchronousTest.java new file mode 100644 index 000000000..b4bb403cf --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/AsynchronousTest.java @@ -0,0 +1,388 @@ +package org.springframework.cassandra.test.integration.core.template.async; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.springframework.cassandra.core.keyspace.CreateTableSpecification.createTable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CancellationException; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.cassandra.core.AsynchronousQueryListener; +import org.springframework.cassandra.core.ConsistencyLevel; +import org.springframework.cassandra.core.Cancellable; +import org.springframework.cassandra.core.QueryForListOfMapListener; +import org.springframework.cassandra.core.QueryForMapListener; +import org.springframework.cassandra.core.QueryForObjectListener; +import org.springframework.cassandra.core.QueryOptions; +import org.springframework.cassandra.core.RetryPolicy; +import org.springframework.cassandra.support.exception.CassandraInsufficientReplicasAvailableException; +import org.springframework.util.StringUtils; + +import com.datastax.driver.core.DataType; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.querybuilder.QueryBuilder; +import com.datastax.driver.core.querybuilder.Select; + +public class AsynchronousTest extends AbstractAsynchronousTest { + + public static final String TABLE = "book"; + + public static String cql(Book book, String... columns) { + if (columns == null || columns.length == 0) { + columns = new String[] { "title", "isbn" }; + } + return String.format("select %s from %s where title = '%s' and isbn = '%s'", + StringUtils.arrayToCommaDelimitedString(columns), TABLE, book.title, book.isbn); + } + + public static String cql(String[] titles) { + String[] quoted = new String[titles.length]; + System.arraycopy(titles, 0, quoted, 0, titles.length); + for (int i = 0; i < quoted.length; i++) { + quoted[i] = "'" + quoted[i] + "'"; + } + + return String + .format("select * from %s where title in (%s)", TABLE, StringUtils.arrayToCommaDelimitedString(quoted)); + } + + public static Select select(String isbn) { + Select select = QueryBuilder.select("isbn", "title").from(TABLE); + select.where(QueryBuilder.eq("isbn", isbn)); + return select; + } + + public static final Comparator BOOK_COMPARATOR = new Comparator() { + @Override + public int compare(Book l, Book r) { + return l.isbn.compareTo(r.isbn); + } + }; + + public static void assertMapEquals(Map expected, Map actual) { + for (Object key : expected.keySet()) { + assertTrue(actual.containsKey(key)); + assertEquals(expected.get(key), actual.get(key)); + } + } + + void ensureTableExists() { + t.execute(createTable(TABLE).ifNotExists().partitionKeyColumn("title", DataType.ascii()) + .clusteredKeyColumn("isbn", DataType.ascii())); + } + + Book[] insert(int n) { + Book[] books = new Book[n]; + for (int i = 0; i < n; i++) { + Book b = books[i] = Book.random(); + t.execute(String.format("insert into %s (isbn, title) values ('%s', '%s')", TABLE, b.isbn, b.title)); + } + return books; + } + + @Before + public void beforeEach() { + ensureTableExists(); + t.truncate(TABLE); + } + + void assertBook(Book expected, Book actual) { + assertEquals(expected.isbn, actual.isbn); + assertEquals(expected.title, actual.title); + } + + /** + * Tests that test {@link AsynchronousQueryListener} should create an anonymous subclass of this class then call + * either {@link #test()} or {@link #test(int)} + */ + abstract class AsynchronousQueryListenerTestTemplate { + + /** + * Subclass must perform the asynchronous query using the given data and listener and set this.expected + * to the appropriate value before returning. + */ + abstract void doAsyncQuery(Book b, BasicListener listener); + + void test() throws InterruptedException { + Book expected = insert(1)[0]; + BasicListener listener = new BasicListener(); + doAsyncQuery(expected, listener); + listener.await(); + Row r = t.getResultSetUninterruptibly(listener.rsf).one(); + Book actual = new Book(r.getString(0), r.getString(1)); + assertBook(expected, actual); + } + } + + /** + * Tests that test {@link QueryForObjectListener} should create an anonymous subclass of this class then call either + * {@link #test()} or {@link #test(int)} + */ + abstract class QueryForObjectListenerTestTemplate { + + /** + * Subclass must perform the asynchronous query using the given data and listener and set this.expected + * to the appropriate value before returning. + */ + abstract void doAsyncQuery(Book b, QueryForObjectListener listener); + + T expected; // subclass should set this value in doAsyncQuery + + void test() throws Exception { + Book book = insert(1)[0]; + ObjectListener listener = new ObjectListener(); + doAsyncQuery(book, listener); + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + assertEquals(expected, listener.result); + } + } + + /** + * Tests that test {@link QueryForMapListener} should create an anonymous subclass of this class then call either + * {@link #test()} or {@link #test(int)} + */ + abstract class QueryForMapListenerTestTemplate { + + /** + * Subclass must perform the asynchronous query using the given data and listener and set this.expected + * to the appropriate value before returning. + */ + abstract void doAsyncQuery(Book b, QueryForMapListener listener); + + Map expected; // subclass should set this value in doAsyncQuery + + void test() throws Exception { + Book book = insert(1)[0]; + MapListener listener = new MapListener(); + doAsyncQuery(book, listener); + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + assertMapEquals(expected, listener.result); + } + } + + /** + * Tests that test {@link QueryForMapListener} should create an anonymous subclass of this class then call either + * {@link #test()} or {@link #test(int)} + */ + abstract class QueryForListListenerTestTemplate { + + /** + * Subclass must perform the asynchronous query using the given data and listener and set this.expected + * to the appropriate value before returning. + */ + abstract void doAsyncQuery(Book[] books, QueryForListOfMapListener listener); + + List> expected; // subclass should set this value in doAsyncQuery + + void test(int n) throws Exception { + Book[] books = insert(n); + ListOfMapListener listener = new ListOfMapListener(); + Arrays.sort(books, BOOK_COMPARATOR); + doAsyncQuery(books, listener); + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + + for (int i = 0; i < expected.size(); i++) { + assertMapEquals(expected.get(i), listener.result.get(i)); + } + } + } + + @Test(expected = CancellationException.class) + public void testString_AsynchronousQueryListener_Cancelled() throws InterruptedException { + new AsynchronousQueryListenerTestTemplate() { + @Override + void doAsyncQuery(Book b, BasicListener listener) { + Cancellable qc = t.queryAsynchronously(cql(b), listener); + qc.cancel(); + } + }.test(); + } + + @Test + public void testString_AsynchronousQueryListener() throws InterruptedException { + new AsynchronousQueryListenerTestTemplate() { + @Override + void doAsyncQuery(Book b, BasicListener listener) { + t.queryAsynchronously(cql(b), listener); + } + }.test(); + } + + public void testString_AsynchronousQueryListener_QueryOptions(final ConsistencyLevel cl) throws InterruptedException { + new AsynchronousQueryListenerTestTemplate() { + @Override + void doAsyncQuery(Book b, BasicListener listener) { + t.queryAsynchronously(cql(b), listener, new QueryOptions(cl, RetryPolicy.LOGGING)); + } + }.test(); + } + + @Test + public void testString_AsynchronousQueryListener_QueryOptionsWithConsistencyLevel1() throws InterruptedException { + testString_AsynchronousQueryListener_QueryOptions(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraInsufficientReplicasAvailableException.class) + public void testString_AsynchronousQueryListener_QueryOptionsWithConsistencyLevel2() throws InterruptedException { + testString_AsynchronousQueryListener_QueryOptions(ConsistencyLevel.TWO); + } + + @Test + public void testSelect_AsynchronousQueryListener() throws InterruptedException { + new AsynchronousQueryListenerTestTemplate() { + @Override + void doAsyncQuery(Book b, BasicListener listener) { + t.queryAsynchronously(cql(b), listener); + } + }.test(); + } + + @Test + public void testString_QueryForObjectListener() throws Exception { + new QueryForObjectListenerTestTemplate() { + + @Override + void doAsyncQuery(Book b, QueryForObjectListener listener) { + t.queryForObjectAsynchronously(cql(b, "title"), String.class, listener); + expected = b.title; + } + + }.test(); + } + + public void testString_QueryForObjectListener_QueryOptions(final ConsistencyLevel cl) throws Exception { + new QueryForObjectListenerTestTemplate() { + + @Override + void doAsyncQuery(Book b, QueryForObjectListener listener) { + QueryOptions opts = new QueryOptions(cl, RetryPolicy.LOGGING); + t.queryForObjectAsynchronously(cql(b, "title"), String.class, listener, opts); + expected = b.title; + } + + }.test(); + } + + @Test + public void testString_QueryForObjectListener_QueryOptionsWithConsistencyLevel() throws Exception { + testString_QueryForObjectListener_QueryOptions(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraInsufficientReplicasAvailableException.class) + public void testString_QueryForObjectListener_QueryOptionsWithConsistencyLevel2() throws Exception { + testString_QueryForObjectListener_QueryOptions(ConsistencyLevel.TWO); + } + + @Test + public void testString_QueryForMapListener() throws Exception { + new QueryForMapListenerTestTemplate() { + + @Override + void doAsyncQuery(Book b, QueryForMapListener listener) { + t.queryForMapAsynchronously(cql(b), listener); + expected = new HashMap(); + expected.put("isbn", b.isbn); + expected.put("title", b.title); + } + + }.test(); + } + + public void testString_QueryForMapListener_QueryOptions(final ConsistencyLevel cl) throws Exception { + new QueryForMapListenerTestTemplate() { + + @Override + void doAsyncQuery(Book b, QueryForMapListener listener) { + QueryOptions opts = new QueryOptions(cl, RetryPolicy.LOGGING); + t.queryForMapAsynchronously(cql(b), listener, opts); + expected = new HashMap(); + expected.put("isbn", b.isbn); + expected.put("title", b.title); + } + + }.test(); + } + + @Test + public void testString_QueryForMapListener_QueryOptionsWithConsistencyLevel1() throws Exception { + testString_QueryForMapListener_QueryOptions(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraInsufficientReplicasAvailableException.class) + public void testString_QueryForMapListener_QueryOptionsWithConsistencyLevel2() throws Exception { + testString_QueryForMapListener_QueryOptions(ConsistencyLevel.TWO); + } + + @Test + public void testString_QueryForListListener() throws Exception { + new QueryForListListenerTestTemplate() { + + @Override + void doAsyncQuery(Book[] books, QueryForListOfMapListener listener) { + + String[] titles = new String[books.length]; + expected = new ArrayList>(books.length); + for (int i = 0; i < books.length; i++) { + Book b = books[i]; + titles[i] = b.title; + HashMap row = new HashMap(2); + row.put("title", b.title); + row.put("isbn", b.isbn); + expected.add(row); + } + + t.queryForListOfMapAsynchronously(cql(titles), listener); + } + + }.test(2); + } + + public void testString_QueryForListListener_QueryOptions(final ConsistencyLevel cl) throws Exception { + new QueryForListListenerTestTemplate() { + + @Override + void doAsyncQuery(Book[] books, QueryForListOfMapListener listener) { + + String[] titles = new String[books.length]; + expected = new ArrayList>(books.length); + for (int i = 0; i < books.length; i++) { + Book b = books[i]; + titles[i] = b.title; + HashMap row = new HashMap(2); + row.put("title", b.title); + row.put("isbn", b.isbn); + expected.add(row); + } + + t.queryForListOfMapAsynchronously(cql(titles), listener, new QueryOptions(cl, RetryPolicy.LOGGING)); + } + + }.test(2); + } + + @Test + public void testString_QueryForListListener_QueryOptionsWithConsistencyLevel1() throws Exception { + testString_QueryForListListener_QueryOptions(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraInsufficientReplicasAvailableException.class) + public void testString_QueryForListListener_QueryOptionsWithConsistencyLevel2() throws Exception { + testString_QueryForListListener_QueryOptions(ConsistencyLevel.TWO); + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/BasicListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/BasicListener.java new file mode 100644 index 000000000..c2c403438 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/BasicListener.java @@ -0,0 +1,17 @@ +package org.springframework.cassandra.test.integration.core.template.async; + +import org.springframework.cassandra.core.AsynchronousQueryListener; +import org.springframework.cassandra.test.unit.support.TestListener; + +import com.datastax.driver.core.ResultSetFuture; + +class BasicListener extends TestListener implements AsynchronousQueryListener { + + ResultSetFuture rsf; + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + countDown(); + this.rsf = rsf; + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/Book.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/Book.java new file mode 100644 index 000000000..afab94959 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/Book.java @@ -0,0 +1,24 @@ +package org.springframework.cassandra.test.integration.core.template.async; + +import java.util.UUID; + +public class Book { + + public static final String uuid() { + return UUID.randomUUID().toString(); + } + + public static Book random() { + return new Book(uuid(), uuid()); + } + + public Book() {} + + public Book(String title, String isbn) { + this.isbn = isbn; + this.title = title; + } + + public String isbn; + public String title; +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListListener.java new file mode 100644 index 000000000..074036bb2 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListListener.java @@ -0,0 +1,24 @@ +package org.springframework.cassandra.test.integration.core.template.async; + +import java.util.List; + +import org.springframework.cassandra.core.QueryForListListener; +import org.springframework.cassandra.test.unit.support.TestListener; + +public class ListListener extends TestListener implements QueryForListListener { + + Exception exception; + List result; + + @Override + public void onQueryComplete(List results) { + countDown(); + this.result = results; + } + + @Override + public void onException(Exception x) { + countDown(); + this.exception = x; + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListOfMapListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListOfMapListener.java new file mode 100644 index 000000000..6bd66a564 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ListOfMapListener.java @@ -0,0 +1,7 @@ +package org.springframework.cassandra.test.integration.core.template.async; + +import java.util.Map; + +import org.springframework.cassandra.core.QueryForListOfMapListener; + +public class ListOfMapListener extends ListListener> implements QueryForListOfMapListener {} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/MapListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/MapListener.java new file mode 100644 index 000000000..c165d56f7 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/MapListener.java @@ -0,0 +1,24 @@ +package org.springframework.cassandra.test.integration.core.template.async; + +import java.util.Map; + +import org.springframework.cassandra.core.QueryForMapListener; +import org.springframework.cassandra.test.unit.support.TestListener; + +public class MapListener extends TestListener implements QueryForMapListener { + + Map result; + Exception exception; + + @Override + public void onQueryComplete(Map results) { + countDown(); + this.result = results; + } + + @Override + public void onException(Exception x) { + countDown(); + this.exception = x; + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ObjectListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ObjectListener.java new file mode 100644 index 000000000..303c85fa1 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/core/template/async/ObjectListener.java @@ -0,0 +1,22 @@ +package org.springframework.cassandra.test.integration.core.template.async; + +import org.springframework.cassandra.core.QueryForObjectListener; +import org.springframework.cassandra.test.unit.support.TestListener; + +class ObjectListener extends TestListener implements QueryForObjectListener { + + T result; + Exception exception; + + @Override + public void onQueryComplete(T result) { + countDown(); + this.result = result; + } + + @Override + public void onException(Exception x) { + countDown(); + this.exception = x; + } +} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlStringUtilsTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlStringUtilsTest.java index da4fc413d..9b72fe303 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlStringUtilsTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/CqlStringUtilsTest.java @@ -15,6 +15,4 @@ */ package org.springframework.cassandra.test.unit.core.cql; - -public class CqlStringUtilsTest { -} +public class CqlStringUtilsTest {} diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterKeyspaceCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterKeyspaceCqlGeneratorTests.java index 36f7ac2fe..b40aa1d60 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterKeyspaceCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterKeyspaceCqlGeneratorTests.java @@ -54,8 +54,7 @@ public class AlterKeyspaceCqlGeneratorTests { * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ public static abstract class AlterKeyspaceTest extends - KeyspaceOperationCqlGeneratorTest { - } + KeyspaceOperationCqlGeneratorTest {} public static class CompleteTest extends AlterKeyspaceTest { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java index 50edc309f..907e19cfb 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/AlterTableCqlGeneratorTests.java @@ -57,8 +57,7 @@ public class AlterTableCqlGeneratorTests { * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ public static abstract class AlterTableTest extends - TableOperationCqlGeneratorTest { - } + TableOperationCqlGeneratorTest {} public static class BasicTest extends AlterTableTest { @@ -95,7 +94,6 @@ public class AlterTableCqlGeneratorTests { * Fully test all available create table options * * @author David Webb - * */ public static class MultipleOptionsTest extends AlterTableTest { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java index abcd30d95..fa6d76b0d 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/CreateTableCqlGeneratorTests.java @@ -167,7 +167,6 @@ public class CreateTableCqlGeneratorTests { * Test just the Read Repair Chance * * @author David Webb - * */ public static class ReadRepairChanceTest extends CreateTableTest { @@ -203,7 +202,6 @@ public class CreateTableCqlGeneratorTests { * Fully test all available create table options * * @author David Webb - * */ public static class MultipleOptionsTest extends CreateTableTest { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropIndexCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropIndexCqlGeneratorTests.java index 877df12fd..363ee4eef 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropIndexCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropIndexCqlGeneratorTests.java @@ -34,8 +34,7 @@ public class DropIndexCqlGeneratorTests { * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ public static abstract class DropIndexTest extends - IndexOperationCqlGeneratorTest { - } + IndexOperationCqlGeneratorTest {} public static class BasicTest extends DropIndexTest { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropKeyspaceCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropKeyspaceCqlGeneratorTests.java index 3875ccb22..a6adf4066 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropKeyspaceCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropKeyspaceCqlGeneratorTests.java @@ -35,8 +35,7 @@ public class DropKeyspaceCqlGeneratorTests { * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ public static abstract class DropTableTest extends - KeyspaceOperationCqlGeneratorTest { - } + KeyspaceOperationCqlGeneratorTest {} public static class BasicTest extends DropTableTest { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropTableCqlGeneratorTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropTableCqlGeneratorTests.java index 3095247a1..cb4098954 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropTableCqlGeneratorTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/DropTableCqlGeneratorTests.java @@ -43,8 +43,7 @@ public class DropTableCqlGeneratorTests { * Convenient base class that other test classes can use so as not to repeat the generics declarations. */ public static abstract class DropTableTest extends - TableOperationCqlGeneratorTest { - } + TableOperationCqlGeneratorTest {} public static class BasicTest extends DropTableTest { diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/IndexOperationCqlGeneratorTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/IndexOperationCqlGeneratorTest.java index e79696b2f..0eb3692c5 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/IndexOperationCqlGeneratorTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/IndexOperationCqlGeneratorTest.java @@ -26,7 +26,6 @@ import org.springframework.cassandra.core.keyspace.IndexNameSpecification; * * @author Matthew T. Adams * @author David Webb - * * @param The type of the {@link IndexNameSpecification} * @param The type of the {@link IndexNameCqlGenerator} */ diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/KeyspaceOperationCqlGeneratorTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/KeyspaceOperationCqlGeneratorTest.java index 712c7799b..633071050 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/KeyspaceOperationCqlGeneratorTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/KeyspaceOperationCqlGeneratorTest.java @@ -30,7 +30,6 @@ import org.springframework.cassandra.core.keyspace.TableNameSpecification; * need for encapsulation, and it makes for easier reuse in other tests like integration tests (hint hint). * * @author Matthew T. Adams - * * @param The type of the {@link TableNameSpecification} * @param The type of the {@link TableNameCqlGenerator} */ diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/TableOperationCqlGeneratorTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/TableOperationCqlGeneratorTest.java index 072375ce1..bbba8e433 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/TableOperationCqlGeneratorTest.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/core/cql/generator/TableOperationCqlGeneratorTest.java @@ -24,7 +24,6 @@ import org.springframework.cassandra.core.keyspace.TableNameSpecification; * need for encapsulation, and it makes for easier reuse in other tests like integration tests (hint hint). * * @author Matthew T. Adams - * * @param The type of the {@link TableNameSpecification} * @param The type of the {@link TableNameCqlGenerator} */ diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/TestListener.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/TestListener.java new file mode 100644 index 000000000..2afd35d9f --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/support/TestListener.java @@ -0,0 +1,34 @@ +package org.springframework.cassandra.test.unit.support; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * Convenient listener base class that includes a {@link CountDownLatch} in order to test asynchronous behavior. + * + * @author Matthew T. Adams + */ +public class TestListener { + + protected CountDownLatch latch; + + public TestListener() { + this(1); + } + + public TestListener(int latchCount) { + latch = new CountDownLatch(latchCount); + } + + public void await() throws InterruptedException { + latch.await(); + } + + public void await(long ms) throws InterruptedException { + latch.await(ms, TimeUnit.MILLISECONDS); + } + + public void countDown() { + latch.countDown(); + } +} diff --git a/spring-data-cassandra/.java-version b/spring-data-cassandra/.java-version new file mode 100644 index 000000000..4c8b1edb0 --- /dev/null +++ b/spring-data-cassandra/.java-version @@ -0,0 +1 @@ +oracle64-1.8.0.11 diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/Constants.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/Constants.java index f6fe45588..963c16de3 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/Constants.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/Constants.java @@ -17,7 +17,6 @@ package org.springframework.data.cassandra; /** * @author David Webb - * */ public interface Constants { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraClusterFactoryBean.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraClusterFactoryBean.java index 4766e6513..ef9b8f09b 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraClusterFactoryBean.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraClusterFactoryBean.java @@ -18,10 +18,9 @@ package org.springframework.data.cassandra.config; import org.springframework.cassandra.config.CassandraCqlClusterFactoryBean; /** - * Spring Data Cassandra extension of CassandraCqlClusterFactoryBean. This class exists only in the name of symmetry, based - * on the other CassandraData*FactoryBean classes. + * Spring Data Cassandra extension of CassandraCqlClusterFactoryBean. This class exists only in the name of symmetry, + * based on the other CassandraData*FactoryBean classes. * * @author Matthew T. Adams */ -public class CassandraClusterFactoryBean extends CassandraCqlClusterFactoryBean { -} +public class CassandraClusterFactoryBean extends CassandraCqlClusterFactoryBean {} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraEntityClassScanner.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraEntityClassScanner.java index e751a841a..591952377 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraEntityClassScanner.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraEntityClassScanner.java @@ -59,8 +59,7 @@ public class CassandraEntityClassScanner { protected Set> entityBasePackageClasses = new HashSet>(); protected ClassLoader beanClassLoader; - public CassandraEntityClassScanner() { - } + public CassandraEntityClassScanner() {} public CassandraEntityClassScanner(Class... entityBasePackageClasses) { this(null, Arrays.asList(entityBasePackageClasses)); diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraMappingBeanFactoryPostProcessor.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraMappingBeanFactoryPostProcessor.java index 656402f70..b45895035 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraMappingBeanFactoryPostProcessor.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraMappingBeanFactoryPostProcessor.java @@ -51,13 +51,12 @@ import com.datastax.driver.core.Session; * when creating a default definition for the {@link CassandraConverter}. *

* If a single definition of a required type is present, then it is used. For example, if there is already a - * {@link CassandraMappingContext} definition present, then it will be used in the - * {@link BasicCassandraMappingContext} bean definition. + * {@link CassandraMappingContext} definition present, then it will be used in the {@link BasicCassandraMappingContext} + * bean definition. *

- * It requires that a single {@link Session} or {@link CassandraSessionFactoryBean} definition be present. As - * described above, multiple {@link Session} definitions, multiple {@link CassandraSessionFactoryBean} definitions, - * or both a {@link Session} and {@link CassandraSessionFactoryBean} will cause an {@link IllegalStateException} to - * be thrown. + * It requires that a single {@link Session} or {@link CassandraSessionFactoryBean} definition be present. As described + * above, multiple {@link Session} definitions, multiple {@link CassandraSessionFactoryBean} definitions, or both a + * {@link Session} and {@link CassandraSessionFactoryBean} will cause an {@link IllegalStateException} to be thrown. * * @author Matthew T. Adams */ @@ -67,8 +66,7 @@ public class CassandraMappingBeanFactoryPostProcessor implements BeanDefinitionR * Does nothing. */ @Override - public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { - } + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {} /** * Ensures that {@link BeanDefinition}s for a {@link CassandraMappingContext} and a {@link CassandraConverter} exist. diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraSessionFactoryBean.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraSessionFactoryBean.java index 93e5802ca..2957ca25a 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraSessionFactoryBean.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/CassandraSessionFactoryBean.java @@ -56,17 +56,17 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean switch (schemaAction) { - case NONE: - return; + case NONE: + return; - case RECREATE_DROP_UNUSED: - dropUnused = true; - // don't break! - case RECREATE: - dropTables = true; - // don't break! - case CREATE: - createTables(dropTables, dropUnused); + case RECREATE_DROP_UNUSED: + dropUnused = true; + // don't break! + case RECREATE: + dropTables = true; + // don't break! + case CREATE: + createTables(dropTables, dropUnused); } } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/convert/AbstractCassandraConverter.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/convert/AbstractCassandraConverter.java index 6b6887a99..bbc9402d9 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/convert/AbstractCassandraConverter.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/convert/AbstractCassandraConverter.java @@ -54,6 +54,5 @@ public abstract class AbstractCassandraConverter implements CassandraConverter, } @Override - public void afterPropertiesSet() { - } + public void afterPropertiesSet() {} } 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 a7283deb9..4fd03b125 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 @@ -18,6 +18,8 @@ package org.springframework.data.cassandra.core; import java.util.List; import org.springframework.cassandra.core.CqlOperations; +import org.springframework.cassandra.core.Cancellable; +import org.springframework.cassandra.core.QueryForObjectListener; import org.springframework.cassandra.core.QueryOptions; import org.springframework.cassandra.core.WriteOptions; import org.springframework.cassandra.core.cql.CqlIdentifier; @@ -72,6 +74,46 @@ public interface CassandraOperations extends CqlOperations { */ T selectOne(String cql, Class type); + /** + * 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. + */ + Cancellable selectOneAsynchronously(Select select, Class type, QueryForObjectListener listener); + + /** + * 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. + */ + Cancellable selectOneAsynchronously(String cql, Class type, QueryForObjectListener listener); + + /** + * 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. + * @return A {@link Cancellable} that can be used to cancel the query. + */ + Cancellable selectOneAsynchronously(Select select, Class type, QueryForObjectListener listener, + QueryOptions options); + + /** + * 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. + * @return A {@link Cancellable} that can be used to cancel the query. + */ + Cancellable selectOneAsynchronously(String cql, Class type, QueryForObjectListener listener, + QueryOptions options); + /** * Execute Select query and convert ResultSet to the entity * @@ -86,126 +128,245 @@ public interface CassandraOperations extends CqlOperations { long count(Class type); /** - * Insert the given object to the table by id. + * Insert the given entity. * - * @param entity + * @param entity The entity to insert + * @return The entity given */ T insert(T entity); /** - * @param entity - * @param tableName - * @param options - * @return + * Insert the given entity. + * + * @param entity The entity to insert + * @param options The {@link WriteOptions} to use. + * @return The entity given */ T insert(T entity, WriteOptions options); /** - * Insert the given list of objects to the table by annotation table name. + * Insert the given list of entities. * - * @param entities - * @return + * @param entities The entities to insert. + * @return The entities given. */ List insert(List entities); /** - * @param entities - * @param tableName - * @param options - * @return + * Insert the given list of entities. + * + * @param entities The entities to insert. + * @param options The {@link WriteOptions} to use. + * @return The entities given. */ List insert(List entities, WriteOptions options); /** - * Insert the given object to the table by id. + * Inserts the given entity asynchronously. * - * @param object + * @param entity The entity to insert + * @return The entity given + * @see #insertAsynchronously(Object, WriteListener) + * @deprecated This method does not allow for query cancellation or notification of completion. Favor + * {@link #insertAsynchronously(Object, WriteListener)}. */ + @Deprecated T insertAsynchronously(T entity); /** - * @param entity - * @param tableName - * @param options - * @return + * Inserts the given entity asynchronously. + * + * @param entity The entity to insert + * @return The entity given + * @see #insertAsynchronously(Object, WriteOptions) + * @deprecated This method does not allow for query cancellation or notification of completion. Favor + * {@link #insertAsynchronously(Object, WriteListener, WriteOptions)}. */ + @Deprecated T insertAsynchronously(T entity, WriteOptions options); /** - * Insert the given object to the table by id. + * Inserts the given entity asynchronously. * - * @param object + * @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 */ + Cancellable insertAsynchronously(T entity, WriteListener listener); + + /** + * 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 + * @return A {@link Cancellable} enabling the cancellation of the operation + */ + Cancellable insertAsynchronously(T entity, WriteListener listener, WriteOptions options); + + /** + * Inserts the given entities asynchronously in a batch. + * + * @param entity The entities to insert + * @return The entities given + * @see #insertAsynchronously(List, WriteListener) + * @deprecated This method does not allow for query cancellation or notification of completion. Favor + * {@link #insertAsynchronously(List, WriteListener)}. + */ + @Deprecated List insertAsynchronously(List entities); /** - * @param entities - * @param tableName - * @param options - * @return + * Inserts the given entities asynchronously in a batch. + * + * @param entity The entities to insert + * @return The entities given + * @see #insertAsynchronously(List, WriteListener, WriteOptions) + * @deprecated This method does not allow for query cancellation or notification of completion. Favor + * {@link #insertAsynchronously(List, WriteListener, WriteOptions)}. */ + @Deprecated List insertAsynchronously(List entities, WriteOptions options); /** - * Insert the given object to the table by id. + * Inserts the given entities asynchronously in a batch. * - * @param object + * @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 + */ + Cancellable insertAsynchronously(List entities, WriteListener listener); + + /** + * 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 + * @return A {@link Cancellable} enabling the cancellation of the operation + */ + Cancellable insertAsynchronously(List entities, WriteListener listener, WriteOptions options); + + /** + * Update the given entity. + * + * @param entity The entity to update + * @return The entity given */ T update(T entity); /** - * @param entity - * @param tableName - * @param options - * @return + * Update the given entity. + * + * @param entity The entity to update + * @param options The {@link WriteOptions} to use. + * @return The entity given */ T update(T entity, WriteOptions options); /** - * Insert the given object to the table by id. + * Update the given list of entities. * - * @param object + * @param entities The entities to update. + * @return The entities given. */ List update(List entities); /** - * @param entities - * @param tableName - * @param options - * @return + * Update the given list of entities. + * + * @param entities The entities to update. + * @param options The {@link WriteOptions} to use. + * @return The entities given. */ List update(List entities, WriteOptions options); /** - * Insert the given object to the table by id. + * Updates the given entity asynchronously. * - * @param object + * @param entity The entity to update + * @return The entity given + * @see #updateAsynchronously(Object, WriteListener) + * @deprecated This method does not allow for query cancellation or notification of completion. Favor + * {@link #updateAsynchronously(Object, WriteListener)}. */ + @Deprecated T updateAsynchronously(T entity); /** - * @param entity - * @param tableName - * @param options - * @return + * Updates the given entity asynchronously. + * + * @param entity The entity to update + * @return The entity given + * @see #updateAsynchronously(Object, WriteOptions) + * @deprecated This method does not allow for query cancellation or notification of completion. Favor + * {@link #updateAsynchronously(Object, WriteListener, WriteOptions)}. */ + @Deprecated T updateAsynchronously(T entity, WriteOptions options); /** - * Insert the given object to the table by id. + * Updates the given entity asynchronously. * - * @param object + * @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 */ + Cancellable updateAsynchronously(T entity, WriteListener listener); + + /** + * 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 + * @return A {@link Cancellable} enabling the cancellation of the operation + */ + Cancellable updateAsynchronously(T entity, WriteListener listener, WriteOptions options); + + /** + * Updates the given entities asynchronously in a batch. + * + * @param entity The entities to update + * @return The entities given + * @see #updateAsynchronously(List, WriteListener) + * @deprecated This method does not allow for query cancellation or notification of completion. Favor + * {@link #updateAsynchronously(List, WriteListener)}. + */ + @Deprecated List updateAsynchronously(List entities); /** - * @param entities - * @param tableName - * @param options - * @return + * Updates the given entities asynchronously in a batch. + * + * @param entity The entities to update + * @return The entities given + * @see #updateAsynchronously(List, WriteListener, WriteOptions) + * @deprecated This method does not allow for query cancellation or notification of completion. Favor + * {@link #updateAsynchronously(List, WriteListener, WriteOptions)}. */ + @Deprecated List updateAsynchronously(List entities, WriteOptions options); + /** + * 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 + */ + Cancellable updateAsynchronously(List entities, WriteListener listener); + + /** + * 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 + * @return A {@link Cancellable} enabling the cancellation of the operation + */ + Cancellable updateAsynchronously(List entities, WriteListener listener, WriteOptions options); + /** * Remove the given object from the table by id. * @@ -227,11 +388,6 @@ public interface CassandraOperations extends CqlOperations { */ void delete(List entities); - /** - * @param entities - * @param tableName - * @param options - */ void delete(List entities, QueryOptions options); /** @@ -242,30 +398,66 @@ public interface CassandraOperations extends CqlOperations { /** * Remove the given object from the table by id. * - * @param object + * @param entity The object to delete */ - void deleteAsynchronously(T entity); - - /** - * @param entity - * @param tableName - * @param options - */ - void deleteAsynchronously(T entity, QueryOptions options); + Cancellable deleteAsynchronously(T entity); /** * Remove the given object from the table by id. * - * @param object + * @param entity The object to delete + * @param options The {@link QueryOptions} to use */ - void deleteAsynchronously(List entities); + Cancellable deleteAsynchronously(T entity, QueryOptions options); /** - * @param entities - * @param tableName - * @param options + * 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 */ - void deleteAsynchronously(List entities, QueryOptions options); + Cancellable deleteAsynchronously(T entity, DeletionListener listener); + + /** + * 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 + */ + Cancellable deleteAsynchronously(T entity, DeletionListener listener, QueryOptions options); + + /** + * 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 + */ + Cancellable deleteAsynchronously(List entities, DeletionListener listener); + + /** + * Remove the given objects from the table by id. + * + * @param entities The objects to delete + * @param options The {@link QueryOptions} to use + */ + Cancellable deleteAsynchronously(List entities, QueryOptions options); + + /** + * 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 + */ + Cancellable deleteAsynchronously(List entities, DeletionListener listener, QueryOptions options); /** * Returns the underlying {@link CassandraConverter}. @@ -278,5 +470,11 @@ public interface CassandraOperations extends CqlOperations { List selectBySimpleIds(Class type, Iterable ids); + /** + * @deprecated Calling this method could result in {@link OutOfMemoryError}, as this is a brute force selection. + * @param type The type of entity to select. + * @return A list of all entities of type T. + */ + @Deprecated List selectAll(Class type); } 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 363234c9a..c13d3a7f9 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 @@ -16,11 +16,16 @@ package org.springframework.data.cassandra.core; import java.util.ArrayList; +import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; +import org.springframework.cassandra.core.AsynchronousQueryListener; +import org.springframework.cassandra.core.CqlOperations; import org.springframework.cassandra.core.CqlTemplate; +import org.springframework.cassandra.core.Cancellable; +import org.springframework.cassandra.core.QueryForObjectListener; import org.springframework.cassandra.core.QueryOptions; import org.springframework.cassandra.core.SessionCallback; import org.springframework.cassandra.core.WriteOptions; @@ -39,8 +44,11 @@ import org.springframework.data.mapping.model.BeanWrapper; import org.springframework.util.Assert; import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.ResultSetFuture; import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; +import com.datastax.driver.core.SimpleStatement; +import com.datastax.driver.core.Statement; import com.datastax.driver.core.querybuilder.Batch; import com.datastax.driver.core.querybuilder.Clause; import com.datastax.driver.core.querybuilder.Delete; @@ -138,7 +146,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation @Override public void delete(List entities, QueryOptions options) { - batchDelete(entities, options, false); + doBatchDelete(entities, options); } @Override @@ -162,27 +170,47 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation @Override public void delete(T entity, QueryOptions options) { - delete(entity, options, false); + doDelete(entity, options); } @Override - public void deleteAsynchronously(List entities) { - deleteAsynchronously(entities, null); + public Cancellable deleteAsynchronously(List entities) { + return doBatchDeleteAsync(entities, null, null); } @Override - public void deleteAsynchronously(List entities, QueryOptions options) { - batchDelete(entities, options, true); + public Cancellable deleteAsynchronously(List entities, QueryOptions options) { + return doBatchDeleteAsync(entities, null, options); } @Override - public void deleteAsynchronously(T entity) { - deleteAsynchronously(entity, null); + public Cancellable deleteAsynchronously(List entities, DeletionListener listener) { + return doBatchDeleteAsync(entities, listener, null); } @Override - public void deleteAsynchronously(T entity, QueryOptions options) { - delete(entity, options, true); + public Cancellable deleteAsynchronously(List entities, DeletionListener listener, QueryOptions options) { + return doBatchDeleteAsync(entities, listener, options); + } + + @Override + public Cancellable deleteAsynchronously(T entity) { + return doDeleteAsync(entity, null, null); + } + + @Override + public Cancellable deleteAsynchronously(T entity, QueryOptions options) { + return doDeleteAsync(entity, null, options); + } + + @Override + public Cancellable deleteAsynchronously(T entity, DeletionListener listener) { + return doDeleteAsync(entity, listener, null); + } + + @Override + public Cancellable deleteAsynchronously(T entity, DeletionListener listener, QueryOptions options) { + return doDeleteAsync(entity, listener, options); } @Override @@ -197,7 +225,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation @Override public List insert(List entities, WriteOptions options) { - return batchInsert(entities, options, false); + return doBatchInsert(entities, options); } @Override @@ -207,27 +235,76 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation @Override public T insert(T entity, WriteOptions options) { - return insert(entity, options, false); + return doInsert(entity, options); } + /** + * @deprecated See {@link CassandraTemplate#insertAsynchronously(List)} + */ + @Deprecated @Override public List insertAsynchronously(List entities) { - return insertAsynchronously(entities, null); + insertAsynchronously(entities, (WriteOptions) null); + return entities; } + /** + * @deprecated See {@link CassandraTemplate#insertAsynchronously(List, WriteOptions)} + */ + @Deprecated @Override public List insertAsynchronously(List entities, WriteOptions options) { - return batchInsert(entities, options, true); + doInsertAsynchronously(entities, null, options); + return entities; } + @Override + public Cancellable insertAsynchronously(List entities, WriteListener listener) { + return doInsertAsynchronously(entities, listener, null); + } + + @Override + public Cancellable insertAsynchronously(List entities, WriteListener listener, WriteOptions options) { + return doInsertAsynchronously(entities, listener, options); + } + + /** + * This method resolves ambiguity the compiler sees as a result of type erasure between + * {@link #insertAsynchronously(Object, WriteListener, WriteOptions)} and {@link #insertAsynchronously(List, + * WriteListener, WriteOptions)}. + */ + protected Cancellable doInsertAsynchronously(List entities, WriteListener listener, WriteOptions options) { + return doBatchInsertAsync(entities, listener, options); + } + + /** + * @deprecated See {@link CqlOperations#insert(Object)} + */ + @Deprecated @Override public T insertAsynchronously(T entity) { - return insertAsynchronously(entity, null); + insertAsynchronously(entity, null, null); + return entity; + } + + /** + * @deprecated See {@link CqlOperations#insert(Object,WriteOptions)} + */ + @Deprecated + @Override + public T insertAsynchronously(T entity, WriteOptions options) { + insertAsynchronously(entity, null, options); + return entity; } @Override - public T insertAsynchronously(T entity, WriteOptions options) { - return insert(entity, options, true); + public Cancellable insertAsynchronously(T entity, WriteListener listener) { + return insertAsynchronously(entity, listener, null); + } + + @Override + public Cancellable insertAsynchronously(T entity, WriteListener listener, WriteOptions options) { + return doInsertAsync(entity, listener, options); } @Override @@ -372,7 +449,7 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation @Override public List update(List entities, WriteOptions options) { - return batchUpdate(entities, options, false); + return doBatchUpdate(entities, options); } @Override @@ -382,27 +459,60 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation @Override public T update(T entity, WriteOptions options) { - return update(entity, options, false); + return doUpdate(entity, options); } @Override public List updateAsynchronously(List entities) { - return updateAsynchronously(entities, null); + doUpdateAsynchronously(entities, null, null); + return entities; } @Override public List updateAsynchronously(List entities, WriteOptions options) { - return batchUpdate(entities, options, true); + doUpdateAsynchronously(entities, null, options); + return entities; + } + + @Override + public Cancellable updateAsynchronously(List entities, WriteListener listener) { + return doUpdateAsynchronously(entities, listener, null); + } + + @Override + public Cancellable updateAsynchronously(List entities, WriteListener listener, WriteOptions options) { + return doUpdateAsynchronously(entities, listener, options); + } + + /** + * This method resolves ambiguity the compiler sees as a result of type erasure between + * {@link #updateAsynchronously(Object, WriteListener, WriteOptions)} and {@link #updateAsynchronously(List, + * WriteListener, WriteOptions)}. + */ + protected Cancellable doUpdateAsynchronously(List entities, WriteListener listener, WriteOptions options) { + return doBatchUpdateAsync(entities, listener, options); } @Override public T updateAsynchronously(T entity) { - return updateAsynchronously(entity, null); + updateAsynchronously(entity, null, null); + return entity; } @Override public T updateAsynchronously(T entity, WriteOptions options) { - return update(entity, options, true); + updateAsynchronously(entity, null, options); + return entity; + } + + @Override + public Cancellable updateAsynchronously(T entity, WriteListener listener) { + return updateAsynchronously(entity, listener, null); + } + + @Override + public Cancellable updateAsynchronously(T entity, WriteListener listener, WriteOptions options) { + return doUpdateAsync(entity, listener, options); } protected CqlIdentifier determineTableName(T obj) { @@ -498,42 +608,72 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation return null; } - /** - * Perform the deletion on a list of objects - * - * @param tableName - * @param objectToRemove - */ - protected void batchDelete(List entities, QueryOptions options, boolean asynchronously) { - - Assert.notEmpty(entities); - - Batch b = createDeleteBatchQuery(getTableName(entities.get(0).getClass()).toCql(), entities, options, - cassandraConverter); - - if (asynchronously) { - executeAsynchronously(b); - } else { - execute(b); - } + protected void doBatchDelete(List entities, QueryOptions options) { + execute(createDeleteBatchQuery(getTableName(entities.get(0).getClass()).toCql(), entities, options, + cassandraConverter)); } - protected T insert(T entity, WriteOptions options, boolean asynchronously) { + protected Cancellable doBatchDeleteAsync(final List entities, final DeletionListener listener, + QueryOptions options) { + + AsynchronousQueryListener aql = listener == null ? null : new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + rsf.getUninterruptibly(); + listener.onDeletionComplete(entities); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }; + + return executeAsynchronously( + createDeleteBatchQuery(getTableName(entities.get(0).getClass()).toCql(), entities, options, cassandraConverter), + aql); + } + + protected T doInsert(T entity, WriteOptions options) { + + Assert.notNull(entity); + Insert insert = createInsertQuery(getTableName(entity.getClass()).toCql(), entity, options, cassandraConverter); + execute(insert); + return entity; + } + + protected Cancellable doInsertAsync(final T entity, final WriteListener listener, WriteOptions options) { Assert.notNull(entity); Insert insert = createInsertQuery(getTableName(entity.getClass()).toCql(), entity, options, cassandraConverter); - if (asynchronously) { - executeAsynchronously(insert); - } else { - execute(insert); - } + AsynchronousQueryListener aql = listener == null ? null : new AsynchronousQueryListener() { - return entity; + @SuppressWarnings("unchecked") + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + rsf.getUninterruptibly(); + listener.onWriteComplete((Collection) CollectionUtils.toList(entity)); + } catch (Exception x) { + listener.onException(translateExceptionIfPossible(x)); + } + } + }; + + return executeAsynchronously(insert, aql); } - protected List batchInsert(List entities, WriteOptions options, boolean asychronously) { + protected List doBatchInsert(List entities, WriteOptions options) { + return doBatchWrite(entities, options, true); + } + + protected List doBatchUpdate(List entities, WriteOptions options) { + return doBatchWrite(entities, options, false); + } + + protected List doBatchWrite(List entities, WriteOptions options, boolean insert) { if (entities == null || entities.size() == 0) { if (logger.isWarnEnabled()) { @@ -542,84 +682,147 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation return entities; } - Batch b = createInsertBatchQuery(getTableName(entities.get(0).getClass()).toCql(), entities, options, - cassandraConverter); - - if (asychronously) { - executeAsynchronously(b); - } else { - execute(b); - } + String tableName = getTableName(entities.get(0).getClass()).toCql(); + Batch b = insert ? createInsertBatchQuery(tableName, entities, options, cassandraConverter) + : createUpdateBatchQuery(tableName, entities, options, cassandraConverter); + execute(b); return entities; } /** - * Update a Batch of rows in a Cassandra CQL Table + * Asynchronously performs a batch insert or update. * - * @param tableName - * @param entities - * @param optionsByName - * @param updateAsychronously - * @return + * @param entities The entities to insert or update. + * @param listener The listener that will receive notification of the completion of the batch insert or update. May be + * null. + * @param options The {@link WriteOptions} to use. May be null. + * @return A {@link Cancellable} that can be used to cancel the query if necessary. */ - protected List batchUpdate(List entities, WriteOptions options, boolean asychronously) { - - Assert.notEmpty(entities); - - Batch b = toUpdateBatchQuery(getTableName(entities.get(0).getClass()).toCql(), entities, options, - cassandraConverter); - - if (asychronously) { - executeAsynchronously(b); - } else { - execute(b); - } - - return entities; + protected Cancellable doBatchInsertAsync(final List entities, final WriteListener listener, + WriteOptions options) { + return doBatchWriteAsync(entities, listener, options, true); } /** - * Perform the removal of a Row. + * Asynchronously performs a batch insert or update. * - * @param tableName - * @param entity + * @param entities The entities to insert or update. + * @param listener The listener that will receive notification of the completion of the batch insert or update. May be + * null. + * @param options The {@link WriteOptions} to use. May be null. + * @return A {@link Cancellable} that can be used to cancel the query if necessary. */ - protected void delete(T entity, QueryOptions options, boolean asynchronously) { + protected Cancellable doBatchUpdateAsync(final List entities, final WriteListener listener, + WriteOptions options) { + return doBatchWriteAsync(entities, listener, options, false); + } + + /** + * Asynchronously performs a batch insert or update. + * + * @param entities The entities to insert or update. + * @param listener The listener that will receive notification of the completion of the batch insert or update. May be + * null. + * @param options The {@link WriteOptions} to use. May be null. + * @param insert If true, then an insert is performed, else an update is performed. + * @return A {@link Cancellable} that can be used to cancel the query if necessary. + */ + protected Cancellable doBatchWriteAsync(final List entities, final WriteListener listener, + WriteOptions options, boolean insert) { + + if (entities == null || entities.size() == 0) { + if (logger.isWarnEnabled()) { + logger.warn("no-op due to given null or empty list"); + } + return new Cancellable() { + + @Override + public void cancel() { + if (logger.isWarnEnabled()) { + logger.warn("no-op query cancellation due to given null or empty list"); + } + } + }; + } + + String tableName = getTableName(entities.get(0).getClass()).toCql(); + Batch b = insert ? createInsertBatchQuery(tableName, entities, options, cassandraConverter) + : createUpdateBatchQuery(tableName, entities, options, cassandraConverter); + + AsynchronousQueryListener aql = listener == null ? null : new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + rsf.getUninterruptibly(); + listener.onWriteComplete(entities); + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }; + + return executeAsynchronously(b, aql); + } + + protected void doDelete(T entity, QueryOptions options) { + + Assert.notNull(entity); + Delete delete = createDeleteQuery(getTableName(entity.getClass()).toCql(), entity, options, cassandraConverter); + execute(delete); + } + + protected Cancellable doDeleteAsync(final T entity, final DeletionListener listener, QueryOptions options) { Assert.notNull(entity); Delete delete = createDeleteQuery(getTableName(entity.getClass()).toCql(), entity, options, cassandraConverter); - if (asynchronously) { - executeAsynchronously(delete); - } else { - execute(delete); - } + AsynchronousQueryListener aql = listener == null ? null : new AsynchronousQueryListener() { + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + rsf.getUninterruptibly(); + listener.onDeletionComplete(CollectionUtils.toList(entity)); + } catch (Exception x) { + listener.onException(translateExceptionIfPossible(x)); + } + } + }; + + return executeAsynchronously(delete, aql); } - /** - * Update a row into a Cassandra CQL Table - * - * @param tableName - * @param entity - * @param optionsByName - * @param updateAsychronously - * @return - */ - protected T update(T entity, WriteOptions options, boolean asychronously) { + protected T doUpdate(T entity, WriteOptions options) { + + Assert.notNull(entity); + Update update = createUpdateQuery(getTableName(entity.getClass()).toCql(), entity, options, cassandraConverter); + execute(update); + return entity; + } + + protected Cancellable doUpdateAsync(final T entity, final WriteListener listener, WriteOptions options) { Assert.notNull(entity); - Update update = toUpdateQuery(getTableName(entity.getClass()).toCql(), entity, options, cassandraConverter); + Update update = createUpdateQuery(getTableName(entity.getClass()).toCql(), entity, options, cassandraConverter); - if (asychronously) { - executeAsynchronously(update); - } else { - execute(update); - } + AsynchronousQueryListener aql = listener == null ? null : new AsynchronousQueryListener() { - return entity; + @SuppressWarnings("unchecked") + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + rsf.getUninterruptibly(); + listener.onWriteComplete((Collection) CollectionUtils.toList(entity)); + } catch (Exception x) { + listener.onException(translateExceptionIfPossible(x)); + } + } + }; + + return executeAsynchronously(update, aql); } /** @@ -635,20 +838,21 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation EntityWriter entityWriter) { Insert insert = QueryBuilder.insertInto(tableName); - - /* - * Write properties - */ entityWriter.write(objectToSave, insert); - - /* - * Add Query Options - */ CqlTemplate.addWriteOptions(insert, options); - return insert; } + /** + * @deprecated Method renamed. Use {@link #createUpdateQuery(String, Object, WriteOptions, EntityWriter)} + * @see #createUpdateQuery(String, Object, WriteOptions, EntityWriter) + */ + @Deprecated + public static Update toUpdateQueryX(String tableName, Object objectToSave, WriteOptions options, + EntityWriter entityWriter) { + return createUpdateQuery(tableName, objectToSave, options, entityWriter); + } + /** * Generates a Query Object for an Update * @@ -658,24 +862,25 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation * @param optionsByName * @return The Query object to run with session.execute(); */ - public static Update toUpdateQuery(String tableName, Object objectToSave, WriteOptions options, + public static Update createUpdateQuery(String tableName, Object objectToSave, WriteOptions options, EntityWriter entityWriter) { Update update = QueryBuilder.update(tableName); - - /* - * Write properties - */ entityWriter.write(objectToSave, update); - - /* - * Add Query Options - */ CqlTemplate.addWriteOptions(update, options); - return update; } + /** + * @deprecated Method renamed. Use {@link #createUpdateBatchQuery(String, List, WriteOptions, EntityWriter)} + * @see #createUpdateBatchQuery(String, List, WriteOptions, EntityWriter) + */ + @Deprecated + public static Batch toUpdateBatchQuery(String tableName, List objectsToSave, WriteOptions options, + EntityWriter entityWriter) { + return createUpdateBatchQuery(tableName, objectsToSave, options, entityWriter); + } + /** * Generates a Batch Object for multiple Updates * @@ -685,27 +890,18 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation * @param optionsByName * @return The Query object to run with session.execute(); */ - public static Batch toUpdateBatchQuery(String tableName, List objectsToSave, WriteOptions options, + public static Batch createUpdateBatchQuery(String tableName, List objectsToSave, WriteOptions options, EntityWriter entityWriter) { - /* - * Return variable is a Batch statement - */ Batch b = QueryBuilder.batch(); for (T objectToSave : objectsToSave) { - - b.add(toUpdateQuery(tableName, objectToSave, options, entityWriter)); - + b.add(createUpdateQuery(tableName, objectToSave, options, entityWriter)); } - /* - * Add Query Options - */ CqlTemplate.addQueryOptions(b, options); return b; - } /** @@ -745,13 +941,9 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation Delete.Selection ds = QueryBuilder.delete(); Delete delete = ds.from(tableName); - Where w = delete.where(); - entityWriter.write(object, w); - CqlTemplate.addQueryOptions(delete, options); - return delete; } @@ -790,4 +982,59 @@ public class CassandraTemplate extends CqlTemplate implements CassandraOperation truncate(mappingContext.getPersistentEntity(clazz).getTableName()); } + + @Override + public Cancellable selectOneAsynchronously(Select select, Class type, QueryForObjectListener listener) { + return selectOneAsynchronously(select, type, listener, null); + } + + @Override + public Cancellable selectOneAsynchronously(String cql, Class type, QueryForObjectListener listener) { + return selectOneAsynchronously(cql, type, listener, null); + } + + @Override + public Cancellable selectOneAsynchronously(Select select, Class type, QueryForObjectListener listener, + QueryOptions options) { + return doSelectOneAsync(select, type, listener, options); + } + + @Override + public Cancellable selectOneAsynchronously(String cql, Class type, QueryForObjectListener listener, + QueryOptions options) { + return doSelectOneAsync(cql, type, listener, options); + } + + protected Cancellable doSelectOneAsync(final Object query, final Class type, + final QueryForObjectListener listener, QueryOptions options) { + + AsynchronousQueryListener aql = new AsynchronousQueryListener() { + + @Override + public void onQueryComplete(ResultSetFuture rsf) { + try { + ResultSet rs = rsf.getUninterruptibly(); + Iterator iterator = rs.iterator(); + if (iterator.hasNext()) { + Row row = iterator.next(); + T result = new CassandraConverterRowCallback(cassandraConverter, type).doWith(row); + if (iterator.hasNext()) { + throw new DuplicateKeyException("found two or more results in query " + query); + } + listener.onQueryComplete(result); + } + } catch (Exception e) { + listener.onException(translateExceptionIfPossible(e)); + } + } + }; + if (query instanceof String) { + return queryAsynchronously((String) query, aql, options); + } + if (query instanceof Select) { + return queryAsynchronously((Select) query, aql); + } + throw new IllegalArgumentException(String.format("Expected type String or Select; got type [%s] with value [%s]", + query.getClass(), query)); + } } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/DeletionListener.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/DeletionListener.java new file mode 100644 index 000000000..a09175ce3 --- /dev/null +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/DeletionListener.java @@ -0,0 +1,15 @@ +package org.springframework.data.cassandra.core; + +import java.util.Collection; + +import com.datastax.driver.core.ResultSet; + +public interface DeletionListener { + + void onDeletionComplete(Collection entities); + + /** + * Called if an exception is raised while getting or converting the {@link ResultSet}. + */ + void onException(Exception x); +} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/WriteListener.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/WriteListener.java new file mode 100644 index 000000000..a0a27079a --- /dev/null +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/WriteListener.java @@ -0,0 +1,40 @@ +/* + * Copyright 2013-2014 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.core; + +import java.util.Collection; + +import com.datastax.driver.core.ResultSet; + +/** + * Listener for asynchronous repository insert or update methods. + * + * @author Matthew T. Adams + */ +public interface WriteListener { + + /** + * Called upon completion of the asynchronous insert or update. + * + * @param entities The entities inserted or updated. + */ + void onWriteComplete(Collection entities); + + /** + * Called if an exception is raised while getting or converting the {@link ResultSet}. + */ + void onException(Exception x); +} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentProperty.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentProperty.java index cc9c09f4d..928e6c379 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentProperty.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/BasicCassandraPersistentProperty.java @@ -192,23 +192,23 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP if (type.isCollection()) { switch (type) { - case MAP: - ensureTypeArguments(annotation.typeArguments().length, 2); - return DataType.map(getDataTypeFor(annotation.typeArguments()[0]), - getDataTypeFor(annotation.typeArguments()[1])); + case MAP: + ensureTypeArguments(annotation.typeArguments().length, 2); + return DataType.map(getDataTypeFor(annotation.typeArguments()[0]), + getDataTypeFor(annotation.typeArguments()[1])); - case LIST: - ensureTypeArguments(annotation.typeArguments().length, 1); - return DataType.list(getDataTypeFor(annotation.typeArguments()[0])); + case LIST: + ensureTypeArguments(annotation.typeArguments().length, 1); + return DataType.list(getDataTypeFor(annotation.typeArguments()[0])); - case SET: - ensureTypeArguments(annotation.typeArguments().length, 1); - return DataType.set(getDataTypeFor(annotation.typeArguments()[0])); + case SET: + ensureTypeArguments(annotation.typeArguments().length, 1); + return DataType.set(getDataTypeFor(annotation.typeArguments()[0])); - default: - throw new InvalidDataAccessApiUsageException( - String.format("unknown multivalued DataType [%s] for property [%s] in entity [%s]", type, getType(), - getOwner().getName())); + default: + throw new InvalidDataAccessApiUsageException(String.format( + "unknown multivalued DataType [%s] for property [%s] in entity [%s]", type, getType(), getOwner() + .getName())); } } else { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPrimaryKeyColumnAnnotationComparator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPrimaryKeyColumnAnnotationComparator.java index 49c9ea0bd..9d8438741 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPrimaryKeyColumnAnnotationComparator.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPrimaryKeyColumnAnnotationComparator.java @@ -31,7 +31,6 @@ import org.springframework.cassandra.core.PrimaryKeyType; * * @see PrimaryKeyType#compareTo(PrimaryKeyType) * @see Ordering#compareTo(Ordering) - * * @author Matthew T. Adams */ public enum CassandraPrimaryKeyColumnAnnotationComparator implements Comparator { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/VerifierMappingExceptions.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/VerifierMappingExceptions.java index 695d701e4..7a0864216 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/VerifierMappingExceptions.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/VerifierMappingExceptions.java @@ -25,7 +25,6 @@ import org.springframework.data.mapping.model.MappingException; * framework to communicate all verification errors to the user of the framework, rather than one at a time. * * @author David Webb - * */ @SuppressWarnings("serial") public class VerifierMappingExceptions extends MappingException { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/config/CassandraRepositoryConfigurationExtension.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/config/CassandraRepositoryConfigurationExtension.java index 0e6579637..a714504d2 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/config/CassandraRepositoryConfigurationExtension.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/config/CassandraRepositoryConfigurationExtension.java @@ -31,7 +31,6 @@ import org.w3c.dom.Element; * {@link RepositoryConfigurationExtension} for Cassandra. * * @author Alex Shvid - * */ public class CassandraRepositoryConfigurationExtension extends RepositoryConfigurationExtensionSupport { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityInformation.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityInformation.java index b7c8976fe..9cc0f3069 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityInformation.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityInformation.java @@ -23,7 +23,6 @@ import org.springframework.data.repository.core.EntityInformation; * Cassandra specific {@link EntityInformation}. * * @author Alex Shvid - * */ public interface CassandraEntityInformation extends EntityInformation, CassandraEntityMetadata { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityMetadata.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityMetadata.java index 9d4873b8a..6b5ef670d 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityMetadata.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraEntityMetadata.java @@ -23,7 +23,6 @@ import org.springframework.data.repository.core.EntityMetadata; * * @author Alex Shvid * @author Matthew T. Adams - * * @param */ public interface CassandraEntityMetadata extends EntityMetadata { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraParameterAccessor.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraParameterAccessor.java index 0261f7704..b8d0b69a4 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraParameterAccessor.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraParameterAccessor.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.repository.query; import org.springframework.data.repository.query.ParameterAccessor; -public interface CassandraParameterAccessor extends ParameterAccessor { -} +public interface CassandraParameterAccessor extends ParameterAccessor {} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraQueryCreator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraQueryCreator.java index a6ba28122..308dd8a5c 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraQueryCreator.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraQueryCreator.java @@ -167,22 +167,22 @@ class CassandraQueryCreator extends AbstractQueryCreator { // // return isSimpleComparisionPossible(part) ? criteria.ne(parameters.nextConverted(property)) // : createLikeRegexCriteriaOrThrow(part, property, criteria, parameters, true); - default: - throw new UnsupportedCassandraQueryOperatorException(String.format("")); + default: + throw new UnsupportedCassandraQueryOperatorException(String.format("")); } } private boolean isSimpleComparisionPossible(Part part) { switch (part.shouldIgnoreCase()) { - case NEVER: - return true; - case WHEN_POSSIBLE: - return part.getProperty().getType() != String.class; - case ALWAYS: - return false; - default: - return true; + case NEVER: + return true; + case WHEN_POSSIBLE: + return part.getProperty().getType() != String.class; + case ALWAYS: + return false; + default: + return true; } } diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraQueryMethod.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraQueryMethod.java index 1e20b081e..bed5e2f33 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraQueryMethod.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/CassandraQueryMethod.java @@ -182,4 +182,4 @@ public class CassandraQueryMethod extends QueryMethod { public boolean isDateParameter(int parameterIndex) { return dateParameterIndexes.contains(parameterIndex); } -} \ No newline at end of file +} diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/PartTreeCassandraQuery.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/PartTreeCassandraQuery.java index 837d88343..9b4439951 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/PartTreeCassandraQuery.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/query/PartTreeCassandraQuery.java @@ -24,7 +24,6 @@ import org.springframework.data.repository.query.parser.PartTree; /** * {@link RepositoryQuery} implementation for Cassandra. - * */ public class PartTreeCassandraQuery extends AbstractCassandraQuery { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/BasicMapId.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/BasicMapId.java index b48b60ac4..c1fb69def 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/BasicMapId.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/BasicMapId.java @@ -52,8 +52,7 @@ public class BasicMapId implements MapId { protected Map map = new HashMap(); - public BasicMapId() { - } + public BasicMapId() {} public BasicMapId(Map map) { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactoryBean.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactoryBean.java index 3ea8fbbc3..c1ee13cd5 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactoryBean.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/repository/support/CassandraRepositoryFactoryBean.java @@ -28,7 +28,6 @@ import org.springframework.util.Assert; * {@link org.springframework.beans.factory.FactoryBean} to create {@link TypedIdCassandraRepository} instances. * * @author Alex Shvid - * */ public class CassandraRepositoryFactoryBean, S, ID extends Serializable> extends RepositoryFactoryBeanSupport { diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/util/CqlUtils.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/util/CqlUtils.java index 27ed82219..ec14d357c 100644 --- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/util/CqlUtils.java +++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/util/CqlUtils.java @@ -33,7 +33,6 @@ import com.datastax.driver.core.TableMetadata; * @author Alex Shvid * @author David Webb * @author Matthew T. Adams - * * @deprecated need to find a better place for this */ @Deprecated diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java index 10bd10254..ce14d333f 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/collections/CollectionsRowValueProviderTest.java @@ -42,7 +42,6 @@ import com.datastax.driver.core.querybuilder.Select; /** * @author dwebb - * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Comment.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Comment.java index 6e2ce01cd..93e1877f4 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Comment.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Comment.java @@ -38,8 +38,7 @@ public class Comment { * @deprecated Only for use by persistence infrastructure */ @Deprecated - protected Comment() { - } + protected Comment() {} public Comment(String author, String company) { this(new CommentKey(author, company)); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentKey.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentKey.java index dcbc19eae..9c0a31ac0 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentKey.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentKey.java @@ -42,8 +42,7 @@ public class CommentKey implements Serializable { * @deprecated Only for use by persistence infrastructure */ @Deprecated - protected CommentKey() { - } + protected CommentKey() {} public CommentKey(String author, String company) { setAuthor(author); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepository.java index 32e1176ca..e7b593062 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepository.java @@ -17,5 +17,4 @@ package org.springframework.data.cassandra.test.integration.composites; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; -public interface CommentRepository extends TypedIdCassandraRepository { -} +public interface CommentRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java index cb6dd3f31..42eda1044 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/CommentRepositoryIntegrationTests.java @@ -31,8 +31,7 @@ public class CommentRepositoryIntegrationTests { CommentRepository repository; CassandraOperations template; - public CommentRepositoryIntegrationTests() { - } + public CommentRepositoryIntegrationTests() {} public CommentRepositoryIntegrationTests(CommentRepository repository, CassandraOperations template) { this.repository = repository; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Notification.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Notification.java index d5391c359..f30554b70 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Notification.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Notification.java @@ -22,10 +22,9 @@ import org.springframework.data.cassandra.mapping.Indexed; import org.springframework.data.cassandra.mapping.Table; /** - * This is an example of dynamic table that creates each time new column with Notification timestamp. - * - * By default it is active Notification until user deactivate it. This table uses index on the field active to access in - * WHERE cause only for active notifications. + * This is an example of dynamic table that creates each time new column with Notification timestamp. By default it is + * active Notification until user deactivate it. This table uses index on the field active to access in WHERE cause only + * for active notifications. * * @author Alex Shvid */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java index ec458b3bf..12fab6925 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/NotificationPK.java @@ -26,10 +26,9 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; import com.datastax.driver.core.DataType; /** - * This is an example of dynamic table that creates each time new column with Notification timestamp. - * - * By default it is active Notification until user deactivate it. This table uses index on the field active to access in - * WHERE cause only for active notifications. + * This is an example of dynamic table that creates each time new column with Notification timestamp. By default it is + * active Notification until user deactivate it. This table uses index on the field active to access in WHERE cause only + * for active notifications. * * @author Alex Shvid */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Post.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Post.java index 28a12f415..35574559f 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Post.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Post.java @@ -23,11 +23,10 @@ import org.springframework.data.annotation.Id; import org.springframework.data.cassandra.mapping.Table; /** - * This is an example of dynamic table that creates each time new column with Post timestamp. - * - * It is possible to use a static table for posts and identify them by PostId(UUID), but in this case we need to use - * MapReduce for Big Data to find posts for particular user, so it is better to have index (userId) -> index (post time) - * architecture. It helps a lot to build eventually a search index for the particular user. + * This is an example of dynamic table that creates each time new column with Post timestamp. It is possible to use a + * static table for posts and identify them by PostId(UUID), but in this case we need to use MapReduce for Big Data to + * find posts for particular user, so it is better to have index (userId) -> index (post time) architecture. It helps a + * lot to build eventually a search index for the particular user. * * @author Alex Shvid */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java index ccc567e32..98d832488 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/PostPK.java @@ -23,11 +23,10 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyClass; import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; /** - * This is an example of dynamic table that creates each time new column with Post timestamp. - * - * It is possible to use a static table for posts and identify them by PostId(UUID), but in this case we need to use - * MapReduce for Big Data to find posts for particular user, so it is better to have index (userId) -> index (post time) - * architecture. It helps a lot to build eventually a search index for the particular user. + * This is an example of dynamic table that creates each time new column with Post timestamp. It is possible to use a + * static table for posts and identify them by PostId(UUID), but in this case we need to use MapReduce for Big Data to + * find posts for particular user, so it is better to have index (userId) -> index (post time) architecture. It helps a + * lot to build eventually a search index for the particular user. * * @author Alex Shvid */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Timeline.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Timeline.java index 8e9e8685c..870a88f60 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Timeline.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/Timeline.java @@ -22,10 +22,9 @@ import org.springframework.data.cassandra.mapping.Table; /** * This is an example of the users timeline dynamic table, where all columns are dynamically created by @ColumnId field - * value. The rest fields are places in Cassandra value. - * - * Timeline entity is used to store user's status updates that it follows in the site. Timeline always ordered by @ColumnId - * field and we can retrieve last top status updates by using limits. + * value. The rest fields are places in Cassandra value. Timeline entity is used to store user's status updates that it + * follows in the site. Timeline always ordered by @ColumnId field and we can retrieve last top status updates by using + * limits. * * @author Alex Shvid */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java index 11de07a8d..55306ad6f 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/composites/TimelinePK.java @@ -24,10 +24,9 @@ import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; /** * This is an example of the users timeline dynamic table, where all columns are dynamically created by @ColumnId field - * value. The rest fields are places in Cassandra value. - * - * Timeline entity is used to store user's status updates that it follows in the site. Timeline always ordered by @ColumnId - * field and we can retrieve last top status updates by using limits. + * value. The rest fields are places in Cassandra value. Timeline entity is used to store user's status updates that it + * follows in the site. Timeline always ordered by @ColumnId field and we can retrieve last top status updates by using + * limits. * * @author Alex Shvid */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java index b75dd3d35..4f7b98502 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Explicit.java @@ -19,8 +19,7 @@ public class Explicit { String stringValue = UUID.randomUUID().toString(); @SuppressWarnings("unused") - private Explicit() { - } + private Explicit() {} public Explicit(ExplicitKey primaryKey) { setPrimaryKey(primaryKey); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java index ddae393dd..3d65630ff 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ExplicitRepository.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.test.integration.forcequote.composite import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; -public interface ExplicitRepository extends TypedIdCassandraRepository { -} +public interface ExplicitRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java index 1b0496ebc..cad059156 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests.java @@ -12,8 +12,7 @@ public class ForceQuotedCompositePrimaryKeyRepositoryJavaConfigIntegrationTests @Configuration @EnableCassandraRepositories(basePackageClasses = ImplicitRepository.class) - public static class Config extends IntegrationTestConfig { - } + public static class Config extends IntegrationTestConfig {} @Test public void testExplicit() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java index 389749ab9..ca4182322 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/Implicit.java @@ -14,8 +14,7 @@ public class Implicit { String stringValue = UUID.randomUUID().toString(); @SuppressWarnings("unused") - private Implicit() { - } + private Implicit() {} public Implicit(ImplicitKey primaryKey) { setPrimaryKey(primaryKey); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java index 644029a52..e7077ddda 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/compositeprimarykey/ImplicitRepository.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.test.integration.forcequote.composite import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; -public interface ImplicitRepository extends TypedIdCassandraRepository { -} +public interface ImplicitRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitPropertiesRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitPropertiesRepository.java index a72a59e58..f676978f8 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitPropertiesRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitPropertiesRepository.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; -public interface ExplicitPropertiesRepository extends TypedIdCassandraRepository { -} +public interface ExplicitPropertiesRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitRepository.java index 83f5ccb4d..907721dbc 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ExplicitRepository.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; -public interface ExplicitRepository extends TypedIdCassandraRepository { -} +public interface ExplicitRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java index 4a133c9a1..d120941bf 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ForceQuotedRepositoryJavaConfigIntegrationTests.java @@ -11,8 +11,7 @@ public class ForceQuotedRepositoryJavaConfigIntegrationTests extends ForceQuoted @Configuration @EnableCassandraRepositories(basePackageClasses = ForceQuotedRepositoryIntegrationTests.class) - public static class Config extends IntegrationTestConfig { - } + public static class Config extends IntegrationTestConfig {} @Test public void testExplicit() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitPropertiesRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitPropertiesRepository.java index 8e51a83c8..46c7f54d7 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitPropertiesRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitPropertiesRepository.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; -public interface ImplicitPropertiesRepository extends TypedIdCassandraRepository { -} +public interface ImplicitPropertiesRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitRepository.java index 944d571b2..e9c3d9829 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/config/ImplicitRepository.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.test.integration.forcequote.config; import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; -public interface ImplicitRepository extends TypedIdCassandraRepository { -} +public interface ImplicitRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedEntitiesSimpleIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedEntitiesSimpleIntegrationTests.java index edfd11404..8e53081ed 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedEntitiesSimpleIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedEntitiesSimpleIntegrationTests.java @@ -19,8 +19,7 @@ public class ForceQuotedEntitiesSimpleIntegrationTests { } @Table(forceQuote = true) - public static class ImplicitTableNameForceQuoted { - } + public static class ImplicitTableNameForceQuoted {} public static final String EXPLICIT_TABLE_NAME = "Xx"; @@ -34,8 +33,7 @@ public class ForceQuotedEntitiesSimpleIntegrationTests { } @Table(value = EXPLICIT_TABLE_NAME, forceQuote = true) - public static class ExplicitTableNameForceQuoted { - } + public static class ExplicitTableNameForceQuoted {} @Test public void testDefaultTableNameForceQuoted() { @@ -47,6 +45,5 @@ public class ForceQuotedEntitiesSimpleIntegrationTests { } @Table - public static class DefaultTableNameForceQuoted { - } -} \ No newline at end of file + public static class DefaultTableNameForceQuoted {} +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java index 6222087d5..8269eaf2f 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/forcequote/simple/ForceQuotedPropertiesSimpleIntegrationTests.java @@ -212,4 +212,4 @@ public class ForceQuotedPropertiesSimpleIntegrationTests { @Column(forceQuote = true) String aString; } -} \ No newline at end of file +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityIntegrationTests.java index e3cdb7a19..28df7b5dc 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityIntegrationTests.java @@ -74,19 +74,15 @@ public class BasicCassandraPersistentEntityIntegrationTests { } @Table("messages") - static class Message { - } + static class Message {} - static class Notification extends Message { - } + static class Notification extends Message {} @Table("#{'a123'}") - static class Area { - } + static class Area {} @Table("#{tableNameHolderThingy.tableName}") - static class UserLine { - } + static class UserLine {} static class TableNameHolderThingy { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityVerifierIntegrationTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityVerifierIntegrationTest.java index 2ccd40d5e..6fdaebf0a 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityVerifierIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/BasicCassandraPersistentEntityVerifierIntegrationTest.java @@ -35,7 +35,6 @@ import org.springframework.data.mapping.model.MappingException; /** * @author dwebb - * */ public class BasicCassandraPersistentEntityVerifierIntegrationTest { @@ -184,8 +183,7 @@ public class BasicCassandraPersistentEntityVerifierIntegrationTest { @Table @PrimaryKeyClass - static class TooManyAnnotations { - } + static class TooManyAnnotations {} @Table public static class NoPartitionKey { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkc.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkc.java index b2c002f2c..4331eb050 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkc.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkc.java @@ -22,8 +22,7 @@ public class MultiPkc { */ @Deprecated @SuppressWarnings("unused") - private MultiPkc() { - } + private MultiPkc() {} public MultiPkc(String key0, String key1) { setKey0(key0); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkcRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkcRepository.java index c7f02b980..1a4a3721b 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkcRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/MultiPkcRepository.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; import org.springframework.data.cassandra.repository.CassandraRepository; -public interface MultiPkcRepository extends CassandraRepository { -} +public interface MultiPkcRepository extends CassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkc.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkc.java index 7e0ce4caf..1a00dad81 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkc.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkc.java @@ -19,8 +19,7 @@ public class SinglePkc { */ @Deprecated @SuppressWarnings("unused") - private SinglePkc() { - } + private SinglePkc() {} public SinglePkc(String key) { setKey(key); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkcRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkcRepository.java index 436f134a5..98fd736f7 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkcRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/repo/SinglePkcRepository.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.test.integration.mapping.mapid.repo; import org.springframework.data.cassandra.repository.CassandraRepository; -public interface SinglePkcRepository extends CassandraRepository { -} +public interface SinglePkcRepository extends CassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/template/CassandraTemplateMapIdIntegrationTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/template/CassandraTemplateMapIdIntegrationTest.java index c3ae31241..28a0ae56c 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/template/CassandraTemplateMapIdIntegrationTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mapping/mapid/template/CassandraTemplateMapIdIntegrationTest.java @@ -88,8 +88,7 @@ public class CassandraTemplateMapIdIntegrationTest extends AbstractSpringDataEmb */ @Deprecated @SuppressWarnings("unused") - private SinglePkc() { - } + private SinglePkc() {} public SinglePkc(String key) { setKey(key); @@ -160,8 +159,7 @@ public class CassandraTemplateMapIdIntegrationTest extends AbstractSpringDataEmb */ @Deprecated @SuppressWarnings("unused") - private MultiPkc() { - } + private MultiPkc() {} public MultiPkc(String key0, String key1) { setKey0(key0); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mappingcontext/MappingContextIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mappingcontext/MappingContextIntegrationTests.java index 13c0fd6b6..2f201544a 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mappingcontext/MappingContextIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/mappingcontext/MappingContextIntegrationTests.java @@ -28,8 +28,7 @@ import org.springframework.data.mapping.model.MappingException; public class MappingContextIntegrationTests { - public static class Transient { - } + public static class Transient {} @Table public static class X { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMinRepository.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMinRepository.java index e6fb1017d..a6564f2c6 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMinRepository.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/minimal/config/entities/AbsMinRepository.java @@ -17,5 +17,4 @@ package org.springframework.data.cassandra.test.integration.minimal.config.entit import org.springframework.data.cassandra.repository.TypedIdCassandraRepository; -public interface AbsMinRepository extends TypedIdCassandraRepository { -} +public interface AbsMinRepository extends TypedIdCassandraRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/Thing.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/Thing.java index d55ac28ae..09d5c55e4 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/Thing.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/datekey/Thing.java @@ -13,8 +13,7 @@ public class Thing { @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private Date date; - protected Thing() { - } + protected Thing() {} public Thing(Date date) { setDate(date); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/QueryAnnotationIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/QueryAnnotationIntegrationTests.java index df6841ff7..9b6c184a5 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/QueryAnnotationIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/anno/QueryAnnotationIntegrationTests.java @@ -10,6 +10,5 @@ public class QueryAnnotationIntegrationTests extends QueryIntegrationTests { @Configuration @EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithQueryAnnotations.class) - public static class Config extends QueryIntegrationTests.Config { - } + public static class Config extends QueryIntegrationTests.Config {} } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/NamedQueryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/NamedQueryIntegrationTests.java index 0673f347c..ca629a0cc 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/NamedQueryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/NamedQueryIntegrationTests.java @@ -9,7 +9,7 @@ import org.springframework.test.context.ContextConfiguration; public class NamedQueryIntegrationTests extends QueryIntegrationTests { @Configuration - @EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithNamedQueries.class, namedQueriesLocation = "classpath:META-INF/PersonRepositoryWithNamedQueries.properties") - public static class Config extends QueryIntegrationTests.Config { - } + @EnableCassandraRepositories(basePackageClasses = PersonRepositoryWithNamedQueries.class, + namedQueriesLocation = "classpath:META-INF/PersonRepositoryWithNamedQueries.properties") + public static class Config extends QueryIntegrationTests.Config {} } diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/PersonRepositoryWithNamedQueries.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/PersonRepositoryWithNamedQueries.java index 1ec86d130..954ec79d8 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/PersonRepositoryWithNamedQueries.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/declared/named/PersonRepositoryWithNamedQueries.java @@ -2,5 +2,4 @@ package org.springframework.data.cassandra.test.integration.querymethods.declare import org.springframework.data.cassandra.test.integration.querymethods.declared.base.PersonRepository; -public interface PersonRepositoryWithNamedQueries extends PersonRepository { -} +public interface PersonRepositoryWithNamedQueries extends PersonRepository {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/derived/TODO.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/derived/TODO.java index 61673e3ec..678cd8808 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/derived/TODO.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/derived/TODO.java @@ -1,5 +1,4 @@ package org.springframework.data.cassandra.test.integration.querymethods.derived; // TODO -public class TODO { -} +public class TODO {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/Thing.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/Thing.java index b444b6592..09f8cba66 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/Thing.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/querymethods/intparam/Thing.java @@ -10,8 +10,7 @@ public class Thing { @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) private int number; - public Thing() { - } + public Thing() {} public Thing(int number) { setNumber(number); diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/User.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/User.java index f628ed68e..b78d9ff7a 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/User.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/User.java @@ -23,10 +23,8 @@ import org.springframework.data.cassandra.mapping.Table; /** * This is an example of the Users status table, where all fields are columns in Cassandra row. Some fields can be - * Set,List,Map like emails. - * - * User contains base information related for separate user, like names, additional information, emails, following - * users, friends. + * Set,List,Map like emails. User contains base information related for separate user, like names, additional + * information, emails, following users, friends. * * @author Alex Shvid */ diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java index 8a3a90004..7e6fb3252 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryIntegrationTests.java @@ -48,8 +48,7 @@ public class UserRepositoryIntegrationTests { List all; - public UserRepositoryIntegrationTests() { - } + public UserRepositoryIntegrationTests() {} public UserRepositoryIntegrationTests(UserRepository repository, CassandraOperations template) { this.repository = repository; diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java index 1b9868394..9291308b4 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/repository/UserRepositoryXmlConfigIntegrationTests.java @@ -23,5 +23,4 @@ import org.springframework.test.context.ContextConfiguration; * @author Matthew T. Adams */ @ContextConfiguration -public class UserRepositoryXmlConfigIntegrationTests extends UserRepositoryIntegrationTestsDelegator { -} +public class UserRepositoryXmlConfigIntegrationTests extends UserRepositoryIntegrationTestsDelegator {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/Book.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/Book.java index 7c6969957..f57418631 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/Book.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/Book.java @@ -24,7 +24,6 @@ import org.springframework.data.cassandra.mapping.Table; * Test POJO * * @author David Webb - * */ @Table("book") public class Book { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookHistory.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookHistory.java index 7e5aa959e..58bf2d294 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookHistory.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookHistory.java @@ -25,7 +25,6 @@ import org.springframework.data.cassandra.mapping.Table; * Test POJO * * @author David Webb - * */ @Table("bookHistory") public class BookHistory { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookReference.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookReference.java index 314cf57b9..24800bd49 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookReference.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/BookReference.java @@ -26,7 +26,6 @@ import org.springframework.data.cassandra.mapping.Table; * Test POJO * * @author David Webb - * */ @Table("bookReference") public class BookReference { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/LogEntry.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/LogEntry.java index d2bc3850b..7319eb6ed 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/LogEntry.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/simpletons/LogEntry.java @@ -23,7 +23,6 @@ import org.springframework.data.cassandra.mapping.Table; /** * This is an example of the LogEntry static table, where all fields are columns in Cassandra row. * - * * @author Alex Shvid */ @Table("log_entry") diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/TestListener.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/TestListener.java new file mode 100644 index 000000000..aeb8b2ec3 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/support/TestListener.java @@ -0,0 +1,34 @@ +package org.springframework.data.cassandra.test.integration.support; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** + * Convenient listener base class that includes a {@link CountDownLatch} in order to test asynchronous behavior. + * + * @author Matthew T. Adams + */ +public class TestListener { + + protected CountDownLatch latch; + + public TestListener() { + this(1); + } + + public TestListener(int latchCount) { + latch = new CountDownLatch(latchCount); + } + + public void await() throws InterruptedException { + latch.await(); + } + + public void await(long ms) throws InterruptedException { + latch.await(ms, TimeUnit.MILLISECONDS); + } + + public void countDown() { + latch.countDown(); + } +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/async/AsynchronousCassandraTemplateTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/async/AsynchronousCassandraTemplateTest.java new file mode 100644 index 000000000..8b1f82ea2 --- /dev/null +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/template/async/AsynchronousCassandraTemplateTest.java @@ -0,0 +1,261 @@ +/* + * Copyright 2013-2014 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.cassandra.test.integration.template.async; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; +import static org.springframework.data.cassandra.repository.support.BasicMapId.id; + +import java.util.Collection; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.CancellationException; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cassandra.core.ConsistencyLevel; +import org.springframework.cassandra.core.PrimaryKeyType; +import org.springframework.cassandra.core.RetryPolicy; +import org.springframework.cassandra.core.WriteOptions; +import org.springframework.cassandra.support.exception.CassandraInsufficientReplicasAvailableException; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.cassandra.core.CassandraOperations; +import org.springframework.data.cassandra.core.CassandraTemplate; +import org.springframework.data.cassandra.core.DeletionListener; +import org.springframework.data.cassandra.core.WriteListener; +import org.springframework.data.cassandra.mapping.Column; +import org.springframework.data.cassandra.mapping.PrimaryKeyColumn; +import org.springframework.data.cassandra.mapping.Table; +import org.springframework.data.cassandra.test.integration.support.AbstractSpringDataEmbeddedCassandraIntegrationTest; +import org.springframework.data.cassandra.test.integration.support.IntegrationTestConfig; +import org.springframework.data.cassandra.test.integration.support.TestListener; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * Asynchronous {@link CassandraTemplate} tests. + * + * @author Matthew T. Adams + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration +public class AsynchronousCassandraTemplateTest extends AbstractSpringDataEmbeddedCassandraIntegrationTest { + + @Configuration + public static class Config extends IntegrationTestConfig {} + + @Table + public static class Thing { + + public static final String uuid() { + return UUID.randomUUID().toString(); + } + + static final Random RNG = new Random(); + + public static Thing random() { + return new Thing(uuid(), RNG.nextInt()); + } + + @PrimaryKeyColumn(ordinal = 0, type = PrimaryKeyType.PARTITIONED) + public String stuff; + + @Column + public int number; + + public Thing() {} + + public Thing(String stuff, int number) { + this.stuff = stuff; + this.number = number; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + number; + result = prime * result + ((stuff == null) ? 0 : stuff.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Thing other = (Thing) obj; + if (number != other.number) + return false; + if (stuff == null) { + if (other.stuff != null) + return false; + } else if (!stuff.equals(other.stuff)) + return false; + return true; + } + } + + public static class ThingWriteListener extends TestListener implements WriteListener { + + public Exception exception; + public Collection entities; + + @Override + public void onWriteComplete(Collection entities) { + this.entities = entities; + countDown(); + } + + @Override + public void onException(Exception x) { + this.exception = x; + countDown(); + } + } + + public static class ThingDeletionListener extends TestListener implements DeletionListener { + + public Exception exception; + public Collection entities; + + @Override + public void onDeletionComplete(Collection entities) { + this.entities = entities; + countDown(); + } + + @Override + public void onException(Exception x) { + this.exception = x; + countDown(); + } + } + + @Autowired + CassandraOperations t; + + @Before + public void before() { + deleteAllEntities(); + } + + public void testInsertAsynchronously(ConsistencyLevel cl) throws Exception { + Thing thing = Thing.random(); + ThingWriteListener listener = new ThingWriteListener(); + t.insertAsynchronously(thing, listener, new WriteOptions(cl, RetryPolicy.LOGGING)); + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + assertEquals(thing, listener.entities.iterator().next()); + } + + @Test + public void testInsertAsynchronously() throws Exception { + testInsertAsynchronously(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraInsufficientReplicasAvailableException.class) + public void testInsertAsynchronouslyThrows() throws Exception { + testInsertAsynchronously(ConsistencyLevel.TWO); + } + + public void testInsertOrUpdateAsynchronouslyCancelled(boolean insert) throws Exception { + Thing thing = Thing.random(); + ThingWriteListener listener = new ThingWriteListener(); + (insert ? t.insertAsynchronously(thing, listener, null) : t.updateAsynchronously(thing, listener, null)).cancel(); + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + fail("should've thrown CancellationException"); + } + + @Test(expected = CancellationException.class) + public void testInsertAsynchronouslyCancelled() throws Exception { + testInsertOrUpdateAsynchronouslyCancelled(true); + } + + @Test(expected = CancellationException.class) + public void testUpdateAsynchronouslyCancelled() throws Exception { + testInsertOrUpdateAsynchronouslyCancelled(false); + } + + public void testUpdateAsynchronously(ConsistencyLevel cl) throws Exception { + Thing thing = Thing.random(); + t.insert(thing); + thing.number = Thing.random().number; + ThingWriteListener listener = new ThingWriteListener(); + t.updateAsynchronously(thing, listener, new WriteOptions(cl, RetryPolicy.LOGGING)); + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + assertEquals(thing, listener.entities.iterator().next()); + } + + @Test + public void testUpdateAsynchronously() throws Exception { + testUpdateAsynchronously(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraInsufficientReplicasAvailableException.class) + public void testUpdateAsynchronouslyThrows() throws Exception { + testUpdateAsynchronously(ConsistencyLevel.TWO); + } + + public void testDeleteAsynchronously(ConsistencyLevel cl) throws Exception { + Thing thing = Thing.random(); + t.insert(thing); + ThingDeletionListener listener = new ThingDeletionListener(); + t.deleteAsynchronously(thing, listener, new WriteOptions(cl, RetryPolicy.LOGGING)); + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + assertFalse(t.exists(Thing.class, id("stuff", thing.stuff))); + } + + @Test + public void testDeleteAsynchronously() throws Exception { + testDeleteAsynchronously(ConsistencyLevel.ONE); + } + + @Test(expected = CassandraInsufficientReplicasAvailableException.class) + public void testDeleteAsynchronouslyThrows() throws Exception { + testDeleteAsynchronously(ConsistencyLevel.TWO); + } + + @Test(expected = CancellationException.class) + public void testDeleteAsynchronouslyCancelled() throws Exception { + Thing thing = Thing.random(); + ThingDeletionListener listener = new ThingDeletionListener(); + t.deleteAsynchronously(thing, listener, null).cancel(); + listener.await(); + if (listener.exception != null) { + throw listener.exception; + } + fail("should've thrown CancellationException"); + } + +} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntity.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntity.java index f7e3e74f7..5d3489f33 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntity.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/AnotherScannedEntity.java @@ -24,7 +24,8 @@ public class AnotherScannedEntity { /* * Primary Row ID */ - @Id private String name; + @Id + private String name; @SuppressWarnings("unused") private AnotherScannedEntity() {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntity.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntity.java index 3b59628aa..5ac06858f 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntity.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/ScannedEntity.java @@ -24,7 +24,8 @@ public class ScannedEntity { /* * Primary Row ID */ - @Id private String name; + @Id + private String name; @SuppressWarnings("unused") private ScannedEntity() {} diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests.java index 2518ea6fc..cec317647 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/integration/xmlentityscanning/XmlEntityScanningIntegrationTests.java @@ -27,10 +27,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration public class XmlEntityScanningIntegrationTests extends AbstractSpringDataEmbeddedCassandraIntegrationTest { - @Autowired ScannedEntityRepository repository; - @Autowired AnotherScannedEntityRepository anotherRepository; + @Autowired + ScannedEntityRepository repository; + @Autowired + AnotherScannedEntityRepository anotherRepository; - @Autowired CassandraOperations template; + @Autowired + CassandraOperations template; @Test public void testInsertScannedEntity() { diff --git a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/BasicCassandraPersistentEntityOrderPropertiesTest.java b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/BasicCassandraPersistentEntityOrderPropertiesTest.java index 47ee75998..782d308bc 100644 --- a/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/BasicCassandraPersistentEntityOrderPropertiesTest.java +++ b/spring-data-cassandra/src/test/java/org/springframework/data/cassandra/test/unit/BasicCassandraPersistentEntityOrderPropertiesTest.java @@ -36,7 +36,6 @@ import org.springframework.data.mapping.PropertyHandler; /** * @author David Webb - * */ public class BasicCassandraPersistentEntityOrderPropertiesTest { @@ -44,8 +43,7 @@ public class BasicCassandraPersistentEntityOrderPropertiesTest { private BasicCassandraMappingContext mappingContext = new BasicCassandraMappingContext(); @Before - public void init() { - } + public void init() {} @Test public void testCompositeKeyPropertyOrder() {