DATACASS-144: done; rebased all branch commits

This commit is contained in:
Matthew Adams
2014-09-23 10:50:57 -05:00
parent 88d5aa2100
commit ff41674809
152 changed files with 2624 additions and 762 deletions

View File

@@ -336,10 +336,10 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, 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);
}

View File

@@ -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<Set<KeyspaceActionSpecification<?>>>,
InitializingBean, DisposableBean {
@@ -74,14 +72,14 @@ public class KeyspaceActionSpecificationFactoryBean implements FactoryBean<Set<K
Assert.notNull(action, "Keyspace Action is required for a Keyspace Action");
switch (action) {
case CREATE_DROP:
specs.add(generateDropKeyspaceSpecification());
case CREATE:
// Assert.notNull(replicationStrategy, "Replication Strategy is required to create a Keyspace");
specs.add(generateCreateKeyspaceSpecification());
break;
case ALTER:
break;
case CREATE_DROP:
specs.add(generateDropKeyspaceSpecification());
case CREATE:
// Assert.notNull(replicationStrategy, "Replication Strategy is required to create a Keyspace");
specs.add(generateCreateKeyspaceSpecification());
break;
case ALTER:
break;
}
}

View File

@@ -25,7 +25,6 @@ import org.springframework.beans.factory.FactoryBean;
*
* @author David Webb
* @param <T>
*
*/
public class MultiLevelListFlattenerFactoryBean<T> implements FactoryBean<List<T>> {

View File

@@ -27,7 +27,6 @@ import org.springframework.beans.factory.FactoryBean;
*
* @author David Webb
* @param <T>
*
*/
public class MultiLevelSetFlattenerFactoryBean<T> implements FactoryBean<Set<T>> {

View File

@@ -244,7 +244,6 @@ public class ParsingUtils {
* null or empty, and <code>defaultValue</code> is null or empty, then no property is added and this method
* silently returns.
* @param reference If <code>true</code>, this method will add the property as a reference, else as a value.
*
* @see BeanDefinitionBuilder#addPropertyReference(String, String)
* @see BeanDefinitionBuilder#addPropertyValue(String, Object)
*/

View File

@@ -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);
}

View File

@@ -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 {

View File

@@ -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();
}

View File

@@ -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 {

View File

@@ -19,7 +19,6 @@ package org.springframework.cassandra.core;
* Generic Consistency Levels associated with Cassandra.
*
* @author David Webb
*
*/
public enum ConsistencyLevel {

View File

@@ -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;

View File

@@ -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 <code>execute()</code> or <code>executeAsync()</code> 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 {
*/
<T> List<T> process(ResultSet resultSet, RowMapper<T> 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 <code>T</code>.
* @param listener The listener that receives the results upon completion.
* @return A {@link Cancellable} that can be used to cancel the query.
* @throws DataAccessException
*/
<T> Cancellable queryForObjectAsynchronously(String cql, RowMapper<T> rowMapper, QueryForObjectListener<T> 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 <code>T</code>.
* @param listener The listener that receives the results upon completion.
* @param options The {@link QueryOptions} to use. May be <code>null</code>.
* @return A {@link Cancellable} that can be used to cancel the query.
* @throws DataAccessException
*/
<T> Cancellable queryForObjectAsynchronously(String cql, RowMapper<T> rowMapper, QueryForObjectListener<T> 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 <code>T</code>.
* @param listener The listener that receives the results upon completion.
* @return A {@link Cancellable} that can be used to cancel the query.
* @throws DataAccessException
*/
<T> Cancellable queryForObjectAsynchronously(Select select, RowMapper<T> rowMapper, QueryForObjectListener<T> listener)
throws DataAccessException;
/**
* Executes the provided CQL Query, and maps <b>ONE</b> Row returned with the supplied RowMapper.
* <p>
@@ -638,6 +714,43 @@ public interface CqlOperations {
*/
<T> T queryForObject(String cql, Class<T> requiredType) throws DataAccessException;
/**
* Executes the provided {@link Select} query and returns the first column of the first Row as an object of type
* <code>T</code>.
*
* @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
*/
<T> Cancellable queryForObjectAsynchronously(Select select, Class<T> requiredType, QueryForObjectListener<T> listener)
throws DataAccessException;
/**
* Executes the provided select CQL query and returns the first column of the first Row as an object of type
* <code>T</code>.
*
* @param cql The select query CQL. Must not be <code>null</code> or blank.
* @param requiredType The type to convert the first column of the first row to. Must not be <code>null</code>.
* @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be <code>null</code>.
* @throws DataAccessException
*/
<T> Cancellable queryForObjectAsynchronously(String cql, Class<T> requiredType, QueryForObjectListener<T> listener)
throws DataAccessException;
/**
* Executes the provided select CQL query and returns the first column of the first Row as an object of type
* <code>T</code>.
*
* @param cql The select query CQL. Must not be <code>null</code> or blank.
* @param requiredType The type to convert the first column of the first row to. Must not be <code>null</code>.
* @param options The {@link QueryOptions} to use. May be <code>null</code>.
* @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be <code>null</code>.
* @throws DataAccessException
*/
<T> Cancellable queryForObjectAsynchronously(String cql, Class<T> requiredType, QueryForObjectListener<T> listener,
QueryOptions options) throws DataAccessException;
/**
* Executes the provided Select query and tries to return the first column of the first Row as a Class<T>.
*
@@ -680,6 +793,44 @@ public interface CqlOperations {
*/
Map<String, Object> queryForMap(Select select) throws DataAccessException;
/**
* Executes the provided CQL query asynchronously and maps the first row to a {@link Map}&lt;String,Object&gt;.
* Additional rows are ignored.
*
* @param cql The select query CQL. Must not be <code>null</code> or blank.
* @param listener The {@link QueryForMapListener} that will recieve the results upon query completion. Must not be
* <code>null</code>.
* @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be <code>null</code>.
* @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}&lt;String,Object&gt;.
* Additional rows are ignored.
*
* @param cql The select query CQL. Must not be <code>null</code> or blank.
* @param listener The {@link QueryForMapListener} that will recieve the results upon query completion. Must not be
* <code>null</code>.
* @param options The {@link QueryOptions} to use. May be <code>null</code>.
* @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be <code>null</code>.
* @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}
* &lt;String,Object&gt;. Additional rows are ignored.
*
* @param cql The select query CQL. Must not be <code>null</code> or blank.
* @param listener The {@link QueryForMapListener} that will recieve the results upon query completion. Must not be
* <code>null</code>.
* @return A {@link Cancellable} that can be used to cancel the query if necessary. Must not be <code>null</code>.
* @throws DataAccessException
*/
Cancellable queryForMapAsynchronously(Select select, QueryForMapListener listener) throws DataAccessException;
/**
* Process a ResultSet with <b>ONE</b> 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 {
*/
<T> List<T> queryForList(Select select, Class<T> 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 <code>null</code>.
* @return {@link Cancellable} to cancel the query if necessary
* @throws DataAccessException
*/
<T> Cancellable queryForListAsynchronously(Select select, Class<T> elementType, QueryForListListener<T> 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 <code>null</code>.
* @return {@link Cancellable} to cancel the query if necessary
* @throws DataAccessException
*/
<T> Cancellable queryForListAsynchronously(String select, Class<T> elementType, QueryForListListener<T> 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<Map<String, Object>> 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 <code>null</code>.
* @param listener The listener that will receive the results upon query completion. Must not be <code>null</code>.
* @return A {@link Cancellable} that can be used to cancel the query. Must not be <code>null</code>.
* @throws DataAccessException
*/
Cancellable queryForListOfMapAsynchronously(Select select, QueryForListListener<Map<String, Object>> 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 <code>null</code> or blank.
* @param listener The listener that will receive the results upon query completion. Must not be <code>null</code>.
* @return A {@link Cancellable} that can be used to cancel the query. Must not be <code>null</code>.
* @throws DataAccessException
*/
Cancellable queryForListOfMapAsynchronously(String cql, QueryForListListener<Map<String, Object>> 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 <code>null</code> or blank.
* @param listener The listener that will receive the results upon query completion. Must not be <code>null</code>.
* @param options The {@link QueryOptions} to use. May be <code>null</code>.
* @return A {@link Cancellable} that can be used to cancel the query. Must not be <code>null</code>.
* @throws DataAccessException
*/
Cancellable queryForListOfMapAsynchronously(String cql, QueryForListListener<Map<String, Object>> 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.

View File

@@ -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<QueryCancellor>() {
return execute(new SessionCallback<Cancellable>() {
@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<QueryCancellor>() {
return execute(new SessionCallback<Cancellable>() {
@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<Cancellable>() {
@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<QueryCancellor>() {
return execute(new SessionCallback<Cancellable>() {
@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<QueryCancellor>() {
return execute(new SessionCallback<Cancellable>() {
@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<QueryCancellor>() {
return execute(new SessionCallback<Cancellable>() {
@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<QueryCancellor>() {
return execute(new SessionCallback<Cancellable>() {
@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<ResultSetFuture>() {
@@ -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<QueryCancellor>() {
return execute(new SessionCallback<Cancellable>() {
@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<QueryCancellor>() {
public Cancellable queryAsynchronously(final Select select, final Runnable listener, final Executor executor) {
return execute(new SessionCallback<Cancellable>() {
@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 <T> Cancellable queryForListAsynchronously(Select select, final Class<T> elementType,
final QueryForListListener<T> 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 <T> Cancellable queryForListAsynchronously(String select, final Class<T> elementType,
final QueryForListListener<T> 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<Map<String, Object>> 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<Map<String, Object>> listener) throws DataAccessException {
return queryForListOfMapAsynchronously(cql, listener, null);
}
@Override
public Cancellable queryForListOfMapAsynchronously(String cql,
final QueryForListListener<Map<String, Object>> 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 <T> Cancellable queryForObjectAsynchronously(Select select, final Class<T> requiredType,
final QueryForObjectListener<T> 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 <T> Cancellable queryForObjectAsynchronously(String cql, Class<T> requiredType,
QueryForObjectListener<T> listener) throws DataAccessException {
return queryForObjectAsynchronously(cql, requiredType, listener, null);
}
@Override
public <T> Cancellable queryForObjectAsynchronously(String cql, final Class<T> requiredType,
final QueryForObjectListener<T> 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 <T> Cancellable queryForObjectAsynchronously(String cql, RowMapper<T> rowMapper,
QueryForObjectListener<T> listener) throws DataAccessException {
return queryForObjectAsynchronously(cql, rowMapper, listener, null);
}
@Override
public <T> Cancellable queryForObjectAsynchronously(String cql, final RowMapper<T> rowMapper,
final QueryForObjectListener<T> 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 <T> Cancellable queryForObjectAsynchronously(Select select, final RowMapper<T> rowMapper,
final QueryForObjectListener<T> 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);
}
}
}

View File

@@ -21,7 +21,6 @@ import com.datastax.driver.core.exceptions.DriverException;
/**
* @author David Webb
*
*/
public interface PreparedStatementBinder {

View File

@@ -22,7 +22,6 @@ import com.datastax.driver.core.exceptions.DriverException;
/**
* @author David Webb
*
*/
public interface PreparedStatementCallback<T> {

View File

@@ -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 {

View File

@@ -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 <code>List&lt;T&gt;</code>.
*
* @author Matthew T. Adams
* @param <T>
*/
public interface QueryForListListener<T> {
/**
* Called upon query completion.
*/
void onQueryComplete(List<T> results);
/**
* Called if an exception is raised while getting or converting the {@link ResultSet}.
*/
void onException(Exception x);
}

View File

@@ -0,0 +1,10 @@
package org.springframework.cassandra.core;
import java.util.Map;
/**
* Listener used to receive asynchronous results expected as a <code>List&lt;T&gt;</code>.
*
* @author Matthew T. Adams
*/
public interface QueryForListOfMapListener extends QueryForListListener<Map<String, Object>> {}

View File

@@ -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 <code>List&lt;Map&lt;String,Object&gt;&gt;</code>.
*
* @author Matthew T. Adams
* @param <T>
*/
public interface QueryForMapListener {
/**
* Called upon query completion.
*/
void onQueryComplete(Map<String, Object> results);
/**
* Called if an exception is raised while getting or converting the {@link ResultSet}.
*/
void onException(Exception x);
}

View File

@@ -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 <code>T</code>.
*
* @author Matthew T. Adams
* @param <T>
*/
public interface QueryForObjectListener<T> {
/**
* 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);
}

View File

@@ -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.
*/

View File

@@ -8,11 +8,57 @@ import org.springframework.util.StringUtils;
*
* @see <a
* href="http://cassandra.apache.org/doc/cql3/CQL.html#appendixA">http://cassandra.apache.org/doc/cql3/CQL.html#appendixA</a>
*
* @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)

View File

@@ -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);
}
}

View File

@@ -19,7 +19,6 @@ package org.springframework.cassandra.core;
* Retry Policies associated with Cassandra.
*
* @author David Webb
*
*/
public enum RetryPolicy {

View File

@@ -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;

View File

@@ -21,7 +21,6 @@ import com.datastax.driver.core.Host;
/**
* @author David Webb
*
*/
public final class RingMember implements Serializable {

View File

@@ -27,7 +27,6 @@ import com.datastax.driver.core.exceptions.DriverException;
/**
* @author David Webb
* @param <T>
*
*/
public class RingMemberHostMapper implements HostMapper<RingMember> {

View File

@@ -15,10 +15,8 @@
*/
package org.springframework.cassandra.core;
/**
* @author David Webb
*
*/
public interface RowIterator {

View File

@@ -23,7 +23,6 @@ import com.datastax.driver.core.Session;
* Interface for operations on a Cassandra Session.
*
* @author David Webb
*
* @param <T>
*/
public interface SessionCallback<T> {

View File

@@ -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 {

View File

@@ -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.
*/

View File

@@ -24,7 +24,6 @@ import com.datastax.driver.core.ResultSet;
* {@link IllegalArgumentException}.
*
* @author Matthew T. Adams
*
* @param <T>
*/
public abstract class AbstractResultSetConverter<T> implements Converter<ResultSet, T> {

View File

@@ -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 <T>
*/
public abstract class AbstractResultSetToBasicFixedTypeConverter<T> extends AbstractResultSetConverter<T> {

View File

@@ -15,8 +15,7 @@ public class ResultSetToListConverter implements Converter<ResultSet, List<Map<S
protected Converter<Row, Map<String, Object>> rowConverter = new RowToMapConverter();
public ResultSetToListConverter() {
}
public ResultSetToListConverter() {}
public ResultSetToListConverter(Converter<Row, Map<String, Object>> rowConverter) {
setRowConverter(rowConverter);

View File

@@ -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);
}
}
}

View File

@@ -21,7 +21,6 @@ import com.datastax.driver.core.TableMetadata;
* @see #toCql()
* @see #toCql(StringBuilder)
* @see #toString()
*
* @author John McPeek
* @author Matthew T. Adams
*/

View File

@@ -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<KeyspaceIdentifier> {

View File

@@ -43,8 +43,8 @@ public class CreateIndexCqlGenerator extends IndexNameCqlGenerator<CreateIndexSp
cql.append("CREATE").append(spec().isCustom() ? " CUSTOM" : "").append(" INDEX ")
.append(spec().getIfNotExists() ? "IF NOT EXISTS " : "")
.append(spec().getName() == null ? "" : spec().getName()).append(" ON ")
.append(spec().getTableName()).append(" (").append(spec().getColumnName()).append(")");
.append(spec().getName() == null ? "" : spec().getName()).append(" ON ").append(spec().getTableName())
.append(" (").append(spec().getColumnName()).append(")");
if (spec().isCustom()) {
cql.append(" USING ").append(spec().getUsing());

View File

@@ -35,8 +35,7 @@ public class AlterKeyspaceSpecification extends KeyspaceOptionsSpecification<Alt
return new AlterKeyspaceSpecification(name);
}
public AlterKeyspaceSpecification() {
}
public AlterKeyspaceSpecification() {}
public AlterKeyspaceSpecification(String name) {
name(name);

View File

@@ -49,8 +49,7 @@ public class CreateKeyspaceSpecification extends KeyspaceSpecification<CreateKey
private boolean ifNotExists = false;
public CreateKeyspaceSpecification() {
}
public CreateKeyspaceSpecification() {}
public CreateKeyspaceSpecification(String name) {
name(name);

View File

@@ -96,13 +96,7 @@ public class DefaultOption implements Option {
}
ctor.newInstance(value.toString());
return true;
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException e) {
} catch (SecurityException e) {
}
} catch (InstantiationException e) {} catch (IllegalAccessException e) {} catch (IllegalArgumentException e) {} catch (InvocationTargetException e) {} catch (NoSuchMethodException e) {} catch (SecurityException e) {}
return false;
}

View File

@@ -45,8 +45,7 @@ public class DropKeyspaceSpecification extends KeyspaceActionSpecification<DropK
private boolean ifExists;
public DropKeyspaceSpecification() {
}
public DropKeyspaceSpecification() {}
public DropKeyspaceSpecification(String name) {
name(name);

View File

@@ -24,7 +24,6 @@ import org.springframework.util.Assert;
* Abstract builder class to support the construction of an index.
*
* @param <T> The subtype of the {@link IndexNameSpecification}
*
* @author David Webb
* @author Matthew T. Adams
*/

View File

@@ -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");

View File

@@ -23,5 +23,4 @@ package org.springframework.cassandra.core.keyspace;
* @author Matthew T. Adams
*/
public class KeyspaceSpecification<T> extends KeyspaceOptionsSpecification<KeyspaceSpecification<T>> implements
KeyspaceDescriptor {
}
KeyspaceDescriptor {}

View File

@@ -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

View File

@@ -39,4 +39,38 @@ public class CollectionUtils {
return list;
}
public static List<?> toList(Object thing) {
List<Object> list = new ArrayList<Object>();
list.add(thing);
return list;
}
public static List<?> toList(Object thing1, Object thing2) {
List<Object> list = new ArrayList<Object>();
list.add(thing1);
list.add(thing2);
return list;
}
public static List<?> toList(Object thing1, Object thing2, Object thing3) {
List<Object> list = new ArrayList<Object>();
list.add(thing1);
list.add(thing2);
list.add(thing3);
return list;
}
public static List<?> toList(Object thing1, Object thing2, Object thing3, Object... rest) {
List<Object> list = new ArrayList<Object>();
list.add(thing1);
list.add(thing2);
list.add(thing3);
if (rest != null) {
for (Object thing : rest) {
list.add(thing);
}
}
return list;
}
}

View File

@@ -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);
}
}

View File

@@ -23,7 +23,6 @@ import com.datastax.driver.core.Host.StateListener;
/**
* @author David Webb
*
*/
public class TestHostStateListener implements StateListener {

View File

@@ -23,7 +23,6 @@ import com.datastax.driver.core.LatencyTracker;
/**
* @author David Webb
*
*/
public class TestLatencyTracker implements LatencyTracker {

View File

@@ -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";

View File

@@ -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<String, Object>) expected, (Map<String, String>) actual);
return;
case COMPACTION:
assertCompaction((Map<String, Object>) expected, (Map<String, String>) actual);
return;
case COMPRESSION:
assertCompression((Map<String, Object>) expected, (Map<String, String>) actual);
return;
case COMPRESSION:
assertCompression((Map<String, Object>) expected, (Map<String, String>) actual);
return;
}
log.info(actual.getClass().getName());
@@ -137,26 +137,26 @@ public class CqlTableSpecificationAssertions {
@SuppressWarnings("unchecked")
public static <T> 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;
}

View File

@@ -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 <T> The concrete unit test class to which this integration test corresponds.
*/
public static abstract class Base<T extends CreateIndexTest> extends AbstractKeyspaceCreatingIntegrationTest {

View File

@@ -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 <T> The concrete unit test class to which this integration test corresponds.
*/
public static abstract class Base<T extends CreateTableTest> extends AbstractKeyspaceCreatingIntegrationTest {

View File

@@ -39,4 +39,4 @@ public class FunkyIdentifierIntegrationTest extends AbstractKeyspaceCreatingInte
.partitionKeyColumn(name, DataType.text())).toCql());
}
}
}
}

View File

@@ -19,7 +19,6 @@ package org.springframework.cassandra.test.integration.core.template;
* Test POJO
*
* @author David Webb
*
*/
public class Book {

View File

@@ -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");
}
/**

View File

@@ -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<String, Object> 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<String, Object> 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<String> 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<String> 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<Map<String, Object>> 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<Map<String, Object>> 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();

View File

@@ -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 {}

View File

@@ -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> BOOK_COMPARATOR = new Comparator<Book>() {
@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 <code>this.expected</code>
* 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<T> {
/**
* Subclass must perform the asynchronous query using the given data and listener and set <code>this.expected</code>
* to the appropriate value before returning.
*/
abstract void doAsyncQuery(Book b, QueryForObjectListener<T> listener);
T expected; // subclass should set this value in doAsyncQuery
void test() throws Exception {
Book book = insert(1)[0];
ObjectListener<T> listener = new ObjectListener<T>();
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 <code>this.expected</code>
* to the appropriate value before returning.
*/
abstract void doAsyncQuery(Book b, QueryForMapListener listener);
Map<String, Object> 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 <code>this.expected</code>
* to the appropriate value before returning.
*/
abstract void doAsyncQuery(Book[] books, QueryForListOfMapListener listener);
List<Map<String, Object>> 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<String>() {
@Override
void doAsyncQuery(Book b, QueryForObjectListener<String> 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<String>() {
@Override
void doAsyncQuery(Book b, QueryForObjectListener<String> 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<String, Object>();
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<String, Object>();
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<Map<String, Object>>(books.length);
for (int i = 0; i < books.length; i++) {
Book b = books[i];
titles[i] = b.title;
HashMap<String, Object> row = new HashMap<String, Object>(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<Map<String, Object>>(books.length);
for (int i = 0; i < books.length; i++) {
Book b = books[i];
titles[i] = b.title;
HashMap<String, Object> row = new HashMap<String, Object>(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);
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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<T> extends TestListener implements QueryForListListener<T> {
Exception exception;
List<T> result;
@Override
public void onQueryComplete(List<T> results) {
countDown();
this.result = results;
}
@Override
public void onException(Exception x) {
countDown();
this.exception = x;
}
}

View File

@@ -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<Map<String, Object>> implements QueryForListOfMapListener {}

View File

@@ -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<String, Object> result;
Exception exception;
@Override
public void onQueryComplete(Map<String, Object> results) {
countDown();
this.result = results;
}
@Override
public void onException(Exception x) {
countDown();
this.exception = x;
}
}

View File

@@ -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<T> extends TestListener implements QueryForObjectListener<T> {
T result;
Exception exception;
@Override
public void onQueryComplete(T result) {
countDown();
this.result = result;
}
@Override
public void onException(Exception x) {
countDown();
this.exception = x;
}
}

View File

@@ -15,6 +15,4 @@
*/
package org.springframework.cassandra.test.unit.core.cql;
public class CqlStringUtilsTest {
}
public class CqlStringUtilsTest {}

View File

@@ -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<AlterKeyspaceSpecification, AlterKeyspaceCqlGenerator> {
}
KeyspaceOperationCqlGeneratorTest<AlterKeyspaceSpecification, AlterKeyspaceCqlGenerator> {}
public static class CompleteTest extends AlterKeyspaceTest {

View File

@@ -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<AlterTableSpecification, AlterTableCqlGenerator> {
}
TableOperationCqlGeneratorTest<AlterTableSpecification, AlterTableCqlGenerator> {}
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 {

View File

@@ -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 {

View File

@@ -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<DropIndexSpecification, DropIndexCqlGenerator> {
}
IndexOperationCqlGeneratorTest<DropIndexSpecification, DropIndexCqlGenerator> {}
public static class BasicTest extends DropIndexTest {

View File

@@ -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<DropKeyspaceSpecification, DropKeyspaceCqlGenerator> {
}
KeyspaceOperationCqlGeneratorTest<DropKeyspaceSpecification, DropKeyspaceCqlGenerator> {}
public static class BasicTest extends DropTableTest {

View File

@@ -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<DropTableSpecification, DropTableCqlGenerator> {
}
TableOperationCqlGeneratorTest<DropTableSpecification, DropTableCqlGenerator> {}
public static class BasicTest extends DropTableTest {

View File

@@ -26,7 +26,6 @@ import org.springframework.cassandra.core.keyspace.IndexNameSpecification;
*
* @author Matthew T. Adams
* @author David Webb
*
* @param <S> The type of the {@link IndexNameSpecification}
* @param <G> The type of the {@link IndexNameCqlGenerator}
*/

View File

@@ -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 <S> The type of the {@link TableNameSpecification}
* @param <G> The type of the {@link TableNameCqlGenerator}
*/

View File

@@ -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 <S> The type of the {@link TableNameSpecification}
* @param <G> The type of the {@link TableNameCqlGenerator}
*/

View File

@@ -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();
}
}