DATACASS-389 - Reformat and reorganize imports.
This commit is contained in:
@@ -70,8 +70,8 @@ public class CassandraCqlTemplateFactoryBean implements FactoryBean<CqlTemplate>
|
||||
|
||||
/**
|
||||
* Sets the Cassandra {@link Session} to use. The {@link CqlTemplate} will use the logged keyspace of the underlying
|
||||
* {@link Session}. Don't change the keyspace using CQL but use multiple {@link Session} and
|
||||
* {@link CqlTemplate} beans.
|
||||
* {@link Session}. Don't change the keyspace using CQL but use multiple {@link Session} and {@link CqlTemplate}
|
||||
* beans.
|
||||
*
|
||||
* @param session must not be {@literal null}.
|
||||
*/
|
||||
|
||||
@@ -19,8 +19,7 @@ package org.springframework.cassandra.config;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
|
||||
/**
|
||||
* Configuration callback class to allow a user to apply additional configuration logic
|
||||
* to the {@link Cluster.Builder}.
|
||||
* Configuration callback class to allow a user to apply additional configuration logic to the {@link Cluster.Builder}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see com.datastax.driver.core.Cluster
|
||||
|
||||
@@ -50,8 +50,7 @@ public class KeyspaceAttributes {
|
||||
* replication strategy class "SimpleStrategy" and with a replication factor equal to that given.
|
||||
*/
|
||||
public static Map<Option, Object> newSimpleReplication(long replicationFactor) {
|
||||
return MapBuilder
|
||||
.map(Option.class, Object.class)
|
||||
return MapBuilder.map(Option.class, Object.class)
|
||||
.entry(new DefaultOption("class", String.class, true, false, true),
|
||||
ReplicationStrategy.SIMPLE_STRATEGY.getValue())
|
||||
.entry(new DefaultOption("replication_factor", Long.class, true, false, false), replicationFactor).build();
|
||||
|
||||
@@ -167,7 +167,7 @@ public abstract class ParsingUtils {
|
||||
* {@link #addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
*/
|
||||
public static void addRequiredPropertyReference(BeanDefinitionBuilder builder, String propertyName, Element element,
|
||||
String attributeName) {
|
||||
String attributeName) {
|
||||
|
||||
addProperty(builder, propertyName, element.getAttribute(attributeName), null, true, true);
|
||||
}
|
||||
@@ -232,8 +232,8 @@ public abstract class ParsingUtils {
|
||||
* @see BeanDefinitionBuilder#addPropertyReference(String, String)
|
||||
* @see BeanDefinitionBuilder#addPropertyValue(String, Object)
|
||||
*/
|
||||
public static BeanDefinitionBuilder addProperty(BeanDefinitionBuilder builder, String propertyName,
|
||||
String value, String defaultValue, boolean required, boolean reference) {
|
||||
public static BeanDefinitionBuilder addProperty(BeanDefinitionBuilder builder, String propertyName, String value,
|
||||
String defaultValue, boolean required, boolean reference) {
|
||||
|
||||
Assert.notNull(builder, "BeanDefinitionBuilder must not be null");
|
||||
Assert.hasText(propertyName, "Property name must not be null");
|
||||
@@ -241,9 +241,8 @@ public abstract class ParsingUtils {
|
||||
if (!StringUtils.hasText(value)) {
|
||||
if (required) {
|
||||
throw new IllegalArgumentException(String.format("value required for property %1$s[%2$s] on class [%3$s]",
|
||||
reference ? "reference " : "", propertyName, builder.getRawBeanDefinition().getBeanClassName()));
|
||||
}
|
||||
else {
|
||||
reference ? "reference " : "", propertyName, builder.getRawBeanDefinition().getBeanClassName()));
|
||||
} else {
|
||||
value = defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -260,13 +259,13 @@ public abstract class ParsingUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link BeanDefinition} built from the given {@link BeanDefinitionBuilder} enriched with
|
||||
* source meta-data derived from the given {@link Element}.
|
||||
* Returns a {@link BeanDefinition} built from the given {@link BeanDefinitionBuilder} enriched with source meta-data
|
||||
* derived from the given {@link Element}.
|
||||
*
|
||||
* @param builder {@link BeanDefinitionBuilder} used to build the {@link BeanDefinition}.
|
||||
* @param parserContext {@link ParserContext} used to track state during the parsing operation.
|
||||
* @param element DOM {@link Element} defining the meta-data that is the source of the {@link BeanDefinition}s
|
||||
* configuration.
|
||||
* configuration.
|
||||
* @return the {@link BeanDefinition} built by the given {@link BeanDefinitionBuilder}.
|
||||
* @throws IllegalArgumentException if the {@link BeanDefinitionBuilder} or {@link ParserContext} are null.
|
||||
*/
|
||||
|
||||
@@ -15,24 +15,24 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Statement;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Statement;
|
||||
|
||||
/**
|
||||
* Interface specifying a basic set of CQL asynchronously executed operations. Exposes similar methods
|
||||
* as {@link CqlTemplate}, but returns result handles or accepts callbacks as opposed to concrete results.
|
||||
* Implemented by {@link AsyncCqlTemplate}. Not often used directly, but a useful option to enhance testability,
|
||||
* as it can easily be mocked or stubbed.
|
||||
* Interface specifying a basic set of CQL asynchronously executed operations. Exposes similar methods as
|
||||
* {@link CqlTemplate}, but returns result handles or accepts callbacks as opposed to concrete results. Implemented by
|
||||
* {@link AsyncCqlTemplate}. Not often used directly, but a useful option to enhance testability, as it can easily be
|
||||
* mocked or stubbed.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
@@ -42,7 +42,8 @@ import reactor.core.publisher.Mono;
|
||||
*/
|
||||
public interface AsyncCqlOperations {
|
||||
|
||||
// TODO many of these data access operations could be implemented as default methods, in terms of other data access operations
|
||||
// TODO many of these data access operations could be implemented as default methods, in terms of other data access
|
||||
// operations
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods dealing with a plain com.datastax.driver.core.Session
|
||||
@@ -93,13 +94,14 @@ public interface AsyncCqlOperations {
|
||||
* {@link PreparedStatementBinder} just needs to set parameters.
|
||||
*
|
||||
* @param cql static CQL to execute, must not be empty or {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @return boolean value whether the statement was applied.
|
||||
* @throws DataAccessException if there is any problem issuing the execution.
|
||||
*/
|
||||
ListenableFuture<Boolean> execute(String cql, PreparedStatementBinder preparedStatementBinder) throws DataAccessException;
|
||||
ListenableFuture<Boolean> execute(String cql, PreparedStatementBinder preparedStatementBinder)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a CQL data access operation, implemented as callback action working on a CQL {@link PreparedStatement}.
|
||||
@@ -170,7 +172,8 @@ public interface AsyncCqlOperations {
|
||||
* @return an arbitrary result object, as returned by the {@link ResultSetExtractor}
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
<T> ListenableFuture<T> query(String cql, ResultSetExtractor<T> resultSetExtractor, Object... args) throws DataAccessException;
|
||||
<T> ListenableFuture<T> query(String cql, ResultSetExtractor<T> resultSetExtractor, Object... args)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, reading the
|
||||
@@ -182,7 +185,8 @@ public interface AsyncCqlOperations {
|
||||
* CQL type)
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
ListenableFuture<Void> query(String cql, RowCallbackHandler rowCallbackHandler, Object... args) throws DataAccessException;
|
||||
ListenableFuture<Void> query(String cql, RowCallbackHandler rowCallbackHandler, Object... args)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given CQL to create a prepared statement from CQL and a list of arguments to bind to the query, mapping each
|
||||
@@ -201,15 +205,15 @@ public interface AsyncCqlOperations {
|
||||
* Query using a prepared statement, reading the {@link ResultSet} with a {@link ResultSetExtractor}.
|
||||
*
|
||||
* @param cql static CQL to execute, must not be empty or {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param resultSetExtractor object that will extract results, must not be {@literal null}.
|
||||
* @return an arbitrary result object, as returned by the {@link ResultSetExtractor}.
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
<T> ListenableFuture<T> query(String cql, PreparedStatementBinder preparedStatementBinder, ResultSetExtractor<T> resultSetExtractor)
|
||||
throws DataAccessException;
|
||||
<T> ListenableFuture<T> query(String cql, PreparedStatementBinder preparedStatementBinder,
|
||||
ResultSetExtractor<T> resultSetExtractor) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given CQL to create a prepared statement from CQL and a {@link PreparedStatementBinder} implementation that
|
||||
@@ -217,29 +221,29 @@ public interface AsyncCqlOperations {
|
||||
* {@link RowCallbackHandler}.
|
||||
*
|
||||
* @param cql static CQL to execute, must not be empty or {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param rowCallbackHandler object that will extract results, one row at a time, must not be {@literal null}.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
ListenableFuture<Void> query(String cql, PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler)
|
||||
throws DataAccessException;
|
||||
ListenableFuture<Void> query(String cql, PreparedStatementBinder preparedStatementBinder,
|
||||
RowCallbackHandler rowCallbackHandler) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given CQL to create a prepared statement from CQL and a {@link PreparedStatementBinder} implementation that
|
||||
* knows how to bind values to the query, mapping each row to a Java object via a {@link RowMapper}.
|
||||
*
|
||||
* @param cql static CQL to execute, must not be empty or {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param rowMapper object that will map one object per row, must not be {@literal null}.
|
||||
* @return the result {@link List}, containing mapped objects.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
<T> ListenableFuture<List<T>> query(String cql, PreparedStatementBinder preparedStatementBinder, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
<T> ListenableFuture<List<T>> query(String cql, PreparedStatementBinder preparedStatementBinder,
|
||||
RowMapper<T> rowMapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query for a result {@link List}, given static CQL.
|
||||
@@ -311,7 +315,8 @@ public interface AsyncCqlOperations {
|
||||
* @see #queryForList(String, Class)
|
||||
* @see SingleColumnRowMapper
|
||||
*/
|
||||
<T> ListenableFuture<List<T>> queryForList(String cql, Class<T> elementType, Object... args) throws DataAccessException;
|
||||
<T> ListenableFuture<List<T>> queryForList(String cql, Class<T> elementType, Object... args)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query for a result Map, given static CQL.
|
||||
@@ -476,7 +481,8 @@ public interface AsyncCqlOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
* @see #query(String, ResultSetExtractor, Object...)
|
||||
*/
|
||||
<T> ListenableFuture<T> query(Statement statement, ResultSetExtractor<T> resultSetExtractor) throws DataAccessException;
|
||||
<T> ListenableFuture<T> query(Statement statement, ResultSetExtractor<T> resultSetExtractor)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query given static CQL, reading the {@link ResultSet} on a per-row basis with a
|
||||
@@ -636,44 +642,44 @@ public interface AsyncCqlOperations {
|
||||
* <p>
|
||||
* The callback action can return a result object, for example a domain object or a collection of domain objects.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param action callback object that specifies the action, must not be {@literal null}.
|
||||
* @return a result object returned by the action, or {@literal null}.
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
<T> ListenableFuture<T> execute(AsyncPreparedStatementCreator preparedStatementCreator, PreparedStatementCallback<T> action)
|
||||
throws DataAccessException;
|
||||
<T> ListenableFuture<T> execute(AsyncPreparedStatementCreator preparedStatementCreator,
|
||||
PreparedStatementCallback<T> action) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement, reading the {@link ResultSet} with a {@link ResultSetExtractor}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param resultSetExtractor object that will extract results, must not be {@literal null}.
|
||||
* @return an arbitrary result object, as returned by the {@link ResultSetExtractor}
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
<T> ListenableFuture<T> query(AsyncPreparedStatementCreator preparedStatementCreator, ResultSetExtractor<T> resultSetExtractor)
|
||||
throws DataAccessException;
|
||||
<T> ListenableFuture<T> query(AsyncPreparedStatementCreator preparedStatementCreator,
|
||||
ResultSetExtractor<T> resultSetExtractor) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement, reading the {@link ResultSet} on a per-row basis with a
|
||||
* {@link RowCallbackHandler}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param rowCallbackHandler object that will extract results, one row at a time, must not be {@literal null}.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
ListenableFuture<Void> query(AsyncPreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler)
|
||||
throws DataAccessException;
|
||||
ListenableFuture<Void> query(AsyncPreparedStatementCreator preparedStatementCreator,
|
||||
RowCallbackHandler rowCallbackHandler) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement, mapping each row to a Java object via a {@link RowMapper}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param rowMapper object that will map one object per row, must not be {@literal null}.
|
||||
* @return the result {@link List}, containing mapped objects.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
@@ -685,47 +691,49 @@ public interface AsyncCqlOperations {
|
||||
* Query using a prepared statement and a {@link PreparedStatementBinder} implementation that knows how to bind values
|
||||
* to the query, reading the {@link ResultSet} with a {@link ResultSetExtractor}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param resultSetExtractor object that will extract results, must not be {@literal null}.
|
||||
* @return an arbitrary result object, as returned by the {@link ResultSetExtractor}.
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
<T> ListenableFuture<T> query(AsyncPreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder,
|
||||
ResultSetExtractor<T> resultSetExtractor) throws DataAccessException;
|
||||
<T> ListenableFuture<T> query(AsyncPreparedStatementCreator preparedStatementCreator,
|
||||
PreparedStatementBinder preparedStatementBinder, ResultSetExtractor<T> resultSetExtractor)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement and a {@link PreparedStatementBinder} implementation that knows how to bind values
|
||||
* to the query, reading the {@link ResultSet} on a per-row basis with a {@link RowCallbackHandler}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param rowCallbackHandler object that will extract results, one row at a time, must not be {@literal null}.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
ListenableFuture<Void> query(AsyncPreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder,
|
||||
RowCallbackHandler rowCallbackHandler) throws DataAccessException;
|
||||
ListenableFuture<Void> query(AsyncPreparedStatementCreator preparedStatementCreator,
|
||||
PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement and a {@link PreparedStatementBinder} implementation that knows how to bind values
|
||||
* to the query, mapping each row to a Java object via a {@link RowMapper}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param rowMapper object that will map one object per row, must not be {@literal null}.
|
||||
* @return the result {@link List}, containing mapped objects.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
<T> ListenableFuture<List<T>> query(AsyncPreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder,
|
||||
RowMapper<T> rowMapper) throws DataAccessException;
|
||||
<T> ListenableFuture<List<T>> query(AsyncPreparedStatementCreator preparedStatementCreator,
|
||||
PreparedStatementBinder preparedStatementBinder, RowMapper<T> rowMapper) throws DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -80,8 +80,8 @@ import com.google.common.util.concurrent.Futures;
|
||||
public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOperations {
|
||||
|
||||
/**
|
||||
* Create a new, uninitialized {@link AsyncCqlTemplate}. Note: The {@link SessionFactory} has to be set before
|
||||
* using the instance.
|
||||
* Create a new, uninitialized {@link AsyncCqlTemplate}. Note: The {@link SessionFactory} has to be set before using
|
||||
* the instance.
|
||||
*
|
||||
* @see #setSessionFactory(SessionFactory)
|
||||
*/
|
||||
@@ -172,8 +172,7 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ResultSetFuture results = getCurrentSession().executeAsync(simpleStatement);
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
new GuavaListenableFutureAdapter<>(results,
|
||||
ex -> translateExceptionIfPossible("Query", cql, ex)),
|
||||
new GuavaListenableFutureAdapter<>(results, ex -> translateExceptionIfPossible("Query", cql, ex)),
|
||||
resultSetExtractor::extractData), getExceptionTranslator());
|
||||
} catch (DriverException e) {
|
||||
throw translateException("Query", cql, e);
|
||||
@@ -189,8 +188,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
|
||||
ListenableFuture<?> results = query(cql, newResultSetExtractor(rowCallbackHandler));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(results, o -> null), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(results, o -> null),
|
||||
getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -248,8 +247,7 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<List<T>> results = query(cql, newResultSetExtractor(rowMapper));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult),
|
||||
getExceptionTranslator());
|
||||
new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -316,8 +314,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
|
||||
ListenableFuture<?> result = query(statement, newResultSetExtractor(rowCallbackHandler));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(result, o -> null), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(result, o -> null),
|
||||
getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -377,8 +375,7 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<List<T>> results = query(statement, newResultSetExtractor(rowMapper));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult),
|
||||
getExceptionTranslator());
|
||||
new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -450,15 +447,15 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
logger.debug("Preparing statement [{}] using {}", toCql(preparedStatementCreator), preparedStatementCreator);
|
||||
}
|
||||
|
||||
Session currentSession = getCurrentSession();return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(preparedStatementCreator.createPreparedStatement(currentSession),
|
||||
preparedStatement -> {
|
||||
try {
|
||||
return action.doInPreparedStatement(currentSession,applyStatementSettings(preparedStatement));
|
||||
} catch (DriverException e) {
|
||||
throw translateException("PreparedStatementCallback", preparedStatement.toString(), e);
|
||||
}
|
||||
}), getExceptionTranslator());
|
||||
Session currentSession = getCurrentSession();
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
preparedStatementCreator.createPreparedStatement(currentSession), preparedStatement -> {
|
||||
try {
|
||||
return action.doInPreparedStatement(currentSession, applyStatementSettings(preparedStatement));
|
||||
} catch (DriverException e) {
|
||||
throw translateException("PreparedStatementCallback", preparedStatement.toString(), e);
|
||||
}
|
||||
}), getExceptionTranslator());
|
||||
|
||||
} catch (DriverException e) {
|
||||
throw translateException("PreparedStatementCallback", toCql(preparedStatementCreator), e);
|
||||
@@ -484,11 +481,10 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
public ListenableFuture<Void> query(AsyncPreparedStatementCreator preparedStatementCreator,
|
||||
RowCallbackHandler rowCallbackHandler) throws DataAccessException {
|
||||
|
||||
ListenableFuture<?> results = query(preparedStatementCreator, null,
|
||||
newResultSetExtractor(rowCallbackHandler));
|
||||
ListenableFuture<?> results = query(preparedStatementCreator, null, newResultSetExtractor(rowCallbackHandler));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(results, o -> null), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(results, o -> null),
|
||||
getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -516,14 +512,13 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
|
||||
try {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Preparing statement [{}] using {}", toCql(preparedStatementCreator),
|
||||
preparedStatementCreator);
|
||||
logger.debug("Preparing statement [{}] using {}", toCql(preparedStatementCreator), preparedStatementCreator);
|
||||
}
|
||||
|
||||
Session session = getCurrentSession();
|
||||
|
||||
PersistenceExceptionTranslator exceptionTranslator = ex ->
|
||||
translateExceptionIfPossible("Query", toCql(preparedStatementCreator), ex);
|
||||
PersistenceExceptionTranslator exceptionTranslator = ex -> translateExceptionIfPossible("Query",
|
||||
toCql(preparedStatementCreator), ex);
|
||||
|
||||
ListenableFuture<BoundStatement> statementFuture = new MappingListenableFutureAdapter<>(
|
||||
preparedStatementCreator.createPreparedStatement(session), preparedStatement -> {
|
||||
@@ -537,31 +532,30 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
|
||||
SettableListenableFuture<T> settableListenableFuture = new SettableListenableFuture<>();
|
||||
|
||||
statementFuture.addCallback(boundStatement ->
|
||||
Futures.addCallback(session.executeAsync(boundStatement), new FutureCallback<ResultSet>() {
|
||||
statementFuture.addCallback(
|
||||
boundStatement -> Futures.addCallback(session.executeAsync(boundStatement), new FutureCallback<ResultSet>() {
|
||||
@Override
|
||||
public void onSuccess(ResultSet result) {
|
||||
try {
|
||||
settableListenableFuture.set(resultSetExtractor.extractData(result));
|
||||
} catch (DriverException e) {
|
||||
settableListenableFuture.setException(
|
||||
exceptionTranslator.translateExceptionIfPossible(e));
|
||||
settableListenableFuture.setException(exceptionTranslator.translateExceptionIfPossible(e));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable ex) {
|
||||
if (ex instanceof DriverException) {
|
||||
settableListenableFuture.setException(
|
||||
exceptionTranslator.translateExceptionIfPossible((DriverException) ex));
|
||||
settableListenableFuture
|
||||
.setException(exceptionTranslator.translateExceptionIfPossible((DriverException) ex));
|
||||
} else {
|
||||
settableListenableFuture.setException(ex);
|
||||
}
|
||||
}
|
||||
}), ex -> {
|
||||
if (ex instanceof DriverException) {
|
||||
settableListenableFuture.setException(
|
||||
exceptionTranslator.translateExceptionIfPossible((DriverException) ex));
|
||||
settableListenableFuture
|
||||
.setException(exceptionTranslator.translateExceptionIfPossible((DriverException) ex));
|
||||
} else {
|
||||
settableListenableFuture.setException(ex);
|
||||
}
|
||||
@@ -586,8 +580,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<?> results = query(preparedStatementCreator, preparedStatementBinder,
|
||||
newResultSetExtractor(rowCallbackHandler));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
results, o -> null), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(results, o -> null),
|
||||
getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -623,8 +617,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<?> results = query(newAsyncPreparedStatementCreator(cql), newPreparedStatementBinder(args),
|
||||
newResultSetExtractor(rowCallbackHandler));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
results, o -> null), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(results, o -> null),
|
||||
getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -661,8 +655,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<?> results = query(newAsyncPreparedStatementCreator(cql), preparedStatementBinder,
|
||||
newResultSetExtractor(rowCallbackHandler));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
results, o -> null), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(results, o -> null),
|
||||
getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -731,8 +725,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<List<T>> results = query(newAsyncPreparedStatementCreator(cql), newPreparedStatementBinder(args),
|
||||
newResultSetExtractor(rowMapper, 1));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
results, DataAccessUtils::requiredSingleResult), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -815,8 +809,7 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
@Override
|
||||
public ListenableFuture<PreparedStatement> createPreparedStatement(Session session) throws DriverException {
|
||||
|
||||
return new GuavaListenableFutureAdapter<>(session.prepareAsync(getCql()),
|
||||
this.persistenceExceptionTranslator);
|
||||
return new GuavaListenableFutureAdapter<>(session.prepareAsync(getCql()), this.persistenceExceptionTranslator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* One of the two central callback interfaces used by the {@link AsyncCqlTemplate} class. This interface prepares a CQL
|
||||
* statement returning a {@link org.springframework.util.concurrent.ListenableFuture} given a {@link Session}, provided
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
|
||||
/**
|
||||
* Generic callback interface for code that operates asynchronously on a Cassandra {@link Session}. Allows to execute any number of
|
||||
* operations on a single session, using any type and number of statements.
|
||||
* Generic callback interface for code that operates asynchronously on a Cassandra {@link Session}. Allows to execute
|
||||
* any number of operations on a single session, using any type and number of statements.
|
||||
* <p>
|
||||
* This is particularly useful for delegating to existing data access code that expects a {@link Session} to work on and
|
||||
* throws {@link DriverException}. For newly written code, it is strongly recommended to use {@link CqlTemplate}'s more
|
||||
|
||||
@@ -115,8 +115,7 @@ public class CachedPreparedStatementCreator implements PreparedStatementCreator
|
||||
if (sessionCache.containsKey(cacheKey)) {
|
||||
log.debug("Found cached PreparedStatement");
|
||||
preparedStatement = sessionCache.get(cacheKey);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
log.debug("No cached PreparedStatement found... creating and caching");
|
||||
preparedStatement = session.prepare(this.cql);
|
||||
sessionCache.put(cacheKey, preparedStatement);
|
||||
|
||||
@@ -30,17 +30,20 @@ public enum ConsistencyLevel {
|
||||
/**
|
||||
* @deprecated as of 1.5, use {@link #QUORUM}
|
||||
*/
|
||||
@Deprecated QUOROM,
|
||||
@Deprecated
|
||||
QUOROM,
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5, use {@link #LOCAL_QUORUM}
|
||||
*/
|
||||
@Deprecated LOCAL_QUOROM,
|
||||
@Deprecated
|
||||
LOCAL_QUOROM,
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5, use {@link #EACH_QUORUM}
|
||||
*/
|
||||
@Deprecated EACH_QUOROM,
|
||||
@Deprecated
|
||||
EACH_QUOROM,
|
||||
|
||||
ALL, LOCAL_ONE, SERIAL, LOCAL_SERIAL,
|
||||
|
||||
|
||||
@@ -15,20 +15,20 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.datastax.driver.core.Statement;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Interface specifying a basic set of CQL operations. Implemented by {@link CqlTemplate}. Not often used directly, but
|
||||
* a useful option to enhance testability, as it can easily be mocked or stubbed.
|
||||
@@ -196,14 +196,15 @@ public interface CqlOperations {
|
||||
* Query using a prepared statement, reading the {@link ResultSet} with a {@link ResultSetExtractor}.
|
||||
*
|
||||
* @param cql static CQL to execute, must not be empty or {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param resultSetExtractor object that will extract results, must not be {@literal null}.
|
||||
* @return an arbitrary result object, as returned by the {@link ResultSetExtractor}.
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
<T> T query(String cql, PreparedStatementBinder preparedStatementBinder, ResultSetExtractor<T> resultSetExtractor) throws DataAccessException;
|
||||
<T> T query(String cql, PreparedStatementBinder preparedStatementBinder, ResultSetExtractor<T> resultSetExtractor)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given CQL to create a prepared statement from CQL and a {@link PreparedStatementBinder} implementation that
|
||||
@@ -211,27 +212,29 @@ public interface CqlOperations {
|
||||
* {@link RowCallbackHandler}.
|
||||
*
|
||||
* @param cql static CQL to execute, must not be empty or {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param rowCallbackHandler object that will extract results, one row at a time, must not be {@literal null}.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
void query(String cql, PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler) throws DataAccessException;
|
||||
void query(String cql, PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query given CQL to create a prepared statement from CQL and a {@link PreparedStatementBinder} implementation that
|
||||
* knows how to bind values to the query, mapping each row to a Java object via a {@link RowMapper}.
|
||||
*
|
||||
* @param cql static CQL to execute, must not be empty or {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param rowMapper object that will map one object per row, must not be {@literal null}.
|
||||
* @return the result {@link List}, containing mapped objects.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
<T> List<T> query(String cql, PreparedStatementBinder preparedStatementBinder, RowMapper<T> rowMapper) throws DataAccessException;
|
||||
<T> List<T> query(String cql, PreparedStatementBinder preparedStatementBinder, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a query for a result {@link List}, given static CQL.
|
||||
@@ -675,56 +678,60 @@ public interface CqlOperations {
|
||||
* <p>
|
||||
* The callback action can return a result object, for example a domain object or a collection of domain objects.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param action callback object that specifies the action, must not be {@literal null}.
|
||||
* @return a result object returned by the action, or {@literal null}.
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
<T> T execute(PreparedStatementCreator preparedStatementCreator, PreparedStatementCallback<T> action) throws DataAccessException;
|
||||
<T> T execute(PreparedStatementCreator preparedStatementCreator, PreparedStatementCallback<T> action)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement, reading the {@link ResultSet} with a {@link ResultSetExtractor}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param resultSetExtractor object that will extract results, must not be {@literal null}.
|
||||
* @return an arbitrary result object, as returned by the {@link ResultSetExtractor}
|
||||
* @throws DataAccessException if there is any problem
|
||||
*/
|
||||
<T> T query(PreparedStatementCreator preparedStatementCreator, ResultSetExtractor<T> resultSetExtractor) throws DataAccessException;
|
||||
<T> T query(PreparedStatementCreator preparedStatementCreator, ResultSetExtractor<T> resultSetExtractor)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement, reading the {@link ResultSet} on a per-row basis with a
|
||||
* {@link RowCallbackHandler}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param rowCallbackHandler object that will extract results, one row at a time, must not be {@literal null}.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
void query(PreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler) throws DataAccessException;
|
||||
void query(PreparedStatementCreator preparedStatementCreator, RowCallbackHandler rowCallbackHandler)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement, mapping each row to a Java object via a {@link RowMapper}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param rowMapper object that will map one object per row, must not be {@literal null}.
|
||||
* @return the result {@link List}, containing mapped objects.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
<T> List<T> query(PreparedStatementCreator preparedStatementCreator, RowMapper<T> rowMapper) throws DataAccessException;
|
||||
<T> List<T> query(PreparedStatementCreator preparedStatementCreator, RowMapper<T> rowMapper)
|
||||
throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Query using a prepared statement and a {@link PreparedStatementBinder} implementation that knows how to bind values
|
||||
* to the query, reading the {@link ResultSet} with a {@link ResultSetExtractor}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param resultSetExtractor object that will extract results, must not be {@literal null}.
|
||||
* @return an arbitrary result object, as returned by the {@link ResultSetExtractor}.
|
||||
* @throws DataAccessException if there is any problem
|
||||
@@ -736,11 +743,11 @@ public interface CqlOperations {
|
||||
* Query using a prepared statement and a {@link PreparedStatementBinder} implementation that knows how to bind values
|
||||
* to the query, reading the {@link ResultSet} on a per-row basis with a {@link RowCallbackHandler}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param rowCallbackHandler object that will extract results, one row at a time, must not be {@literal null}.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
@@ -751,11 +758,11 @@ public interface CqlOperations {
|
||||
* Query using a prepared statement and a {@link PreparedStatementBinder} implementation that knows how to bind values
|
||||
* to the query, mapping each row to a Java object via a {@link RowMapper}.
|
||||
*
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a {@link com.datastax.driver.core.Session},
|
||||
* must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is {@literal null}, the CQL will
|
||||
* be assumed to contain no bind parameters. Even if there are no bind parameters, this object may be used to
|
||||
* set fetch size and other performance options.
|
||||
* @param preparedStatementCreator object that can create a {@link PreparedStatement} given a
|
||||
* {@link com.datastax.driver.core.Session}, must not be {@literal null}.
|
||||
* @param preparedStatementBinder object that knows how to set values on the prepared statement. If this is
|
||||
* {@literal null}, the CQL will be assumed to contain no bind parameters. Even if there are no bind
|
||||
* parameters, this object may be used to set fetch size and other performance options.
|
||||
* @param rowMapper object that will map one object per row, must not be {@literal null}.
|
||||
* @return the result {@link List}, containing mapped objects.
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
|
||||
@@ -80,8 +80,8 @@ import com.datastax.driver.core.exceptions.DriverException;
|
||||
public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
|
||||
/**
|
||||
* Create a new, uninitialized {@link CqlTemplate}. Note: The {@link SessionFactory} has to be set before using
|
||||
* the instance.
|
||||
* Create a new, uninitialized {@link CqlTemplate}. Note: The {@link SessionFactory} has to be set before using the
|
||||
* instance.
|
||||
*
|
||||
* @see #setSessionFactory(SessionFactory)
|
||||
*/
|
||||
@@ -486,8 +486,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
|
||||
try {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Preparing statement [{}] using {}", toCql(preparedStatementCreator),
|
||||
preparedStatementCreator);
|
||||
logger.debug("Preparing statement [{}] using {}", toCql(preparedStatementCreator), preparedStatementCreator);
|
||||
}
|
||||
|
||||
Session session = getCurrentSession();
|
||||
@@ -515,9 +514,8 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
* @see org.springframework.cassandra.core.CqlOperationsNG#query(org.springframework.cassandra.core.PreparedStatementCreator, org.springframework.cassandra.core.PreparedStatementBinder, org.springframework.cassandra.core.RowCallbackHandler)
|
||||
*/
|
||||
@Override
|
||||
public void query(PreparedStatementCreator preparedStatementCreator,
|
||||
PreparedStatementBinder preparedStatementBinder, RowCallbackHandler rowCallbackHandler)
|
||||
throws DataAccessException {
|
||||
public void query(PreparedStatementCreator preparedStatementCreator, PreparedStatementBinder preparedStatementBinder,
|
||||
RowCallbackHandler rowCallbackHandler) throws DataAccessException {
|
||||
|
||||
query(preparedStatementCreator, preparedStatementBinder, newResultSetExtractor(rowCallbackHandler));
|
||||
}
|
||||
@@ -538,8 +536,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
* @see org.springframework.cassandra.core.CqlOperationsNG#query(java.lang.String, org.springframework.cassandra.core.ResultSetExtractor, java.lang.Object[])
|
||||
*/
|
||||
@Override
|
||||
public <T> T query(String cql, ResultSetExtractor<T> resultSetExtractor, Object... args)
|
||||
throws DataAccessException {
|
||||
public <T> T query(String cql, ResultSetExtractor<T> resultSetExtractor, Object... args) throws DataAccessException {
|
||||
|
||||
return query(newPreparedStatementCreator(cql), newPreparedStatementBinder(args), resultSetExtractor);
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ class ExceptionTranslatingListenableFutureAdapter<T> implements ListenableFuture
|
||||
@Override
|
||||
public void onFailure(Throwable ex) {
|
||||
if (ex instanceof RuntimeException) {
|
||||
DataAccessException dataAccessException =
|
||||
exceptionTranslator.translateExceptionIfPossible((RuntimeException) ex);
|
||||
DataAccessException dataAccessException = exceptionTranslator
|
||||
.translateExceptionIfPossible((RuntimeException) ex);
|
||||
|
||||
if (dataAccessException != null) {
|
||||
settableFuture.setException(dataAccessException);
|
||||
|
||||
@@ -19,9 +19,6 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -31,6 +28,9 @@ import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.util.concurrent.SettableListenableFuture;
|
||||
import org.springframework.util.concurrent.SuccessCallback;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
|
||||
/**
|
||||
* Adapter class to adapt Guava's {@link com.google.common.util.concurrent.ListenableFuture} into a Spring
|
||||
* {@link ListenableFuture}.
|
||||
@@ -75,8 +75,8 @@ public class GuavaListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
@Override
|
||||
public void onFailure(Throwable t) {
|
||||
if (t instanceof RuntimeException) {
|
||||
DataAccessException dataAccessException =
|
||||
exceptionTranslator.translateExceptionIfPossible((RuntimeException) t);
|
||||
DataAccessException dataAccessException = exceptionTranslator
|
||||
.translateExceptionIfPossible((RuntimeException) t);
|
||||
|
||||
if (dataAccessException != null) {
|
||||
settableFuture.setException(dataAccessException);
|
||||
|
||||
@@ -205,8 +205,8 @@ public class QueryOptions {
|
||||
* Sets the read timeout in milliseconds. Overrides the default per-host read timeout (
|
||||
* {@link SocketOptions#getReadTimeoutMillis()}).
|
||||
*
|
||||
* @param readTimeout the read timeout in milliseconds. Negative values are not allowed. If it is {@code 0}, the read timeout
|
||||
* will be disabled for this statement.
|
||||
* @param readTimeout the read timeout in milliseconds. Negative values are not allowed. If it is {@code 0}, the read
|
||||
* timeout will be disabled for this statement.
|
||||
* @since 1.5
|
||||
* @see SocketOptions#getReadTimeoutMillis()
|
||||
* @see com.datastax.driver.core.Cluster.Builder#withSocketOptions(SocketOptions)
|
||||
@@ -338,8 +338,8 @@ public class QueryOptions {
|
||||
/**
|
||||
* Sets the read timeout in milliseconds. Overrides the default per-host read timeout.
|
||||
*
|
||||
* @param readTimeout the read timeout in milliseconds. Negative values are not allowed. If it is {@code 0}, the read
|
||||
* timeout will be disabled for this statement.
|
||||
* @param readTimeout the read timeout in milliseconds. Negative values are not allowed. If it is {@code 0}, the
|
||||
* read timeout will be disabled for this statement.
|
||||
* @return {@code this} {@link QueryOptionsBuilder}
|
||||
* @see SocketOptions#getReadTimeoutMillis()
|
||||
* @see com.datastax.driver.core.Cluster.Builder#withSocketOptions(SocketOptions)
|
||||
@@ -356,8 +356,8 @@ public class QueryOptions {
|
||||
/**
|
||||
* Sets the read timeout. Overrides the default per-host read timeout.
|
||||
*
|
||||
* @param readTimeout the read timeout value. Negative values are not allowed. If it is {@code 0}, the read timeout will be
|
||||
* disabled for this statement.
|
||||
* @param readTimeout the read timeout value. Negative values are not allowed. If it is {@code 0}, the read timeout
|
||||
* will be disabled for this statement.
|
||||
* @param timeUnit the {@link TimeUnit} for the supplied timeout; must not be {@literal null}.
|
||||
* @return {@code this} {@link QueryOptionsBuilder}
|
||||
* @see SocketOptions#getReadTimeoutMillis()
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import com.datastax.driver.core.querybuilder.Insert;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Update;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Utility class to associate {@link QueryOptions} and {@link WriteOptions} with QueryBuilder {@link Statement}s.
|
||||
*
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
@@ -26,9 +29,6 @@ import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.datastax.driver.core.Statement;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Interface specifying a basic set of CQL operations executed in a reactive fashion. Implemented by
|
||||
* {@link ReactiveCqlTemplate}. Not often used directly, but a useful option to enhance testability, as it can easily be
|
||||
|
||||
@@ -32,9 +32,6 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.DataAccessUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import com.datastax.driver.core.BoundStatement;
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
@@ -260,8 +257,7 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
*/
|
||||
@Override
|
||||
public <T> Mono<T> queryForObject(String cql, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(cql, rowMapper).buffer(2).flatMap(list ->
|
||||
Mono.just(DataAccessUtils.requiredSingleResult(list)))
|
||||
return query(cql, rowMapper).buffer(2).flatMap(list -> Mono.just(DataAccessUtils.requiredSingleResult(list)))
|
||||
.next();
|
||||
}
|
||||
|
||||
@@ -382,8 +378,7 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
*/
|
||||
@Override
|
||||
public <T> Mono<T> queryForObject(Statement statement, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(statement, rowMapper).buffer(2).flatMap(list ->
|
||||
Mono.just(DataAccessUtils.requiredSingleResult(list)))
|
||||
return query(statement, rowMapper).buffer(2).flatMap(list -> Mono.just(DataAccessUtils.requiredSingleResult(list)))
|
||||
.next();
|
||||
}
|
||||
|
||||
@@ -573,8 +568,7 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
*/
|
||||
@Override
|
||||
public <T> Mono<T> queryForObject(String cql, RowMapper<T> rowMapper, Object... args) throws DataAccessException {
|
||||
return query(cql, rowMapper, args).buffer(2).flatMap(list ->
|
||||
Mono.just(DataAccessUtils.requiredSingleResult(list)))
|
||||
return query(cql, rowMapper, args).buffer(2).flatMap(list -> Mono.just(DataAccessUtils.requiredSingleResult(list)))
|
||||
.next();
|
||||
}
|
||||
|
||||
@@ -618,8 +612,8 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
|
||||
Assert.hasText(cql, "CQL must not be empty");
|
||||
|
||||
return query(new SimpleReactivePreparedStatementCreator(cql),
|
||||
newArgPreparedStatementBinder(args), Mono::just).next();
|
||||
return query(new SimpleReactivePreparedStatementCreator(cql), newArgPreparedStatementBinder(args), Mono::just)
|
||||
.next();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -644,8 +638,7 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
*/
|
||||
@Override
|
||||
public Mono<Boolean> execute(String cql, PreparedStatementBinder psb) throws DataAccessException {
|
||||
return query(new SimpleReactivePreparedStatementCreator(cql), psb, resultSet ->
|
||||
Mono.just(resultSet.wasApplied()))
|
||||
return query(new SimpleReactivePreparedStatementCreator(cql), psb, resultSet -> Mono.just(resultSet.wasApplied()))
|
||||
.next();
|
||||
}
|
||||
|
||||
@@ -757,8 +750,7 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
protected <T> Function<Throwable, Mono<? extends T>> translateException(String task, String cql) {
|
||||
|
||||
return throwable -> Mono
|
||||
.error(
|
||||
throwable instanceof DriverException ? translate(task, cql, (DriverException) throwable) : throwable);
|
||||
.error(throwable instanceof DriverException ? translate(task, cql, (DriverException) throwable) : throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,8 +39,8 @@ import com.datastax.driver.core.exceptions.DriverException;
|
||||
public interface RowCallbackHandler {
|
||||
|
||||
/**
|
||||
* Implementations must implement this method to process each row of data in the {@link ResultSet}. This method is only
|
||||
* supposed to extract values of the current row.
|
||||
* Implementations must implement this method to process each row of data in the {@link ResultSet}. This method is
|
||||
* only supposed to extract values of the current row.
|
||||
* <p>
|
||||
* Exactly what the implementation chooses to do is up to it: A trivial implementation might simply count rows, while
|
||||
* another implementation might build an XML document.
|
||||
|
||||
@@ -18,13 +18,13 @@ package org.springframework.cassandra.core;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Adapter implementation of the {@link ResultSetExtractor} interface that delegates to a {@link RowMapper} which is
|
||||
* supposed to create an object for each row. Each object is added to the results List of this
|
||||
|
||||
@@ -101,7 +101,7 @@ public abstract class AbstractResultSetConverter<T> implements Converter<ResultS
|
||||
}
|
||||
|
||||
protected void doThrow(String string) {
|
||||
throw new IllegalArgumentException(String.format("can't convert %s to desired type [%s]", string, getType()
|
||||
.getName()));
|
||||
throw new IllegalArgumentException(
|
||||
String.format("can't convert %s to desired type [%s]", string, getType().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -16,16 +16,13 @@
|
||||
package org.springframework.cassandra.core.cql;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlConstantType.Regex.*;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -61,16 +61,16 @@ public class CqlStringUtils {
|
||||
* Surrounds given object's {@link Object#toString()} with single quotes. Given {@code null}, returns {@code null}.
|
||||
*/
|
||||
public static String singleQuote(Object thing) {
|
||||
return thing == null ? null : new StringBuilder().append(SINGLE_QUOTE).append(thing).append(SINGLE_QUOTE)
|
||||
.toString();
|
||||
return thing == null ? null
|
||||
: new StringBuilder().append(SINGLE_QUOTE).append(thing).append(SINGLE_QUOTE).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds given object's {@link Object#toString()} with double quotes. Given {@code null}, returns {@code null}.
|
||||
*/
|
||||
public static String doubleQuote(Object thing) {
|
||||
return thing == null ? null : new StringBuilder().append(DOUBLE_QUOTE).append(thing).append(DOUBLE_QUOTE)
|
||||
.toString();
|
||||
return thing == null ? null
|
||||
: new StringBuilder().append(DOUBLE_QUOTE).append(thing).append(DOUBLE_QUOTE).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.DropColumnSpecification;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class DropIndexCqlGenerator extends IndexNameCqlGenerator<DropIndexSpecif
|
||||
@Override
|
||||
public StringBuilder toCql(StringBuilder cql) {
|
||||
return noNull(cql).append("DROP INDEX ")
|
||||
// .append(spec().getIfExists() ? "IF EXISTS " : "")
|
||||
// .append(spec().getIfExists() ? "IF EXISTS " : "")
|
||||
.append(spec().getName()).append(";");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DropTableCqlGenerator extends TableNameCqlGenerator<DropTableSpecif
|
||||
@Override
|
||||
public StringBuilder toCql(StringBuilder cql) {
|
||||
return noNull(cql).append("DROP TABLE ")
|
||||
// .append(spec().getIfExists() ? "IF EXISTS " : "")
|
||||
// .append(spec().getIfExists() ? "IF EXISTS " : "")
|
||||
.append(spec().getName()).append(";");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class DropUserTypeCqlGenerator extends UserTypeNameCqlGenerator<DropUserT
|
||||
*/
|
||||
@Override
|
||||
public StringBuilder toCql(StringBuilder cql) {
|
||||
return noNull(cql).append("DROP TYPE").append(spec().getIfExists() ? " IF EXISTS " : " ")
|
||||
.append(spec().getName()).append(";");
|
||||
return noNull(cql).append("DROP TYPE").append(spec().getIfExists() ? " IF EXISTS " : " ").append(spec().getName())
|
||||
.append(";");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.springframework.cassandra.core.keyspace.KeyspaceSpecification;
|
||||
* @author Matthew T. Adams
|
||||
* @param <T> subtype of this class for which this is a CQL generator.
|
||||
*/
|
||||
public abstract class KeyspaceCqlGenerator<T extends KeyspaceSpecification<T>> extends
|
||||
KeyspaceOptionsCqlGenerator<KeyspaceSpecification<T>> {
|
||||
public abstract class KeyspaceCqlGenerator<T extends KeyspaceSpecification<T>>
|
||||
extends KeyspaceOptionsCqlGenerator<KeyspaceSpecification<T>> {
|
||||
|
||||
public KeyspaceCqlGenerator(KeyspaceSpecification<T> specification) {
|
||||
super(specification);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.escapeSingle;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.singleQuote;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -26,12 +24,12 @@ import org.springframework.cassandra.core.keyspace.Option;
|
||||
|
||||
/**
|
||||
* Base class that contains behavior common to CQL generation for table operations.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param T The subtype of this class for which this is a CQL generator.
|
||||
*/
|
||||
public abstract class KeyspaceOptionsCqlGenerator<T extends KeyspaceOptionsSpecification<T>> extends
|
||||
KeyspaceNameCqlGenerator<KeyspaceOptionsSpecification<T>> {
|
||||
public abstract class KeyspaceOptionsCqlGenerator<T extends KeyspaceOptionsSpecification<T>>
|
||||
extends KeyspaceNameCqlGenerator<KeyspaceOptionsSpecification<T>> {
|
||||
|
||||
public KeyspaceOptionsCqlGenerator(KeyspaceOptionsSpecification<T> specification) {
|
||||
super(specification);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.ColumnChangeSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.RenameColumnSpecification;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -19,12 +19,12 @@ import org.springframework.cassandra.core.keyspace.TableSpecification;
|
||||
|
||||
/**
|
||||
* Base class that contains behavior common to CQL generation for table operations.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param T The subtype of this class for which this is a CQL generator.
|
||||
*/
|
||||
public abstract class TableCqlGenerator<T extends TableSpecification<T>> extends
|
||||
TableOptionsCqlGenerator<TableSpecification<T>> {
|
||||
public abstract class TableCqlGenerator<T extends TableSpecification<T>>
|
||||
extends TableOptionsCqlGenerator<TableSpecification<T>> {
|
||||
|
||||
public TableCqlGenerator(TableSpecification<T> specification) {
|
||||
super(specification);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.escapeSingle;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.singleQuote;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -26,12 +24,12 @@ import org.springframework.cassandra.core.keyspace.TableOptionsSpecification;
|
||||
|
||||
/**
|
||||
* Base class that contains behavior common to CQL generation for table operations.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param T The subtype of this class for which this is a CQL generator.
|
||||
*/
|
||||
public abstract class TableOptionsCqlGenerator<T extends TableOptionsSpecification<T>> extends
|
||||
TableNameCqlGenerator<TableOptionsSpecification<T>> {
|
||||
public abstract class TableOptionsCqlGenerator<T extends TableOptionsSpecification<T>>
|
||||
extends TableNameCqlGenerator<TableOptionsSpecification<T>> {
|
||||
|
||||
public TableOptionsCqlGenerator(TableOptionsSpecification<T> specification) {
|
||||
super(specification);
|
||||
|
||||
@@ -86,10 +86,8 @@ public class CreateKeyspaceSpecification extends KeyspaceSpecification<CreateKey
|
||||
}
|
||||
|
||||
public CreateKeyspaceSpecification withSimpleReplication(long replicationFactor) {
|
||||
return with(
|
||||
KeyspaceOption.REPLICATION,
|
||||
MapBuilder
|
||||
.map(Option.class, Object.class)
|
||||
return with(KeyspaceOption.REPLICATION,
|
||||
MapBuilder.map(Option.class, Object.class)
|
||||
.entry(new DefaultOption("class", String.class, true, false, true),
|
||||
ReplicationStrategy.SIMPLE_STRATEGY.getValue())
|
||||
.entry(new DefaultOption("replication_factor", Long.class, true, false, false), replicationFactor).build());
|
||||
|
||||
@@ -70,7 +70,7 @@ public class DropUserTypeSpecification extends UserTypeNameSpecification<DropUse
|
||||
* Sets the inclusion of an {@code IF EXISTS} clause.
|
||||
*
|
||||
* @param ifExists {@literal true} to include an {@code IF EXISTS} clause, {@literal false} to omit the
|
||||
* {@code IF NOT EXISTS} clause.
|
||||
* {@code IF NOT EXISTS} clause.
|
||||
* @return this {@link DropUserTypeSpecification}.
|
||||
*/
|
||||
public DropUserTypeSpecification ifExists(boolean ifExists) {
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.cqlId;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.*;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.springframework.cassandra.core.cql.CqlStringUtils;
|
||||
* @author John McPeek
|
||||
* @param <T> The subtype of the {@link KeyspaceOptionsSpecification}.
|
||||
*/
|
||||
public abstract class KeyspaceOptionsSpecification<T extends KeyspaceOptionsSpecification<T>> extends
|
||||
KeyspaceActionSpecification<KeyspaceOptionsSpecification<T>> {
|
||||
public abstract class KeyspaceOptionsSpecification<T extends KeyspaceOptionsSpecification<T>>
|
||||
extends KeyspaceActionSpecification<KeyspaceOptionsSpecification<T>> {
|
||||
|
||||
protected Map<String, Object> options = new LinkedHashMap<>();
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -18,9 +18,9 @@ package org.springframework.cassandra.core.keyspace;
|
||||
/**
|
||||
* Builder class to support the construction of keyspace specifications that have columns. This class can also be used
|
||||
* as a standalone {@link KeyspaceDescriptor}, independent of {@link CreateKeyspaceSpecification}.
|
||||
*
|
||||
*
|
||||
* @author John McPeek
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class KeyspaceSpecification<T> extends KeyspaceOptionsSpecification<KeyspaceSpecification<T>> implements
|
||||
KeyspaceDescriptor {}
|
||||
public class KeyspaceSpecification<T> extends KeyspaceOptionsSpecification<KeyspaceSpecification<T>>
|
||||
implements KeyspaceDescriptor {}
|
||||
|
||||
@@ -132,7 +132,6 @@ public enum TableOption implements Option {
|
||||
*
|
||||
* @author David Webb
|
||||
* @since 1.2.0
|
||||
*
|
||||
*/
|
||||
public enum KeyCachingOption {
|
||||
|
||||
@@ -270,8 +269,7 @@ public enum TableOption implements Option {
|
||||
|
||||
private Option delegate;
|
||||
|
||||
CompactionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue,
|
||||
boolean quotesValue) {
|
||||
CompactionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) {
|
||||
this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue);
|
||||
}
|
||||
|
||||
@@ -347,8 +345,7 @@ public enum TableOption implements Option {
|
||||
|
||||
private Option delegate;
|
||||
|
||||
CompressionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue,
|
||||
boolean quotesValue) {
|
||||
CompressionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) {
|
||||
this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ import org.springframework.cassandra.core.cql.CqlStringUtils;
|
||||
* @author Matthew T. Adams
|
||||
* @param <T> The subtype of the {@link TableOptionsSpecification}.
|
||||
*/
|
||||
public abstract class TableOptionsSpecification<T extends TableOptionsSpecification<T>> extends
|
||||
TableNameSpecification<TableOptionsSpecification<T>> {
|
||||
public abstract class TableOptionsSpecification<T extends TableOptionsSpecification<T>>
|
||||
extends TableNameSpecification<TableOptionsSpecification<T>> {
|
||||
|
||||
protected Map<String, Object> options = new LinkedHashMap<>();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.cqlId;
|
||||
import static org.springframework.cassandra.core.cql.CqlIdentifier.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -15,6 +15,11 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.session;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -23,22 +28,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.ColumnDefinitions;
|
||||
import com.datastax.driver.core.ExecutionInfo;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.RegularStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.ResultSetFuture;
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.SimpleStatement;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
|
||||
@@ -108,8 +108,7 @@ public abstract class AbstractRoutingSessionFactory implements SessionFactory, I
|
||||
* {@literal null}.
|
||||
*/
|
||||
public void setSessionFactoryLookup(SessionFactoryLookup sessionFactoryLookup) {
|
||||
this.sessionFactoryLookup = (sessionFactoryLookup != null ? sessionFactoryLookup
|
||||
: new MapSessionFactoryLookup());
|
||||
this.sessionFactoryLookup = (sessionFactoryLookup != null ? sessionFactoryLookup : new MapSessionFactoryLookup());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -175,8 +174,8 @@ public abstract class AbstractRoutingSessionFactory implements SessionFactory, I
|
||||
} else if (sessionFactory instanceof String) {
|
||||
return this.sessionFactoryLookup.getSessionFactory((String) sessionFactory);
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Illegal session factory value. Only [org.springframework.cassandra.core.session.SessionFactory]"
|
||||
throw new IllegalArgumentException(String
|
||||
.format("Illegal session factory value. Only [org.springframework.cassandra.core.session.SessionFactory]"
|
||||
+ " and String supported: %s", sessionFactory));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.datastax.driver.core.WriteType;
|
||||
import com.datastax.driver.core.exceptions.*;
|
||||
@@ -150,12 +150,10 @@ public class CassandraExceptionTranslator implements CQLExceptionTranslator {
|
||||
return new CassandraTraceRetrievalException(message, exception);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (exception instanceof NoHostAvailableException) {
|
||||
return new CassandraConnectionFailureException(((NoHostAvailableException) exception).getErrors(),message,
|
||||
exception);
|
||||
}
|
||||
if (exception instanceof NoHostAvailableException) {
|
||||
return new CassandraConnectionFailureException(((NoHostAvailableException) exception).getErrors(), message,
|
||||
exception);
|
||||
}
|
||||
|
||||
String exceptionType = ClassUtils.getShortName(ClassUtils.getUserClass(exception.getClass()));
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ public class CassandraSchemaElementExistsException extends NonTransientDataAcces
|
||||
private String elementName;
|
||||
private ElementType elementType;
|
||||
|
||||
public CassandraSchemaElementExistsException(String elementName, ElementType elementType, String msg, Throwable cause) {
|
||||
public CassandraSchemaElementExistsException(String elementName, ElementType elementType, String msg,
|
||||
Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.elementName = elementName;
|
||||
this.elementType = elementType;
|
||||
|
||||
@@ -16,26 +16,16 @@
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.datastax.driver.core.AuthProvider;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Configuration;
|
||||
import com.datastax.driver.core.JdkSSLOptions;
|
||||
import com.datastax.driver.core.PlainTextAuthProvider;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import com.datastax.driver.core.ProtocolOptions;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.datastax.driver.core.ProtocolOptions.Compression;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.QueryOptions;
|
||||
import com.datastax.driver.core.SSLOptions;
|
||||
import com.datastax.driver.core.SocketOptions;
|
||||
import com.datastax.driver.core.TimestampGenerator;
|
||||
import com.datastax.driver.core.policies.AddressTranslator;
|
||||
import com.datastax.driver.core.policies.ExponentialReconnectionPolicy;
|
||||
import com.datastax.driver.core.policies.LoadBalancingPolicy;
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -17,7 +17,10 @@ package org.springframework.cassandra.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.util.ReflectionUtils.*;
|
||||
|
||||
@@ -310,7 +313,8 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
final PoolingOptionsFactoryBean.HostDistancePoolingOptions mockHostDistancePoolingOptions = mock(
|
||||
PoolingOptionsFactoryBean.HostDistancePoolingOptions.class);
|
||||
|
||||
when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
|
||||
when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class)))
|
||||
.thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
|
||||
|
||||
poolingOptionsFactoryBean = new PoolingOptionsFactoryBean() {
|
||||
@Override
|
||||
@@ -331,7 +335,8 @@ public class PoolingOptionsFactoryBeanUnitTests {
|
||||
final PoolingOptionsFactoryBean.HostDistancePoolingOptions mockHostDistancePoolingOptions = mock(
|
||||
PoolingOptionsFactoryBean.HostDistancePoolingOptions.class);
|
||||
|
||||
when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
|
||||
when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class)))
|
||||
.thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0));
|
||||
|
||||
poolingOptionsFactoryBean = new PoolingOptionsFactoryBean() {
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.cassandra.config.java;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -30,17 +30,8 @@ import org.springframework.cassandra.config.CompressionType;
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
|
||||
|
||||
import com.datastax.driver.core.AuthProvider;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Configuration;
|
||||
import com.datastax.driver.core.PlainTextAuthProvider;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import com.datastax.driver.core.ProtocolOptions;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.datastax.driver.core.ProtocolOptions.Compression;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.QueryOptions;
|
||||
import com.datastax.driver.core.SocketOptions;
|
||||
import com.datastax.driver.core.TimestampGenerator;
|
||||
import com.datastax.driver.core.policies.AddressTranslator;
|
||||
import com.datastax.driver.core.policies.ExponentialReconnectionPolicy;
|
||||
import com.datastax.driver.core.policies.LoadBalancingPolicy;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.cassandra.config.xml;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.cassandra.support.BeanDefinitionTestUtils.*;
|
||||
|
||||
|
||||
@@ -147,12 +147,11 @@ public class AsyncCqlTemplateIntegrationTests extends AbstractKeyspaceCreatingIn
|
||||
public void queryPreparedStatementCreatorShouldInvokeCallback() throws Exception {
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
getUninterruptibly(template.query(
|
||||
session -> new GuavaListenableFutureAdapter<>(
|
||||
session.prepareAsync("SELECT id FROM user WHERE id = ?;"), template.getExceptionTranslator()),
|
||||
ps -> ps.bind("WHITE"), row -> {
|
||||
result.add(row.getString(0));
|
||||
}));
|
||||
getUninterruptibly(template
|
||||
.query(session -> new GuavaListenableFutureAdapter<>(session.prepareAsync("SELECT id FROM user WHERE id = ?;"),
|
||||
template.getExceptionTranslator()), ps -> ps.bind("WHITE"), row -> {
|
||||
result.add(row.getString(0));
|
||||
}));
|
||||
|
||||
assertThat(result).contains("WHITE");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.cassandra.core;
|
||||
|
||||
import static edu.umd.cs.mtc.TestFramework.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import edu.umd.cs.mtc.MultithreadedTestCase;
|
||||
@@ -38,7 +38,7 @@ import com.datastax.driver.core.Session;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link CachedPreparedStatementCreator}.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
|
||||
@@ -443,8 +443,7 @@ public class CqlTemplateUnitTests {
|
||||
|
||||
doTestStrings(null, null, null, cqlTemplate -> {
|
||||
|
||||
ResultSet resultSet = cqlTemplate.execute("SELECT * from USERS",
|
||||
(session, ps) -> session.execute(ps.bind("A")));
|
||||
ResultSet resultSet = cqlTemplate.execute("SELECT * from USERS", (session, ps) -> session.execute(ps.bind("A")));
|
||||
|
||||
try {
|
||||
assertThat(resultSet).hasSize(3);
|
||||
|
||||
@@ -92,8 +92,8 @@ public class DefaultBridgedReactiveSessionIntegrationTests extends AbstractKeysp
|
||||
|
||||
session.execute("CREATE TABLE users (\n" + " userid text PRIMARY KEY,\n" + " first_name text\n" + ");");
|
||||
|
||||
Mono<PreparedStatement> execution = reactiveSession.prepare(
|
||||
"INSERT INTO users (userid, first_name) VALUES (?, ?);");
|
||||
Mono<PreparedStatement> execution = reactiveSession
|
||||
.prepare("INSERT INTO users (userid, first_name) VALUES (?, ?);");
|
||||
PreparedStatement preparedStatement = execution.block();
|
||||
|
||||
assertThat(preparedStatement).isNotNull();
|
||||
|
||||
@@ -83,8 +83,8 @@ public class DefaultBridgedReactiveSessionUnitTests {
|
||||
|
||||
reactiveSession.execute("SELECT * WHERE a = ?", Collections.singletonMap("a", "value")).subscribe();
|
||||
|
||||
verify(sessionMock).executeAsync(eq(new SimpleStatement("SELECT * WHERE a = ?",
|
||||
Collections.singletonMap("a", "value"))));
|
||||
verify(sessionMock)
|
||||
.executeAsync(eq(new SimpleStatement("SELECT * WHERE a = ?", Collections.singletonMap("a", "value"))));
|
||||
}
|
||||
|
||||
@Test // DATACASS-335
|
||||
@@ -137,7 +137,7 @@ public class DefaultBridgedReactiveSessionUnitTests {
|
||||
private static <T extends Statement> T eq(T value) {
|
||||
|
||||
return ArgumentMatchers.argThat(argument -> argument instanceof Statement //
|
||||
? value.toString().equals(argument.toString()) //
|
||||
: value.equals(argument));
|
||||
? value.toString().equals(argument.toString()) //
|
||||
: value.equals(argument));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,9 @@ public class AlterKeyspaceCqlGeneratorUnitTests {
|
||||
private static void assertReplicationMap(Map<Option, Object> replicationMap, String cql) {
|
||||
assertThat(cql.contains(" WITH replication = { ")).isTrue();
|
||||
|
||||
replicationMap.entrySet().stream().map(entry -> "'" + entry.getKey().getName() + "' : '" + entry.getValue().toString() + "'").forEach(keyValuePair -> assertThat(cql.contains(keyValuePair)).isTrue());
|
||||
replicationMap.entrySet().stream()
|
||||
.map(entry -> "'" + entry.getKey().getName() + "' : '" + entry.getValue().toString() + "'")
|
||||
.forEach(keyValuePair -> assertThat(cql.contains(keyValuePair)).isTrue());
|
||||
}
|
||||
|
||||
public static void assertDurableWrites(Boolean durableWrites, String cql) {
|
||||
|
||||
@@ -278,7 +278,7 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
public static final List<String> FUNKY_LEGAL_NAMES;
|
||||
|
||||
static {
|
||||
List<String> funkies = new ArrayList<>(Arrays.asList(new String[]{ /* TODO */}));
|
||||
List<String> funkies = new ArrayList<>(Arrays.asList(new String[] { /* TODO */ }));
|
||||
// TODO: should these work? "a \"\" x", "a\"\"\"\"x", "a b"
|
||||
FUNKY_LEGAL_NAMES = Collections.unmodifiableList(Arrays.stream(ReservedKeyword.values()) //
|
||||
.map(Enum::name) //
|
||||
|
||||
@@ -51,8 +51,7 @@ public class MapSessionFactoryLookupUnitTests {
|
||||
@Test // DATACASS-330
|
||||
public void shouldResolveSessionFactoryCorrectly() {
|
||||
|
||||
MapSessionFactoryLookup sessionFactoryLookup =
|
||||
new MapSessionFactoryLookup("factory", sessionFactory);
|
||||
MapSessionFactoryLookup sessionFactoryLookup = new MapSessionFactoryLookup("factory", sessionFactory);
|
||||
|
||||
assertThat(sessionFactoryLookup.getSessionFactory("factory")).isSameAs(sessionFactory);
|
||||
}
|
||||
|
||||
@@ -23,24 +23,8 @@ import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.support.exception.CassandraAuthenticationException;
|
||||
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInsufficientReplicasAvailableException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInternalException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInvalidConfigurationInQueryException;
|
||||
import org.springframework.cassandra.support.exception.CassandraInvalidQueryException;
|
||||
import org.springframework.cassandra.support.exception.CassandraKeyspaceExistsException;
|
||||
import org.springframework.cassandra.support.exception.CassandraQuerySyntaxException;
|
||||
import org.springframework.cassandra.support.exception.CassandraReadTimeoutException;
|
||||
import org.springframework.cassandra.support.exception.CassandraSchemaElementExistsException;
|
||||
import org.springframework.cassandra.support.exception.*;
|
||||
import org.springframework.cassandra.support.exception.CassandraSchemaElementExistsException.ElementType;
|
||||
import org.springframework.cassandra.support.exception.CassandraTableExistsException;
|
||||
import org.springframework.cassandra.support.exception.CassandraTraceRetrievalException;
|
||||
import org.springframework.cassandra.support.exception.CassandraTruncateException;
|
||||
import org.springframework.cassandra.support.exception.CassandraTypeMismatchException;
|
||||
import org.springframework.cassandra.support.exception.CassandraUnauthorizedException;
|
||||
import org.springframework.cassandra.support.exception.CassandraUncategorizedException;
|
||||
import org.springframework.cassandra.support.exception.CassandraWriteTimeoutException;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
import org.springframework.dao.TransientDataAccessResourceException;
|
||||
@@ -50,34 +34,7 @@ import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.DataType;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.WriteType;
|
||||
import com.datastax.driver.core.exceptions.AlreadyExistsException;
|
||||
import com.datastax.driver.core.exceptions.AuthenticationException;
|
||||
import com.datastax.driver.core.exceptions.BootstrappingException;
|
||||
import com.datastax.driver.core.exceptions.BusyConnectionException;
|
||||
import com.datastax.driver.core.exceptions.CodecNotFoundException;
|
||||
import com.datastax.driver.core.exceptions.ConnectionException;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
import com.datastax.driver.core.exceptions.DriverInternalError;
|
||||
import com.datastax.driver.core.exceptions.FunctionExecutionException;
|
||||
import com.datastax.driver.core.exceptions.InvalidConfigurationInQueryException;
|
||||
import com.datastax.driver.core.exceptions.InvalidQueryException;
|
||||
import com.datastax.driver.core.exceptions.InvalidTypeException;
|
||||
import com.datastax.driver.core.exceptions.NoHostAvailableException;
|
||||
import com.datastax.driver.core.exceptions.OverloadedException;
|
||||
import com.datastax.driver.core.exceptions.PagingStateException;
|
||||
import com.datastax.driver.core.exceptions.ReadFailureException;
|
||||
import com.datastax.driver.core.exceptions.ReadTimeoutException;
|
||||
import com.datastax.driver.core.exceptions.SyntaxError;
|
||||
import com.datastax.driver.core.exceptions.TraceRetrievalException;
|
||||
import com.datastax.driver.core.exceptions.TruncateException;
|
||||
import com.datastax.driver.core.exceptions.UnauthorizedException;
|
||||
import com.datastax.driver.core.exceptions.UnavailableException;
|
||||
import com.datastax.driver.core.exceptions.UnpreparedException;
|
||||
import com.datastax.driver.core.exceptions.UnresolvedUserTypeException;
|
||||
import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
|
||||
import com.datastax.driver.core.exceptions.UnsupportedProtocolVersionException;
|
||||
import com.datastax.driver.core.exceptions.WriteFailureException;
|
||||
import com.datastax.driver.core.exceptions.WriteTimeoutException;
|
||||
import com.datastax.driver.core.exceptions.*;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,11 +43,10 @@ public abstract class AbstractEmbeddedCassandraIntegrationTest {
|
||||
/**
|
||||
* Initiate a Cassandra environment in test scope.
|
||||
*/
|
||||
@Rule public final CassandraRule cassandraRule = cassandraEnvironment.testInstance()
|
||||
.before(session -> {
|
||||
AbstractEmbeddedCassandraIntegrationTest.this.cluster = session.getCluster();
|
||||
return null;
|
||||
});
|
||||
@Rule public final CassandraRule cassandraRule = cassandraEnvironment.testInstance().before(session -> {
|
||||
AbstractEmbeddedCassandraIntegrationTest.this.cluster = session.getCluster();
|
||||
return null;
|
||||
});
|
||||
|
||||
/**
|
||||
* The {@link Cluster} that's connected to Cassandra.
|
||||
|
||||
@@ -60,9 +60,9 @@ public class BeanDefinitionBuilderArgument {
|
||||
protected BeanDefinitionBuilderArgument(boolean reference, Object value) {
|
||||
this.reference = reference;
|
||||
if (this.reference && (value == null || !(value instanceof CharSequence))) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"reference argument must have value of type CharSequence, not [%s]", value == null ? "null" : value
|
||||
.getClass().getName()));
|
||||
throw new IllegalArgumentException(
|
||||
String.format("reference argument must have value of type CharSequence, not [%s]",
|
||||
value == null ? "null" : value.getClass().getName()));
|
||||
}
|
||||
if (!StringUtils.hasText((CharSequence) value)) {
|
||||
throw new IllegalArgumentException("given CharSequence has no text");
|
||||
|
||||
@@ -93,7 +93,8 @@ public class BeanDefinitionUtils {
|
||||
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)
|
||||
*/
|
||||
public static BeanDefinitionHolder getSingleBeanDefinitionOfType(BeanDefinitionRegistry registry,
|
||||
ListableBeanFactory factory, Class<?> type, boolean includeNonSingletons, boolean allowEagerInit, boolean required) {
|
||||
ListableBeanFactory factory, Class<?> type, boolean includeNonSingletons, boolean allowEagerInit,
|
||||
boolean required) {
|
||||
|
||||
BeanDefinitionHolder[] definitions = getBeanDefinitionsOfType(registry, factory, type, includeNonSingletons,
|
||||
allowEagerInit);
|
||||
|
||||
@@ -85,8 +85,7 @@ public class CassandraEntityClassScanner {
|
||||
}
|
||||
|
||||
public void setEntityBasePackages(Collection<String> entityBasePackages) {
|
||||
this.entityBasePackages = entityBasePackages == null ? new HashSet<>() : new HashSet<>(
|
||||
entityBasePackages);
|
||||
this.entityBasePackages = entityBasePackages == null ? new HashSet<>() : new HashSet<>(entityBasePackages);
|
||||
}
|
||||
|
||||
public Set<Class<?>> getEntityBasePackageClasses() {
|
||||
@@ -94,8 +93,8 @@ public class CassandraEntityClassScanner {
|
||||
}
|
||||
|
||||
public void setEntityBasePackageClasses(Collection<Class<?>> entityBasePackageClasses) {
|
||||
this.entityBasePackageClasses = entityBasePackageClasses == null ? new HashSet<>() : new HashSet<>(
|
||||
entityBasePackageClasses);
|
||||
this.entityBasePackageClasses = entityBasePackageClasses == null ? new HashSet<>()
|
||||
: new HashSet<>(entityBasePackageClasses);
|
||||
}
|
||||
|
||||
public void setBeanClassLoader(ClassLoader beanClassLoader) {
|
||||
|
||||
@@ -146,8 +146,7 @@ abstract class CassandraConverters {
|
||||
|
||||
Object object = source.getObject(0);
|
||||
|
||||
return (object != null ? NumberUtils.convertNumberToTargetClass((Number) object, this.targetType)
|
||||
: null);
|
||||
return (object != null ? NumberUtils.convertNumberToTargetClass((Number) object, this.targetType) : null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
private final CQLExceptionTranslator exceptionTranslator;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link AsyncCassandraTemplate} initialized with the given {@link Session}
|
||||
* and a default {@link MappingCassandraConverter}.
|
||||
* Creates an instance of {@link AsyncCassandraTemplate} initialized with the given {@link Session} and a default
|
||||
* {@link MappingCassandraConverter}.
|
||||
*
|
||||
* @param session {@link Session} used to interact with Cassandra; must not be {@literal null}.
|
||||
* @see CassandraConverter
|
||||
@@ -91,12 +91,12 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link AsyncCassandraTemplate} initialized with the given {@link Session}
|
||||
* and {@link CassandraConverter}.
|
||||
* Creates an instance of {@link AsyncCassandraTemplate} initialized with the given {@link Session} and
|
||||
* {@link CassandraConverter}.
|
||||
*
|
||||
* @param session {@link Session} used to interact with Cassandra; must not be {@literal null}.
|
||||
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types;
|
||||
* must not be {@literal null}.
|
||||
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types; must not be
|
||||
* {@literal null}.
|
||||
* @see CassandraConverter
|
||||
* @see Session
|
||||
*/
|
||||
@@ -105,12 +105,12 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link AsyncCassandraTemplate} initialized with the given {@link SessionFactory}
|
||||
* and {@link CassandraConverter}.
|
||||
* Creates an instance of {@link AsyncCassandraTemplate} initialized with the given {@link SessionFactory} and
|
||||
* {@link CassandraConverter}.
|
||||
*
|
||||
* @param sessionFactory {@link SessionFactory} used to interact with Cassandra; must not be {@literal null}.
|
||||
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types;
|
||||
* must not be {@literal null}.
|
||||
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types; must not be
|
||||
* {@literal null}.
|
||||
* @see CassandraConverter
|
||||
* @see Session
|
||||
*/
|
||||
@@ -119,12 +119,12 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link AsyncCassandraTemplate} initialized with the given {@link AsyncCqlTemplate}
|
||||
* and {@link CassandraConverter}.
|
||||
* Creates an instance of {@link AsyncCassandraTemplate} initialized with the given {@link AsyncCqlTemplate} and
|
||||
* {@link CassandraConverter}.
|
||||
*
|
||||
* @param asyncCqlTemplate {@link AsyncCqlTemplate} used to interact with Cassandra; must not be {@literal null}.
|
||||
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types;
|
||||
* must not be {@literal null}.
|
||||
* @param converter {@link CassandraConverter} used to convert between Java and Cassandra types; must not be
|
||||
* {@literal null}.
|
||||
* @see CassandraConverter
|
||||
* @see Session
|
||||
*/
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.data.cassandra.core;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.core.SessionCallback;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.cassandra.core.cql.generator.CreateTableCqlGenerator;
|
||||
@@ -29,7 +27,6 @@ import org.springframework.cassandra.core.keyspace.CreateTableSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DropTableSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DropUserTypeSpecification;
|
||||
import org.springframework.cassandra.core.session.SessionFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -133,10 +130,8 @@ public class CassandraAdminTemplate extends CassandraTemplate implements Cassand
|
||||
|
||||
KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace());
|
||||
|
||||
|
||||
|
||||
Assert.state(keyspaceMetadata != null, String.format("Metadata for keyspace [%s] not available",
|
||||
session.getLoggedKeyspace()));
|
||||
Assert.state(keyspaceMetadata != null,
|
||||
String.format("Metadata for keyspace [%s] not available", session.getLoggedKeyspace()));
|
||||
|
||||
return keyspaceMetadata;
|
||||
});
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.data.cassandra.core;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import org.springframework.cassandra.core.CqlTemplate;
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
import org.springframework.cassandra.core.QueryOptionsUtil;
|
||||
import org.springframework.cassandra.core.WriteOptions;
|
||||
@@ -32,7 +31,7 @@ import com.datastax.driver.core.querybuilder.Update;
|
||||
* Simple utility class for working with the QueryBuilder API.
|
||||
* <p>
|
||||
* Only intended for internal use.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
import org.springframework.cassandra.core.ReactiveCqlOperations;
|
||||
@@ -24,9 +27,6 @@ import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
|
||||
import com.datastax.driver.core.Statement;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Interface specifying a basic set of reactive Cassandra operations. Implemented by {@link ReactiveCassandraTemplate}.
|
||||
* Not often used directly, but a useful option to enhance testability, as it can easily be mocked or stubbed.
|
||||
@@ -246,7 +246,7 @@ public interface ReactiveCassandraOperations {
|
||||
|
||||
/**
|
||||
* Execute a {@code TRUNCATE} query to remove all entities of a given class.
|
||||
*
|
||||
*
|
||||
* @param entityClass The entity type must not be {@literal null}.
|
||||
* @throws DataAccessException if there is any problem issuing the execution.
|
||||
*/
|
||||
@@ -261,7 +261,7 @@ public interface ReactiveCassandraOperations {
|
||||
|
||||
/**
|
||||
* Expose the underlying {@link ReactiveCqlOperations} to allow CQL operations.
|
||||
*
|
||||
*
|
||||
* @return the underlying {@link ReactiveCqlOperations}.
|
||||
* @see ReactiveCqlOperations
|
||||
*/
|
||||
|
||||
@@ -18,20 +18,6 @@ package org.springframework.data.cassandra.core;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.cassandra.core.*;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
|
||||
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
|
||||
import org.springframework.data.cassandra.mapping.CassandraPersistentEntity;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.cassandra.core.CqlProvider;
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
@@ -45,7 +31,6 @@ import org.springframework.cassandra.core.session.ReactiveResultSet;
|
||||
import org.springframework.cassandra.core.session.ReactiveSession;
|
||||
import org.springframework.cassandra.core.session.ReactiveSessionFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.cassandra.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.convert.MappingCassandraConverter;
|
||||
import org.springframework.data.cassandra.mapping.CassandraMappingContext;
|
||||
@@ -265,7 +250,8 @@ public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
|
||||
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
Select select = QueryBuilder.select().countAll().from(mappingContext.getRequiredPersistentEntity(entityClass).getTableName().toCql());
|
||||
Select select = QueryBuilder.select().countAll()
|
||||
.from(mappingContext.getRequiredPersistentEntity(entityClass).getTableName().toCql());
|
||||
|
||||
return cqlOperations.queryForObject(select, Long.class);
|
||||
}
|
||||
@@ -294,8 +280,8 @@ public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
|
||||
|
||||
@Override
|
||||
public Publisher<T> doInSession(ReactiveSession session) throws DriverException, DataAccessException {
|
||||
return session.execute(insert).flatMap(
|
||||
reactiveResultSet -> reactiveResultSet.wasApplied() ? Mono.just(entity) : Mono.empty());
|
||||
return session.execute(insert)
|
||||
.flatMap(reactiveResultSet -> reactiveResultSet.wasApplied() ? Mono.just(entity) : Mono.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -352,8 +338,8 @@ public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
|
||||
|
||||
@Override
|
||||
public Publisher<T> doInSession(ReactiveSession session) throws DriverException, DataAccessException {
|
||||
return session.execute(update).flatMap(
|
||||
reactiveResultSet -> reactiveResultSet.wasApplied() ? Mono.just(entity) : Mono.empty());
|
||||
return session.execute(update)
|
||||
.flatMap(reactiveResultSet -> reactiveResultSet.wasApplied() ? Mono.just(entity) : Mono.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -429,8 +415,8 @@ public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
|
||||
|
||||
@Override
|
||||
public Publisher<T> doInSession(ReactiveSession session) throws DriverException, DataAccessException {
|
||||
return session.execute(delete).flatMap(
|
||||
reactiveResultSet -> reactiveResultSet.wasApplied() ? Mono.just(entity) : Mono.empty());
|
||||
return session.execute(delete)
|
||||
.flatMap(reactiveResultSet -> reactiveResultSet.wasApplied() ? Mono.just(entity) : Mono.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -472,7 +458,8 @@ public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
|
||||
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
Truncate truncate = QueryBuilder.truncate(mappingContext.getRequiredPersistentEntity(entityClass).getTableName().toCql());
|
||||
Truncate truncate = QueryBuilder
|
||||
.truncate(mappingContext.getRequiredPersistentEntity(entityClass).getTableName().toCql());
|
||||
|
||||
return cqlOperations.execute(truncate).then();
|
||||
}
|
||||
|
||||
@@ -458,8 +458,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
getName(), getOwner().getType().getName(), this.columnNames.size(), this.columnNames.size() == 1 ? "" : "s",
|
||||
columnNames.size()));
|
||||
|
||||
this.columnNames = this.explicitColumnNames = Collections
|
||||
.unmodifiableList(new ArrayList<>(columnNames));
|
||||
this.columnNames = this.explicitColumnNames = Collections.unmodifiableList(new ArrayList<>(columnNames));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -17,15 +17,15 @@ package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
import com.datastax.driver.core.TableMetadata;
|
||||
import com.datastax.driver.core.UserType;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.CreateTableSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.CreateUserTypeSpecification;
|
||||
import org.springframework.data.cassandra.convert.CustomConversions;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
import com.datastax.driver.core.TableMetadata;
|
||||
import com.datastax.driver.core.UserType;
|
||||
|
||||
/**
|
||||
* A {@link MappingContext} for Cassandra.
|
||||
*
|
||||
@@ -46,8 +46,9 @@ public interface CassandraMappingContext
|
||||
/**
|
||||
* Returns all persistent entities or only non-primary-key entities.
|
||||
*
|
||||
* @param includePrimaryKeyTypesAndUdts If {@literal true}, returns all entities, including entities that represent primary
|
||||
* key types and user-defined types. If {@literal false}, returns only entities that don't represent primary key types and no user-defined types.
|
||||
* @param includePrimaryKeyTypesAndUdts If {@literal true}, returns all entities, including entities that represent
|
||||
* primary key types and user-defined types. If {@literal false}, returns only entities that don't represent
|
||||
* primary key types and no user-defined types.
|
||||
*/
|
||||
Collection<CassandraPersistentEntity<?>> getPersistentEntities(boolean includePrimaryKeyTypesAndUdts);
|
||||
|
||||
@@ -62,6 +63,7 @@ public interface CassandraMappingContext
|
||||
|
||||
/**
|
||||
* Returns only those entities representing primary key types.
|
||||
*
|
||||
* @deprecated as of 1.5
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -146,8 +148,8 @@ public interface CassandraMappingContext
|
||||
DataType getDataType(CassandraPersistentProperty property);
|
||||
|
||||
/**
|
||||
* Retrieve the data type based on the given {@code type}. Cassandra {@link DataType types} are determined using simple types and
|
||||
* configured {@link CustomConversions}.
|
||||
* Retrieve the data type based on the given {@code type}. Cassandra {@link DataType types} are determined using
|
||||
* simple types and configured {@link CustomConversions}.
|
||||
*
|
||||
* @param type must not be {@literal null}.
|
||||
* @return the Cassandra {@link DataType type}.
|
||||
|
||||
@@ -85,8 +85,7 @@ public class EntityMapping {
|
||||
}
|
||||
|
||||
public void setPropertyMappings(Map<String, PropertyMapping> propertyMappings) {
|
||||
this.propertyMappings = (propertyMappings != null ? new HashMap<>(propertyMappings)
|
||||
: Collections.emptyMap());
|
||||
this.propertyMappings = (propertyMappings != null ? new HashMap<>(propertyMappings) : Collections.emptyMap());
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
|
||||
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* Cassandra specific {@link org.springframework.data.repository.Repository} interface with reactive support.
|
||||
*
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@@ -21,10 +21,10 @@ import org.springframework.data.repository.core.EntityInformation;
|
||||
|
||||
/**
|
||||
* Cassandra specific {@link EntityInformation}.
|
||||
*
|
||||
*
|
||||
* @author Alex Shvid
|
||||
*/
|
||||
public interface CassandraEntityInformation<T, ID extends Serializable> extends EntityInformation<T, ID>,
|
||||
CassandraEntityMetadata<T> {
|
||||
public interface CassandraEntityInformation<T, ID extends Serializable>
|
||||
extends EntityInformation<T, ID>, CassandraEntityMetadata<T> {
|
||||
|
||||
}
|
||||
|
||||
@@ -85,11 +85,11 @@ public class CassandraParameters extends Parameters<CassandraParameters, Cassand
|
||||
AnnotatedParameter annotatedParameter = new AnnotatedParameter(parameter);
|
||||
|
||||
if (AnnotatedElementUtils.hasAnnotation(annotatedParameter, CassandraType.class)) {
|
||||
CassandraType cassandraType = AnnotatedElementUtils.findMergedAnnotation(
|
||||
annotatedParameter, CassandraType.class);
|
||||
CassandraType cassandraType = AnnotatedElementUtils.findMergedAnnotation(annotatedParameter,
|
||||
CassandraType.class);
|
||||
|
||||
Assert.notNull(cassandraType.type(), String.format(
|
||||
"You must specify the type() when annotating method parameters with @%s",
|
||||
Assert.notNull(cassandraType.type(),
|
||||
String.format("You must specify the type() when annotating method parameters with @%s",
|
||||
CassandraType.class.getSimpleName()));
|
||||
|
||||
this.cassandraType = cassandraType;
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.springframework.data.repository.query.ParametersParameterAccessor;
|
||||
import com.datastax.driver.core.DataType;
|
||||
|
||||
/**
|
||||
* Cassandra-specific {@link ParameterAccessor} exposing Cassandra {@link DataType types}
|
||||
* that are supported by the driver and parameter type.
|
||||
* Cassandra-specific {@link ParameterAccessor} exposing Cassandra {@link DataType types} that are supported by the
|
||||
* driver and parameter type.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @see org.springframework.data.cassandra.repository.query.CassandraParameterAccessor
|
||||
|
||||
@@ -15,16 +15,16 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.repository.util.ReactiveWrapperConverters;
|
||||
import org.springframework.data.repository.util.ReactiveWrappers;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.MonoProcessor;
|
||||
|
||||
/**
|
||||
* Reactive {@link org.springframework.data.repository.query.ParametersParameterAccessor} implementation that subscribes
|
||||
* to reactive parameter wrapper types upon creation. This class performs synchronization when acessing parameters.
|
||||
|
||||
@@ -344,8 +344,8 @@ class StringBasedQuery {
|
||||
.expression(input.substring(exprStart + 3, currentPosition - 1), true));
|
||||
} else {
|
||||
if (matcher.pattern() == INDEX_PARAMETER_BINDING_PATTERN) {
|
||||
bindings.add(ExpressionEvaluatingParameterBinder.ParameterBinding.indexed(
|
||||
Integer.parseInt(matcher.group(1))));
|
||||
bindings
|
||||
.add(ExpressionEvaluatingParameterBinder.ParameterBinding.indexed(Integer.parseInt(matcher.group(1))));
|
||||
} else {
|
||||
bindings.add(ExpressionEvaluatingParameterBinder.ParameterBinding.named(matcher.group(1)));
|
||||
}
|
||||
|
||||
@@ -97,10 +97,7 @@ public class CassandraRepositoryFactory extends RepositoryFactorySupport {
|
||||
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(domainClass);
|
||||
|
||||
|
||||
|
||||
return new MappingCassandraEntityInformation<>((CassandraPersistentEntity<T>) entity,
|
||||
operations.getConverter());
|
||||
return new MappingCassandraEntityInformation<>((CassandraPersistentEntity<T>) entity, operations.getConverter());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -67,8 +67,8 @@ public class IdInterfaceValidator {
|
||||
}
|
||||
|
||||
Class<?>[] interfaces = id.getInterfaces();
|
||||
if (interfaces.length > 2
|
||||
|| ((interfaces.length == 1 && !(interfaces[0].equals(Serializable.class) || interfaces[0].equals(MapId.class))))) {
|
||||
if (interfaces.length > 2 || ((interfaces.length == 1
|
||||
&& !(interfaces[0].equals(Serializable.class) || interfaces[0].equals(MapId.class))))) {
|
||||
x.add(new IdInterfaceException(id, null, "id type may only extend Serializable and/or MapId"));
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,8 @@ public class SimpleCassandraRepository<T, ID extends Serializable> implements Ty
|
||||
@Override
|
||||
public <S extends T> List<S> save(Iterable<S> entities) {
|
||||
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null");List<S> result = new ArrayList<>();
|
||||
Assert.notNull(entities, "The given Iterable of entities must not be null");
|
||||
List<S> result = new ArrayList<>();
|
||||
for (S entity : entities) {
|
||||
|
||||
S saved;
|
||||
|
||||
@@ -130,7 +130,7 @@ public class SchemaActionIntegrationTests extends AbstractEmbeddedCassandraInteg
|
||||
assertHasTableWithColumns(session, "person", "firstName", "lastName", "nickname", "birthDate",
|
||||
"numberOfChildren", "cool", "createdDate", "zoneId", "mainAddress", "alternativeAddresses");
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,7 +139,7 @@ public class SchemaActionIntegrationTests extends AbstractEmbeddedCassandraInteg
|
||||
(SessionCallback<Void>) session -> {
|
||||
assertHasTableWithColumns(session, "person", "id", "firstName", "lastName");
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,7 +149,7 @@ public class SchemaActionIntegrationTests extends AbstractEmbeddedCassandraInteg
|
||||
assertHasTableWithColumns(session, "person", "firstName", "lastName", "nickname", "birthDate",
|
||||
"numberOfChildren", "cool", "createdDate", "zoneId", "mainAddress", "alternativeAddresses");
|
||||
return null;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.matches;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.data.cassandra.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
@@ -112,8 +112,7 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
assertThat(stringZero.getColumnName().toCql()).isEqualTo("\"stringZero\"");
|
||||
assertThat(stringOne.getColumnName().toCql()).isEqualTo("\"stringOne\"");
|
||||
|
||||
List<CqlIdentifier> names = Arrays
|
||||
.asList(quotedCqlId("stringZero"), quotedCqlId("stringOne"));
|
||||
List<CqlIdentifier> names = Arrays.asList(quotedCqlId("stringZero"), quotedCqlId("stringOne"));
|
||||
CassandraPersistentEntity<?> entity = context.getRequiredPersistentEntity(ImplicitComposite.class);
|
||||
|
||||
assertThat(entity.getRequiredPersistentProperty("primaryKey").getColumnNames()).isEqualTo(names);
|
||||
@@ -189,8 +188,7 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
assertThat(stringZero.getColumnName().toCql()).isEqualTo("\"" + EXPLICIT_KEY_0 + "\"");
|
||||
assertThat(stringOne.getColumnName().toCql()).isEqualTo("\"" + EXPLICIT_KEY_1 + "\"");
|
||||
|
||||
List<CqlIdentifier> names = Arrays
|
||||
.asList(quotedCqlId(EXPLICIT_KEY_0), quotedCqlId(EXPLICIT_KEY_1));
|
||||
List<CqlIdentifier> names = Arrays.asList(quotedCqlId(EXPLICIT_KEY_0), quotedCqlId(EXPLICIT_KEY_1));
|
||||
CassandraPersistentEntity<?> entity = context.getRequiredPersistentEntity(ExplicitComposite.class);
|
||||
|
||||
assertThat(entity.getRequiredPersistentProperty("primaryKey").getColumnNames()).isEqualTo(names);
|
||||
|
||||
@@ -84,8 +84,7 @@ public class CassandraParametersParameterAccessorUnitTests {
|
||||
public void returnTypeForAnnotatedParameterWhenUsingStringValue() throws Exception {
|
||||
|
||||
Method method = PossibleRepository.class.getMethod("findByAnnotatedObject", Object.class);
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method),
|
||||
"");
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method), "");
|
||||
|
||||
assertThat(accessor.getDataType(0)).isEqualTo(DataType.date());
|
||||
}
|
||||
@@ -94,8 +93,7 @@ public class CassandraParametersParameterAccessorUnitTests {
|
||||
public void returnTypeForAnnotatedParameterWhenUsingNullValue() throws Exception {
|
||||
|
||||
Method method = PossibleRepository.class.getMethod("findByAnnotatedObject", Object.class);
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method),
|
||||
"");
|
||||
CassandraParameterAccessor accessor = new CassandraParametersParameterAccessor(getCassandraQueryMethod(method), "");
|
||||
|
||||
assertThat(accessor.getDataType(0)).isEqualTo(DataType.date());
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ public abstract class QueryIntegrationTests extends AbstractSpringDataEmbeddedCa
|
||||
|
||||
@Test // DATACASS-297
|
||||
public void streamShouldReturnEntities() {
|
||||
|
||||
|
||||
long before = personRepository.count();
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
@@ -41,8 +41,6 @@ import org.reactivestreams.Publisher;
|
||||
import org.reactivestreams.Subscriber;
|
||||
import org.reactivestreams.Subscription;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* ###############################################################
|
||||
@@ -57,33 +55,30 @@ import org.reactivestreams.Subscription;
|
||||
* ###############################################################
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* A Subscriber implementation that hosts assertion tests for its state and allows
|
||||
* asynchronous cancellation and requesting.
|
||||
*
|
||||
* <p> To create a new instance of {@link TestSubscriber}, you have the choice between
|
||||
* these static methods:
|
||||
* A Subscriber implementation that hosts assertion tests for its state and allows asynchronous cancellation and
|
||||
* requesting.
|
||||
* <p>
|
||||
* To create a new instance of {@link TestSubscriber}, you have the choice between these static methods:
|
||||
* <ul>
|
||||
* <li>{@link TestSubscriber#subscribe(Publisher)}: create a new {@link TestSubscriber},
|
||||
* subscribe to it with the specified {@link Publisher} and requests an unbounded
|
||||
* number of elements.</li>
|
||||
* <li>{@link TestSubscriber#subscribe(Publisher, long)}: create a new {@link TestSubscriber},
|
||||
* subscribe to it with the specified {@link Publisher} and requests {@code n} elements
|
||||
* (can be 0 if you want no initial demand).
|
||||
* <li>{@link TestSubscriber#create()}: create a new {@link TestSubscriber} and requests
|
||||
* an unbounded number of elements.</li>
|
||||
* <li>{@link TestSubscriber#create(long)}: create a new {@link TestSubscriber} and
|
||||
* requests {@code n} elements (can be 0 if you want no initial demand).
|
||||
* <li>{@link TestSubscriber#subscribe(Publisher)}: create a new {@link TestSubscriber}, subscribe to it with the
|
||||
* specified {@link Publisher} and requests an unbounded number of elements.</li>
|
||||
* <li>{@link TestSubscriber#subscribe(Publisher, long)}: create a new {@link TestSubscriber}, subscribe to it with the
|
||||
* specified {@link Publisher} and requests {@code n} elements (can be 0 if you want no initial demand).
|
||||
* <li>{@link TestSubscriber#create()}: create a new {@link TestSubscriber} and requests an unbounded number of
|
||||
* elements.</li>
|
||||
* <li>{@link TestSubscriber#create(long)}: create a new {@link TestSubscriber} and requests {@code n} elements (can be
|
||||
* 0 if you want no initial demand).
|
||||
* </ul>
|
||||
* <p>
|
||||
* If you are testing asynchronous publishers, don't forget to use one of the {@code await*()} methods to wait for the
|
||||
* data to assert.
|
||||
* <p>
|
||||
* You can extend this class but only the onNext, onError and onComplete can be overridden. You can call
|
||||
* {@link #request(long)} and {@link #cancel()} from any thread or from within the overridable methods but you should
|
||||
* avoid calling the assertXXX methods asynchronously.
|
||||
* <p>
|
||||
* Usage:
|
||||
*
|
||||
* <p>If you are testing asynchronous publishers, don't forget to use one of the
|
||||
* {@code await*()} methods to wait for the data to assert.
|
||||
*
|
||||
* <p> You can extend this class but only the onNext, onError and onComplete can be overridden.
|
||||
* You can call {@link #request(long)} and {@link #cancel()} from any thread or from within
|
||||
* the overridable methods but you should avoid calling the assertXXX methods asynchronously.
|
||||
*
|
||||
* <p>Usage:
|
||||
* <pre>
|
||||
* {@code
|
||||
* TestSubscriber
|
||||
@@ -94,34 +89,27 @@ import org.reactivestreams.Subscription;
|
||||
* </pre>
|
||||
*
|
||||
* @param <T> the value type.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author David Karnok
|
||||
* @author Anatoly Kadyshev
|
||||
* @author Stephane Maldini
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class TestSubscriber<T>
|
||||
implements Subscriber<T>, Subscription, Trackable, Receiver {
|
||||
public class TestSubscriber<T> implements Subscriber<T>, Subscription, Trackable, Receiver {
|
||||
|
||||
/**
|
||||
* Default timeout for waiting next values to be received
|
||||
*/
|
||||
public static final Duration DEFAULT_VALUES_TIMEOUT = Duration.ofSeconds(3);
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final AtomicLongFieldUpdater<TestSubscriber> REQUESTED =
|
||||
AtomicLongFieldUpdater.newUpdater(TestSubscriber.class, "requested");
|
||||
@SuppressWarnings("rawtypes") private static final AtomicLongFieldUpdater<TestSubscriber> REQUESTED = AtomicLongFieldUpdater
|
||||
.newUpdater(TestSubscriber.class, "requested");
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final AtomicReferenceFieldUpdater<TestSubscriber, List> NEXT_VALUES =
|
||||
AtomicReferenceFieldUpdater.newUpdater(TestSubscriber.class, List.class,
|
||||
"values");
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final AtomicReferenceFieldUpdater<TestSubscriber, Subscription> S =
|
||||
AtomicReferenceFieldUpdater.newUpdater(TestSubscriber.class, Subscription.class, "s");
|
||||
@SuppressWarnings("rawtypes") private static final AtomicReferenceFieldUpdater<TestSubscriber, List> NEXT_VALUES = AtomicReferenceFieldUpdater
|
||||
.newUpdater(TestSubscriber.class, List.class, "values");
|
||||
|
||||
@SuppressWarnings("rawtypes") private static final AtomicReferenceFieldUpdater<TestSubscriber, Subscription> S = AtomicReferenceFieldUpdater
|
||||
.newUpdater(TestSubscriber.class, Subscription.class, "s");
|
||||
|
||||
private final List<Throwable> errors = new LinkedList<>();
|
||||
|
||||
@@ -160,23 +148,20 @@ public class TestSubscriber<T>
|
||||
|
||||
private boolean valuesStorage = true;
|
||||
|
||||
// ==============================================================================================================
|
||||
// Static methods
|
||||
// ==============================================================================================================
|
||||
// ==============================================================================================================
|
||||
// Static methods
|
||||
// ==============================================================================================================
|
||||
|
||||
/**
|
||||
* Blocking method that waits until {@code conditionSupplier} returns true, or if it
|
||||
* does not before the specified timeout, throws an {@link AssertionError} with the
|
||||
* specified error message supplier.
|
||||
* Blocking method that waits until {@code conditionSupplier} returns true, or if it does not before the specified
|
||||
* timeout, throws an {@link AssertionError} with the specified error message supplier.
|
||||
*
|
||||
* @param timeout the timeout duration
|
||||
* @param errorMessageSupplier the error message supplier
|
||||
* @param conditionSupplier condition to break out of the wait loop
|
||||
*
|
||||
* @throws AssertionError
|
||||
*/
|
||||
public static void await(Duration timeout, Supplier<String> errorMessageSupplier,
|
||||
BooleanSupplier conditionSupplier) {
|
||||
public static void await(Duration timeout, Supplier<String> errorMessageSupplier, BooleanSupplier conditionSupplier) {
|
||||
|
||||
Objects.requireNonNull(errorMessageSupplier);
|
||||
Objects.requireNonNull(conditionSupplier);
|
||||
@@ -190,30 +175,24 @@ public class TestSubscriber<T>
|
||||
}
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
while (System.nanoTime() - startTime < timeoutNs);
|
||||
} while (System.nanoTime() - startTime < timeoutNs);
|
||||
throw new AssertionError(errorMessageSupplier.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocking method that waits until {@code conditionSupplier} returns true, or if it
|
||||
* does not before the specified timeout, throw an {@link AssertionError} with the
|
||||
* specified error message.
|
||||
* Blocking method that waits until {@code conditionSupplier} returns true, or if it does not before the specified
|
||||
* timeout, throw an {@link AssertionError} with the specified error message.
|
||||
*
|
||||
* @param timeout the timeout duration
|
||||
* @param errorMessage the error message
|
||||
* @param conditionSupplier condition to break out of the wait loop
|
||||
*
|
||||
* @throws AssertionError
|
||||
*/
|
||||
public static void await(Duration timeout,
|
||||
final String errorMessage,
|
||||
BooleanSupplier conditionSupplier) {
|
||||
public static void await(Duration timeout, final String errorMessage, BooleanSupplier conditionSupplier) {
|
||||
await(timeout, new Supplier<String>() {
|
||||
@Override
|
||||
public String get() {
|
||||
@@ -224,8 +203,10 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Create a new {@link TestSubscriber} that requests an unbounded number of elements.
|
||||
* <p>Be sure at least a publisher has subscribed to it via {@link Publisher#subscribe(Subscriber)}
|
||||
* before use assert methods.
|
||||
* <p>
|
||||
* Be sure at least a publisher has subscribed to it via {@link Publisher#subscribe(Subscriber)} before use assert
|
||||
* methods.
|
||||
*
|
||||
* @see #subscribe(Publisher)
|
||||
* @param <T> the observed value type
|
||||
* @return a fresh TestSubscriber instance
|
||||
@@ -235,25 +216,28 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link TestSubscriber} that requests initially {@code n} elements. You
|
||||
* can then manage the demand with {@link Subscription#request(long)}.
|
||||
* <p>Be sure at least a publisher has subscribed to it via {@link Publisher#subscribe(Subscriber)}
|
||||
* before use assert methods.
|
||||
* Create a new {@link TestSubscriber} that requests initially {@code n} elements. You can then manage the demand with
|
||||
* {@link Subscription#request(long)}.
|
||||
* <p>
|
||||
* Be sure at least a publisher has subscribed to it via {@link Publisher#subscribe(Subscriber)} before use assert
|
||||
* methods.
|
||||
*
|
||||
* @param n Number of elements to request (can be 0 if you want no initial demand).
|
||||
* @see #subscribe(Publisher, long)
|
||||
* @param <T> the observed value type
|
||||
* @return a fresh TestSubscriber instance
|
||||
* @param <T> the observed value type
|
||||
* @return a fresh TestSubscriber instance
|
||||
*/
|
||||
public static <T> TestSubscriber<T> create(long n) {
|
||||
return new TestSubscriber<>(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link TestSubscriber} that requests an unbounded number of elements,
|
||||
* and make the specified {@code publisher} subscribe to it.
|
||||
* Create a new {@link TestSubscriber} that requests an unbounded number of elements, and make the specified
|
||||
* {@code publisher} subscribe to it.
|
||||
*
|
||||
* @param publisher The publisher to subscribe with
|
||||
* @param <T> the observed value type
|
||||
* @return a fresh TestSubscriber instance
|
||||
* @param <T> the observed value type
|
||||
* @return a fresh TestSubscriber instance
|
||||
*/
|
||||
public static <T> TestSubscriber<T> subscribe(Publisher<T> publisher) {
|
||||
TestSubscriber<T> subscriber = new TestSubscriber<>();
|
||||
@@ -262,13 +246,13 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link TestSubscriber} that requests initially {@code n} elements,
|
||||
* and make the specified {@code publisher} subscribe to it. You can then manage the
|
||||
* demand with {@link Subscription#request(long)}.
|
||||
* Create a new {@link TestSubscriber} that requests initially {@code n} elements, and make the specified
|
||||
* {@code publisher} subscribe to it. You can then manage the demand with {@link Subscription#request(long)}.
|
||||
*
|
||||
* @param publisher The publisher to subscribe with
|
||||
* @param n Number of elements to request (can be 0 if you want no initial demand).
|
||||
* @param <T> the observed value type
|
||||
* @return a fresh TestSubscriber instance
|
||||
* @param <T> the observed value type
|
||||
* @return a fresh TestSubscriber instance
|
||||
*/
|
||||
public static <T> TestSubscriber<T> subscribe(Publisher<T> publisher, long n) {
|
||||
TestSubscriber<T> subscriber = new TestSubscriber<>(n);
|
||||
@@ -276,12 +260,12 @@ public class TestSubscriber<T>
|
||||
return subscriber;
|
||||
}
|
||||
|
||||
// ==============================================================================================================
|
||||
// Private constructors
|
||||
// ==============================================================================================================
|
||||
// ==============================================================================================================
|
||||
// Private constructors
|
||||
// ==============================================================================================================
|
||||
|
||||
private TestSubscriber() {
|
||||
this(Long.MAX_VALUE);
|
||||
this(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
private TestSubscriber(long n) {
|
||||
@@ -291,15 +275,14 @@ public class TestSubscriber<T>
|
||||
REQUESTED.lazySet(this, n);
|
||||
}
|
||||
|
||||
// ==============================================================================================================
|
||||
// Configuration
|
||||
// ==============================================================================================================
|
||||
|
||||
// ==============================================================================================================
|
||||
// Configuration
|
||||
// ==============================================================================================================
|
||||
|
||||
/**
|
||||
* Enable or disabled the values storage. It is enabled by default, and can be disable
|
||||
* in order to be able to perform performance benchmarks or tests with a huge amount
|
||||
* values.
|
||||
* Enable or disabled the values storage. It is enabled by default, and can be disable in order to be able to perform
|
||||
* performance benchmarks or tests with a huge amount values.
|
||||
*
|
||||
* @param enabled enable value storage?
|
||||
* @return this
|
||||
*/
|
||||
@@ -309,8 +292,8 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the timeout in seconds for waiting next values to be received (3 seconds
|
||||
* by default).
|
||||
* Configure the timeout in seconds for waiting next values to be received (3 seconds by default).
|
||||
*
|
||||
* @param timeout the new default value timeout duration
|
||||
* @return this
|
||||
*/
|
||||
@@ -328,12 +311,13 @@ public class TestSubscriber<T>
|
||||
return establishedFusionMode;
|
||||
}
|
||||
|
||||
// ==============================================================================================================
|
||||
// Assertions
|
||||
// ==============================================================================================================
|
||||
// ==============================================================================================================
|
||||
// Assertions
|
||||
// ==============================================================================================================
|
||||
|
||||
/**
|
||||
* Assert a complete successfully signal has been received.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertComplete() {
|
||||
@@ -349,16 +333,15 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the specified values have been received. Values storage should be enabled to
|
||||
* use this method.
|
||||
* Assert the specified values have been received. Values storage should be enabled to use this method.
|
||||
*
|
||||
* @param expectedValues the values to assert
|
||||
* @see #configureValuesStorage(boolean)
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertContainValues(Set<? extends T> expectedValues) {
|
||||
if (!valuesStorage) {
|
||||
throw new IllegalStateException(
|
||||
"Using assertNoValues() requires enabling values storage");
|
||||
throw new IllegalStateException("Using assertNoValues() requires enabling values storage");
|
||||
}
|
||||
if (expectedValues.size() > values.size()) {
|
||||
throw new AssertionError("Actual contains fewer elements" + values, null);
|
||||
@@ -366,17 +349,15 @@ public class TestSubscriber<T>
|
||||
|
||||
Iterator<? extends T> expected = expectedValues.iterator();
|
||||
|
||||
for (; ; ) {
|
||||
for (;;) {
|
||||
boolean n2 = expected.hasNext();
|
||||
if (n2) {
|
||||
T t2 = expected.next();
|
||||
if (!values.contains(t2)) {
|
||||
throw new AssertionError("The element is not contained in the " +
|
||||
"received resuls" +
|
||||
" = " + valueAndClass(t2), null);
|
||||
throw new AssertionError(
|
||||
"The element is not contained in the " + "received resuls" + " = " + valueAndClass(t2), null);
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -385,6 +366,7 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Assert an error signal has been received.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertError() {
|
||||
@@ -401,20 +383,20 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Assert an error signal has been received.
|
||||
*
|
||||
* @param clazz The class of the exception contained in the error signal
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertError(Class<? extends Throwable> clazz) {
|
||||
assertNotComplete();
|
||||
int s = errors.size();
|
||||
int s = errors.size();
|
||||
if (s == 0) {
|
||||
throw new AssertionError("No error", null);
|
||||
}
|
||||
if (s == 1) {
|
||||
Throwable e = errors.get(0);
|
||||
if (!clazz.isInstance(e)) {
|
||||
throw new AssertionError("Error class incompatible: expected = " +
|
||||
clazz + ", actual = " + e, null);
|
||||
throw new AssertionError("Error class incompatible: expected = " + clazz + ", actual = " + e, null);
|
||||
}
|
||||
}
|
||||
if (s > 1) {
|
||||
@@ -430,11 +412,10 @@ public class TestSubscriber<T>
|
||||
assertionError("No error", null);
|
||||
}
|
||||
if (s == 1) {
|
||||
if (!Objects.equals(message,
|
||||
errors.get(0)
|
||||
.getMessage())) {
|
||||
assertionError("Error class incompatible: expected = \"" + message +
|
||||
"\", actual = \"" + errors.get(0).getMessage() + "\"", null);
|
||||
if (!Objects.equals(message, errors.get(0).getMessage())) {
|
||||
assertionError(
|
||||
"Error class incompatible: expected = \"" + message + "\", actual = \"" + errors.get(0).getMessage() + "\"",
|
||||
null);
|
||||
}
|
||||
}
|
||||
if (s > 1) {
|
||||
@@ -446,8 +427,9 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Assert an error signal has been received.
|
||||
* @param expectation A method that can verify the exception contained in the error signal
|
||||
* and throw an exception (like an {@link AssertionError}) if the exception is not valid.
|
||||
*
|
||||
* @param expectation A method that can verify the exception contained in the error signal and throw an exception
|
||||
* (like an {@link AssertionError}) if the exception is not valid.
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertErrorWith(Consumer<? super Throwable> expectation) {
|
||||
@@ -491,8 +473,8 @@ public class TestSubscriber<T>
|
||||
|
||||
public final TestSubscriber<T> assertFusionMode(int expectedMode) {
|
||||
if (establishedFusionMode != expectedMode) {
|
||||
throw new AssertionError("Wrong fusion mode: expected: " + fusionModeName(
|
||||
expectedMode) + ", actual: " + fusionModeName(establishedFusionMode));
|
||||
throw new AssertionError("Wrong fusion mode: expected: " + fusionModeName(expectedMode) + ", actual: "
|
||||
+ fusionModeName(establishedFusionMode));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -511,7 +493,8 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Assert no error signal has been received.
|
||||
* @return this
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertNoError() {
|
||||
int s = errors.size();
|
||||
@@ -533,14 +516,14 @@ public class TestSubscriber<T>
|
||||
*/
|
||||
public final TestSubscriber<T> assertNoValues() {
|
||||
if (valueCount != 0) {
|
||||
throw new AssertionError("No values expected but received: [length = " + values.size() + "] " + values,
|
||||
null);
|
||||
throw new AssertionError("No values expected but received: [length = " + values.size() + "] " + values, null);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the upstream was not a Fuseable source.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertNonFuseableSource() {
|
||||
@@ -552,6 +535,7 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Assert no complete successfully signal has been received.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertNotComplete() {
|
||||
@@ -585,6 +569,7 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Assert no complete successfully or error signal has been received.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertNotTerminated() {
|
||||
@@ -596,6 +581,7 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Assert subscription occurred (once).
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertSubscribed() {
|
||||
@@ -613,6 +599,7 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Assert either complete successfully or error signal has been received.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertTerminated() {
|
||||
@@ -626,25 +613,22 @@ public class TestSubscriber<T>
|
||||
* Assert {@code n} values has been received.
|
||||
*
|
||||
* @param n the expected value count
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertValueCount(long n) {
|
||||
if (valueCount != n) {
|
||||
throw new AssertionError("Different value count: expected = " + n + ", actual = " + valueCount,
|
||||
null);
|
||||
throw new AssertionError("Different value count: expected = " + n + ", actual = " + valueCount, null);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the specified values have been received in the same order read by the
|
||||
* passed {@link Iterable}. Values storage
|
||||
* should be enabled to
|
||||
* use this method.
|
||||
* Assert the specified values have been received in the same order read by the passed {@link Iterable}. Values
|
||||
* storage should be enabled to use this method.
|
||||
*
|
||||
* @param expectedSequence the values to assert
|
||||
* @see #configureValuesStorage(boolean)
|
||||
* @return this
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> assertValueSequence(Iterable<? extends T> expectedSequence) {
|
||||
if (!valuesStorage) {
|
||||
@@ -653,16 +637,15 @@ public class TestSubscriber<T>
|
||||
Iterator<T> actual = values.iterator();
|
||||
Iterator<? extends T> expected = expectedSequence.iterator();
|
||||
int i = 0;
|
||||
for (; ; ) {
|
||||
for (;;) {
|
||||
boolean n1 = actual.hasNext();
|
||||
boolean n2 = expected.hasNext();
|
||||
if (n1 && n2) {
|
||||
T t1 = actual.next();
|
||||
T t2 = expected.next();
|
||||
if (!Objects.equals(t1, t2)) {
|
||||
throw new AssertionError("The element with index " + i + " does not match: expected = " + valueAndClass(t2) + ", actual = "
|
||||
+ valueAndClass(
|
||||
t1), null);
|
||||
throw new AssertionError("The element with index " + i + " does not match: expected = " + valueAndClass(t2)
|
||||
+ ", actual = " + valueAndClass(t1), null);
|
||||
}
|
||||
i++;
|
||||
} else if (n1 && !n2) {
|
||||
@@ -677,13 +660,11 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the specified values have been received in the declared order. Values
|
||||
* storage should be enabled to use this method.
|
||||
* Assert the specified values have been received in the declared order. Values storage should be enabled to use this
|
||||
* method.
|
||||
*
|
||||
* @param expectedValues the values to assert
|
||||
*
|
||||
* @return this
|
||||
*
|
||||
* @see #configureValuesStorage(boolean)
|
||||
*/
|
||||
@SafeVarargs
|
||||
@@ -692,25 +673,23 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the specified values have been received in the declared order. Values
|
||||
* storage should be enabled to use this method.
|
||||
*
|
||||
* @param expectations One or more methods that can verify the values and throw a
|
||||
* exception (like an {@link AssertionError}) if the value is not valid.
|
||||
* Assert the specified values have been received in the declared order. Values storage should be enabled to use this
|
||||
* method.
|
||||
*
|
||||
* @param expectations One or more methods that can verify the values and throw a exception (like an
|
||||
* {@link AssertionError}) if the value is not valid.
|
||||
* @return this
|
||||
*
|
||||
* @see #configureValuesStorage(boolean)
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final TestSubscriber<T> assertValuesWith(Consumer<T>... expectations) {
|
||||
if (!valuesStorage) {
|
||||
throw new IllegalStateException(
|
||||
"Using assertNoValues() requires enabling values storage");
|
||||
throw new IllegalStateException("Using assertNoValues() requires enabling values storage");
|
||||
}
|
||||
final int expectedValueCount = expectations.length;
|
||||
if (expectedValueCount != values.size()) {
|
||||
throw new AssertionError("Different value count: expected = " + expectedValueCount + ", actual = " + valueCount, null);
|
||||
throw new AssertionError("Different value count: expected = " + expectedValueCount + ", actual = " + valueCount,
|
||||
null);
|
||||
}
|
||||
for (int i = 0; i < expectedValueCount; i++) {
|
||||
Consumer<T> consumer = expectations[i];
|
||||
@@ -720,13 +699,14 @@ public class TestSubscriber<T>
|
||||
return this;
|
||||
}
|
||||
|
||||
// ==============================================================================================================
|
||||
// Await methods
|
||||
// ==============================================================================================================
|
||||
// ==============================================================================================================
|
||||
// Await methods
|
||||
// ==============================================================================================================
|
||||
|
||||
/**
|
||||
* Blocking method that waits until a complete successfully or error signal is received.
|
||||
* @return this
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> await() {
|
||||
if (cdl.getCount() == 0) {
|
||||
@@ -741,10 +721,10 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocking method that waits until a complete successfully or error signal is received
|
||||
* or until a timeout occurs.
|
||||
* Blocking method that waits until a complete successfully or error signal is received or until a timeout occurs.
|
||||
*
|
||||
* @param timeout The timeout value
|
||||
* @return this
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> await(Duration timeout) {
|
||||
if (cdl.getCount() == 0) {
|
||||
@@ -755,8 +735,7 @@ public class TestSubscriber<T>
|
||||
throw new AssertionError("No complete or error signal before timeout");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
} catch (InterruptedException ex) {
|
||||
throw new AssertionError("Wait interrupted", ex);
|
||||
}
|
||||
}
|
||||
@@ -765,23 +744,15 @@ public class TestSubscriber<T>
|
||||
* Blocking method that waits until {@code n} next values have been received.
|
||||
*
|
||||
* @param n the value count to assert
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public final TestSubscriber<T> awaitAndAssertNextValueCount(final long n) {
|
||||
await(valuesTimeout, () -> {
|
||||
if(valuesStorage){
|
||||
return String.format("%d out of %d next values received within %d, " +
|
||||
"values : %s",
|
||||
valueCount - nextValueAssertedCount,
|
||||
n,
|
||||
valuesTimeout.toMillis(),
|
||||
values.toString()
|
||||
);
|
||||
if (valuesStorage) {
|
||||
return String.format("%d out of %d next values received within %d, " + "values : %s",
|
||||
valueCount - nextValueAssertedCount, n, valuesTimeout.toMillis(), values.toString());
|
||||
}
|
||||
return String.format("%d out of %d next values received within %d",
|
||||
valueCount - nextValueAssertedCount,
|
||||
n,
|
||||
return String.format("%d out of %d next values received within %d", valueCount - nextValueAssertedCount, n,
|
||||
valuesTimeout.toMillis());
|
||||
}, () -> valueCount >= (nextValueAssertedCount + n));
|
||||
nextValueAssertedCount += n;
|
||||
@@ -789,11 +760,10 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocking method that waits until {@code n} next values have been received (n is the
|
||||
* number of values provided) to assert them.
|
||||
* Blocking method that waits until {@code n} next values have been received (n is the number of values provided) to
|
||||
* assert them.
|
||||
*
|
||||
* @param values the values to assert
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
@SafeVarargs
|
||||
@@ -805,10 +775,7 @@ public class TestSubscriber<T>
|
||||
final T expectedValue = values[i];
|
||||
expectations.add(actualValue -> {
|
||||
if (!actualValue.equals(expectedValue)) {
|
||||
throw new AssertionError(String.format(
|
||||
"Expected Next signal: %s, but got: %s",
|
||||
expectedValue,
|
||||
actualValue));
|
||||
throw new AssertionError(String.format("Expected Next signal: %s, but got: %s", expectedValue, actualValue));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -817,42 +784,35 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocking method that waits until {@code n} next values have been received
|
||||
* (n is the number of expectations provided) to assert them.
|
||||
* @param expectations One or more methods that can verify the values and throw a
|
||||
* exception (like an {@link AssertionError}) if the value is not valid.
|
||||
* @return this
|
||||
* Blocking method that waits until {@code n} next values have been received (n is the number of expectations
|
||||
* provided) to assert them.
|
||||
*
|
||||
* @param expectations One or more methods that can verify the values and throw a exception (like an
|
||||
* {@link AssertionError}) if the value is not valid.
|
||||
* @return this
|
||||
*/
|
||||
@SafeVarargs
|
||||
public final TestSubscriber<T> awaitAndAssertNextValuesWith(Consumer<T>... expectations) {
|
||||
valuesStorage = true;
|
||||
final int expectedValueCount = expectations.length;
|
||||
await(valuesTimeout, () -> {
|
||||
if(valuesStorage){
|
||||
return String.format("%d out of %d next values received within %d, " +
|
||||
"values : %s",
|
||||
valueCount - nextValueAssertedCount,
|
||||
expectedValueCount,
|
||||
valuesTimeout.toMillis(),
|
||||
values.toString()
|
||||
);
|
||||
if (valuesStorage) {
|
||||
return String.format("%d out of %d next values received within %d, " + "values : %s",
|
||||
valueCount - nextValueAssertedCount, expectedValueCount, valuesTimeout.toMillis(), values.toString());
|
||||
}
|
||||
return String.format("%d out of %d next values received within %d ms",
|
||||
valueCount - nextValueAssertedCount,
|
||||
expectedValueCount,
|
||||
valuesTimeout.toMillis());
|
||||
return String.format("%d out of %d next values received within %d ms", valueCount - nextValueAssertedCount,
|
||||
expectedValueCount, valuesTimeout.toMillis());
|
||||
}, () -> valueCount >= (nextValueAssertedCount + expectedValueCount));
|
||||
List<T> nextValuesSnapshot;
|
||||
List<T> empty = new ArrayList<>();
|
||||
for(;;){
|
||||
for (;;) {
|
||||
nextValuesSnapshot = values;
|
||||
if(NEXT_VALUES.compareAndSet(this, values, empty)){
|
||||
if (NEXT_VALUES.compareAndSet(this, values, empty)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (nextValuesSnapshot.size() < expectedValueCount) {
|
||||
throw new AssertionError(String.format("Expected %d number of signals but received %d",
|
||||
expectedValueCount,
|
||||
throw new AssertionError(String.format("Expected %d number of signals but received %d", expectedValueCount,
|
||||
nextValuesSnapshot.size()));
|
||||
}
|
||||
for (int i = 0; i < expectedValueCount; i++) {
|
||||
@@ -864,9 +824,9 @@ public class TestSubscriber<T>
|
||||
return this;
|
||||
}
|
||||
|
||||
// ==============================================================================================================
|
||||
// Overrides
|
||||
// ==============================================================================================================
|
||||
// ==============================================================================================================
|
||||
// Overrides
|
||||
// ==============================================================================================================
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
@@ -909,7 +869,7 @@ public class TestSubscriber<T>
|
||||
@Override
|
||||
public void onNext(T t) {
|
||||
if (establishedFusionMode == Fuseable.ASYNC) {
|
||||
for (; ; ) {
|
||||
for (;;) {
|
||||
t = qs.poll();
|
||||
if (t == null) {
|
||||
break;
|
||||
@@ -917,28 +877,23 @@ public class TestSubscriber<T>
|
||||
valueCount++;
|
||||
if (valuesStorage) {
|
||||
List<T> nextValuesSnapshot;
|
||||
for (; ; ) {
|
||||
for (;;) {
|
||||
nextValuesSnapshot = values;
|
||||
nextValuesSnapshot.add(t);
|
||||
if (NEXT_VALUES.compareAndSet(this,
|
||||
nextValuesSnapshot,
|
||||
nextValuesSnapshot)) {
|
||||
if (NEXT_VALUES.compareAndSet(this, nextValuesSnapshot, nextValuesSnapshot)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
valueCount++;
|
||||
if (valuesStorage) {
|
||||
List<T> nextValuesSnapshot;
|
||||
for (; ; ) {
|
||||
for (;;) {
|
||||
nextValuesSnapshot = values;
|
||||
nextValuesSnapshot.add(t);
|
||||
if (NEXT_VALUES.compareAndSet(this,
|
||||
nextValuesSnapshot,
|
||||
nextValuesSnapshot)) {
|
||||
if (NEXT_VALUES.compareAndSet(this, nextValuesSnapshot, nextValuesSnapshot)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -954,12 +909,11 @@ public class TestSubscriber<T>
|
||||
if (requestMode >= 0) {
|
||||
if (!setWithoutRequesting(s)) {
|
||||
if (!isCancelled()) {
|
||||
errors.add(new IllegalStateException("Subscription already set: " +
|
||||
subscriptionCount));
|
||||
errors.add(new IllegalStateException("Subscription already set: " + subscriptionCount));
|
||||
}
|
||||
} else {
|
||||
if (s instanceof Fuseable.QueueSubscription) {
|
||||
this.qs = (Fuseable.QueueSubscription<T>)s;
|
||||
this.qs = (Fuseable.QueueSubscription<T>) s;
|
||||
|
||||
int m = qs.requestFusion(requestMode);
|
||||
establishedFusionMode = m;
|
||||
@@ -974,20 +928,17 @@ public class TestSubscriber<T>
|
||||
|
||||
onNext(v);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
requestDeferred();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
requestDeferred();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!set(s)) {
|
||||
if (!isCancelled()) {
|
||||
errors.add(new IllegalStateException("Subscription already set: " +
|
||||
subscriptionCount));
|
||||
errors.add(new IllegalStateException("Subscription already set: " + subscriptionCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1008,8 +959,8 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup what fusion mode should be requested from the incomining
|
||||
* Subscription if it happens to be QueueSubscription
|
||||
* Setup what fusion mode should be requested from the incomining Subscription if it happens to be QueueSubscription
|
||||
*
|
||||
* @param requestMode the mode to request, see Fuseable constants
|
||||
* @return this
|
||||
*/
|
||||
@@ -1023,10 +974,9 @@ public class TestSubscriber<T>
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
// ==============================================================================================================
|
||||
// Non public methods
|
||||
// ==============================================================================================================
|
||||
// ==============================================================================================================
|
||||
// Non public methods
|
||||
// ==============================================================================================================
|
||||
|
||||
protected final void normalRequest(long n) {
|
||||
Subscription a = s;
|
||||
@@ -1101,6 +1051,7 @@ public class TestSubscriber<T>
|
||||
|
||||
/**
|
||||
* Sets the Subscription once but does not request anything.
|
||||
*
|
||||
* @param s the Subscription to set
|
||||
* @return true if successful, false if the current subscription is not null
|
||||
*/
|
||||
@@ -1125,12 +1076,11 @@ public class TestSubscriber<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares and throws an AssertionError exception based on the message, cause, the
|
||||
* active state and the potential errors so far.
|
||||
* Prepares and throws an AssertionError exception based on the message, cause, the active state and the potential
|
||||
* errors so far.
|
||||
*
|
||||
* @param message the message
|
||||
* @param cause the optional Throwable cause
|
||||
*
|
||||
* @throws AssertionError as expected
|
||||
*/
|
||||
protected final void assertionError(String message, Throwable cause) {
|
||||
@@ -1143,9 +1093,7 @@ public class TestSubscriber<T>
|
||||
|
||||
List<Throwable> err = errors;
|
||||
if (!err.isEmpty()) {
|
||||
b.append(" (+ ")
|
||||
.append(err.size())
|
||||
.append(" errors)");
|
||||
b.append(" (+ ").append(err.size()).append(" errors)");
|
||||
}
|
||||
AssertionError e = new AssertionError(b.toString(), cause);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user