DATACASS-56 - Polish.
This commit is contained in:
@@ -113,8 +113,9 @@ public interface AsyncCassandraOperations {
|
||||
<T> ListenableFuture<List<T>> select(Statement statement, Class<T> entityClass) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a {@code SELECT} query with paging and convert the resulting items to a {@link Slice} of entities. A sliced
|
||||
* query translates the effective {@link Statement#getFetchSize() fetch size} to the page size.
|
||||
* Execute a {@code SELECT} query with paging and convert the result set to a {@link Slice} of entities.
|
||||
*
|
||||
* A sliced query translates the effective {@link Statement#getFetchSize() fetch size} to the page size.
|
||||
*
|
||||
* @param statement the CQL statement, must not be {@literal null}.
|
||||
* @param entityClass The entity type must not be {@literal null}.
|
||||
@@ -162,7 +163,7 @@ public interface AsyncCassandraOperations {
|
||||
<T> ListenableFuture<List<T>> select(Query query, Class<T> entityClass) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a {@code SELECT} query with paging and convert the resulting items to a {@link Slice} of entities.
|
||||
* Execute a {@code SELECT} query with paging and convert the result set to a {@link Slice} of entities.
|
||||
*
|
||||
* @param query the query object used to create a CQL statement, must not be {@literal null}.
|
||||
* @param entityClass The entity type must not be {@literal null}.
|
||||
@@ -331,4 +332,5 @@ public interface AsyncCassandraOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
ListenableFuture<Void> truncate(Class<?> entityClass) throws DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ import com.datastax.driver.core.querybuilder.Update;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.cassandra.core.AsyncCassandraOperations
|
||||
* @since 2.0
|
||||
*/
|
||||
public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
@@ -267,6 +268,7 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
ListenableFuture<ResultSet> resultSet = getAsyncCqlOperations().queryForResultSet(statement);
|
||||
|
||||
CassandraConverter converter = getConverter();
|
||||
|
||||
return new MappingListenableFutureAdapter<>(resultSet, rs -> QueryUtils.readSlice(rs,
|
||||
@@ -325,7 +327,7 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return slice(statementFactory.select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
return slice(this.statementFactory.select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
entityClass);
|
||||
}
|
||||
|
||||
@@ -535,8 +537,8 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
Truncate truncate = QueryBuilder
|
||||
.truncate(getMappingContext().getRequiredPersistentEntity(entityClass).getTableName().toCql());
|
||||
Truncate truncate = QueryBuilder.truncate(getMappingContext().getRequiredPersistentEntity(entityClass)
|
||||
.getTableName().toCql());
|
||||
|
||||
return new MappingListenableFutureAdapter<>(getAsyncCqlOperations().execute(truncate), aBoolean -> null);
|
||||
}
|
||||
@@ -559,8 +561,9 @@ public class AsyncCassandraTemplate implements AsyncCassandraOperations {
|
||||
}
|
||||
}
|
||||
|
||||
return getAsyncCqlOperations().execute((AsyncSessionCallback<Integer>) session -> AsyncResult
|
||||
.forValue(session.getCluster().getConfiguration().getQueryOptions().getFetchSize())).completable().join();
|
||||
return getAsyncCqlOperations().execute((AsyncSessionCallback<Integer>) session ->
|
||||
AsyncResult.forValue(session.getCluster().getConfiguration().getQueryOptions().getFetchSize()))
|
||||
.completable().join();
|
||||
}
|
||||
|
||||
static class MappingListenableFutureAdapter<T, S>
|
||||
|
||||
@@ -134,8 +134,9 @@ public interface CassandraOperations {
|
||||
<T> List<T> select(Statement statement, Class<T> entityClass) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a {@code SELECT} query with paging and convert the resulting items to a {@link Slice} of entities. A sliced
|
||||
* query translates the effective {@link Statement#getFetchSize() fetch size} to the page size.
|
||||
* Execute a {@code SELECT} query with paging and convert the result set to a {@link Slice} of entities.
|
||||
*
|
||||
* A sliced query translates the effective {@link Statement#getFetchSize() fetch size} to the page size.
|
||||
*
|
||||
* @param statement the CQL statement, must not be {@literal null}.
|
||||
* @param entityClass The entity type must not be {@literal null}.
|
||||
@@ -186,7 +187,7 @@ public interface CassandraOperations {
|
||||
<T> List<T> select(Query query, Class<T> entityClass) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Execute a {@code SELECT} query with paging and convert the resulting items to a {@link Slice} of entities.
|
||||
* Execute a {@code SELECT} query with paging and convert the result set to a {@link Slice} of entities.
|
||||
*
|
||||
* @param query the query object used to create a CQL statement, must not be {@literal null}.
|
||||
* @param entityClass The entity type must not be {@literal null}.
|
||||
@@ -355,4 +356,5 @@ public interface CassandraOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
*/
|
||||
void truncate(Class<?> entityClass) throws DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.cassandra.SessionFactory;
|
||||
import org.springframework.data.cassandra.core.convert.CassandraConverter;
|
||||
@@ -71,6 +71,7 @@ import com.datastax.driver.core.querybuilder.Update;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.cassandra.core.CassandraOperations
|
||||
* @since 2.0
|
||||
*/
|
||||
public class CassandraTemplate implements CassandraOperations {
|
||||
@@ -255,6 +256,7 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
ResultSet resultSet = getCqlOperations().queryForResultSet(statement);
|
||||
|
||||
CassandraConverter converter = getConverter();
|
||||
|
||||
return QueryUtils.readSlice(resultSet, (row, rowNum) -> converter.read(entityClass, row), 0,
|
||||
@@ -308,7 +310,7 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return slice(statementFactory.select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
return slice(this.statementFactory.select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
entityClass);
|
||||
}
|
||||
|
||||
@@ -541,15 +543,14 @@ public class CassandraTemplate implements CassandraOperations {
|
||||
}
|
||||
|
||||
if (getCqlOperations() instanceof CassandraAccessor) {
|
||||
|
||||
CassandraAccessor accessor = (CassandraAccessor) getCqlOperations();
|
||||
if (accessor.getFetchSize() != -1) {
|
||||
return accessor.getFetchSize();
|
||||
}
|
||||
}
|
||||
|
||||
return getCqlOperations().execute(
|
||||
(SessionCallback<Integer>) session -> session.getCluster().getConfiguration().getQueryOptions().getFetchSize());
|
||||
return getCqlOperations().execute((SessionCallback<Integer>) session ->
|
||||
session.getCluster().getConfiguration().getQueryOptions().getFetchSize());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.WriteOptions;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -42,9 +43,19 @@ public class InsertOptions extends WriteOptions {
|
||||
@Nullable Boolean tracing, @Nullable Integer fetchSize, Duration readTimeout, Duration ttl, boolean ifNotExists) {
|
||||
|
||||
super(consistencyLevel, retryPolicy, tracing, fetchSize, readTimeout, ttl);
|
||||
|
||||
this.ifNotExists = ifNotExists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link InsertOptionsBuilder}.
|
||||
*
|
||||
* @return a new {@link InsertOptionsBuilder}.
|
||||
*/
|
||||
public static InsertOptionsBuilder builder() {
|
||||
return new InsertOptionsBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default {@link InsertOptions}.
|
||||
*
|
||||
@@ -55,15 +66,6 @@ public class InsertOptions extends WriteOptions {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link InsertOptionsBuilder}.
|
||||
*
|
||||
* @return a new {@link InsertOptionsBuilder}.
|
||||
*/
|
||||
public static InsertOptionsBuilder builder() {
|
||||
return new InsertOptionsBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link InsertOptionsBuilder} to mutate properties of this {@link InsertOptions}.
|
||||
*
|
||||
@@ -96,6 +98,7 @@ public class InsertOptions extends WriteOptions {
|
||||
private InsertOptionsBuilder(InsertOptions insertOptions) {
|
||||
|
||||
super(insertOptions);
|
||||
|
||||
this.ifNotExists = insertOptions.ifNotExists;
|
||||
}
|
||||
|
||||
@@ -177,7 +180,8 @@ public class InsertOptions extends WriteOptions {
|
||||
* @return a new {@link InsertOptions} with the configured values
|
||||
*/
|
||||
public InsertOptions build() {
|
||||
return new InsertOptions(consistencyLevel, retryPolicy, tracing, fetchSize, readTimeout, ttl, ifNotExists);
|
||||
return new InsertOptions(this.consistencyLevel, this.retryPolicy, this.tracing,
|
||||
this.fetchSize, this.readTimeout, this.ttl, this.ifNotExists);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,15 +151,16 @@ class QueryUtils {
|
||||
static <T> Slice<T> readSlice(ResultSet resultSet, RowMapper<T> mapper, int page, int pageSize) {
|
||||
|
||||
int toRead = resultSet.getAvailableWithoutFetching();
|
||||
|
||||
List<T> result = new ArrayList<>(toRead);
|
||||
|
||||
for (int i = 0; i < toRead; i++) {
|
||||
|
||||
T element = mapper.mapRow(resultSet.one(), i);
|
||||
for (int index = 0; index < toRead; index++) {
|
||||
T element = mapper.mapRow(resultSet.one(), index);
|
||||
result.add(element);
|
||||
}
|
||||
|
||||
PagingState pagingState = resultSet.getExecutionInfo().getPagingState();
|
||||
|
||||
CassandraPageRequest pageRequest = CassandraPageRequest.of(PageRequest.of(page, pageSize), pagingState);
|
||||
|
||||
return new SliceImpl<>(result, pageRequest, pagingState != null);
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.cassandra.core;
|
||||
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -264,8 +265,8 @@ public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return select(getStatementFactory().select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
entityClass);
|
||||
return select(getStatementFactory().select(query,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)), entityClass);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -277,8 +278,8 @@ public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return selectOne(getStatementFactory().select(query, getMappingContext().getRequiredPersistentEntity(entityClass)),
|
||||
entityClass);
|
||||
return selectOne(getStatementFactory().select(query,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)), entityClass);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -292,8 +293,8 @@ public class ReactiveCassandraTemplate implements ReactiveCassandraOperations {
|
||||
Assert.notNull(update, "Update must not be null");
|
||||
Assert.notNull(entityClass, "Entity type must not be null");
|
||||
|
||||
return getReactiveCqlOperations().execute(
|
||||
getStatementFactory().update(query, update, getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
return getReactiveCqlOperations().execute(getStatementFactory().update(query, update,
|
||||
getMappingContext().getRequiredPersistentEntity(entityClass)));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.WriteOptions;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -42,9 +43,19 @@ public class UpdateOptions extends WriteOptions {
|
||||
@Nullable Boolean tracing, @Nullable Integer fetchSize, Duration readTimeout, Duration ttl, boolean ifExists) {
|
||||
|
||||
super(consistencyLevel, retryPolicy, tracing, fetchSize, readTimeout, ttl);
|
||||
|
||||
this.ifExists = ifExists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link UpdateOptionsBuilder}.
|
||||
*
|
||||
* @return a new {@link UpdateOptionsBuilder}.
|
||||
*/
|
||||
public static UpdateOptionsBuilder builder() {
|
||||
return new UpdateOptionsBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default {@link UpdateOptions}.
|
||||
*
|
||||
@@ -55,15 +66,6 @@ public class UpdateOptions extends WriteOptions {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link UpdateOptionsBuilder}.
|
||||
*
|
||||
* @return a new {@link UpdateOptionsBuilder}.
|
||||
*/
|
||||
public static UpdateOptionsBuilder builder() {
|
||||
return new UpdateOptionsBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link UpdateOptionsBuilder} to mutate properties of this {@link UpdateOptions}.
|
||||
*
|
||||
@@ -96,6 +98,7 @@ public class UpdateOptions extends WriteOptions {
|
||||
private UpdateOptionsBuilder(UpdateOptions updateOptions) {
|
||||
|
||||
super(updateOptions);
|
||||
|
||||
this.ifExists = updateOptions.ifExists;
|
||||
}
|
||||
|
||||
@@ -177,7 +180,8 @@ public class UpdateOptions extends WriteOptions {
|
||||
* @return a new {@link UpdateOptions} with the configured values
|
||||
*/
|
||||
public UpdateOptions build() {
|
||||
return new UpdateOptions(consistencyLevel, retryPolicy, tracing, fetchSize, readTimeout, ttl, ifExists);
|
||||
return new UpdateOptions(this.consistencyLevel, this.retryPolicy, this.tracing,
|
||||
this.fetchSize, this.readTimeout, this.ttl, this.ifExists);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.convert;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -24,8 +22,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -56,6 +54,9 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.datastax.driver.core.CodecRegistry;
|
||||
import com.datastax.driver.core.DataType;
|
||||
import com.datastax.driver.core.Row;
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -38,15 +39,15 @@ public class QueryOptions {
|
||||
|
||||
private static final QueryOptions EMPTY = QueryOptions.builder().build();
|
||||
|
||||
private final @Nullable Boolean tracing;
|
||||
|
||||
private final @Nullable ConsistencyLevel consistencyLevel;
|
||||
|
||||
private final @Nullable RetryPolicy retryPolicy;
|
||||
|
||||
private final @Nullable Boolean tracing;
|
||||
private final Duration readTimeout;
|
||||
|
||||
private final @Nullable Integer fetchSize;
|
||||
|
||||
private final Duration readTimeout;
|
||||
private final @Nullable RetryPolicy retryPolicy;
|
||||
|
||||
protected QueryOptions(@Nullable ConsistencyLevel consistencyLevel, @Nullable RetryPolicy retryPolicy,
|
||||
@Nullable Boolean tracing, @Nullable Integer fetchSize, Duration readTimeout) {
|
||||
@@ -75,16 +76,6 @@ public class QueryOptions {
|
||||
this.readTimeout = Duration.ofMillis(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default {@link QueryOptions}.
|
||||
*
|
||||
* @return default {@link QueryOptions}.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static QueryOptions empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link QueryOptionsBuilder}.
|
||||
*
|
||||
@@ -95,6 +86,16 @@ public class QueryOptions {
|
||||
return new QueryOptionsBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create default {@link QueryOptions}.
|
||||
*
|
||||
* @return default {@link QueryOptions}.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static QueryOptions empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link QueryOptionsBuilder} to mutate properties of this {@link QueryOptions}.
|
||||
*
|
||||
@@ -114,22 +115,13 @@ public class QueryOptions {
|
||||
return this.consistencyLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the driver {@link RetryPolicy}
|
||||
* @since 1.5
|
||||
*/
|
||||
@Nullable
|
||||
protected RetryPolicy getRetryPolicy() {
|
||||
return this.retryPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of rows to fetch per chunking request. May be {@literal null} if not set.
|
||||
* @since 1.5
|
||||
*/
|
||||
@Nullable
|
||||
protected Integer getFetchSize() {
|
||||
return fetchSize;
|
||||
return this.fetchSize;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,6 +132,15 @@ public class QueryOptions {
|
||||
return this.readTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the driver {@link RetryPolicy}
|
||||
* @since 1.5
|
||||
*/
|
||||
@Nullable
|
||||
protected RetryPolicy getRetryPolicy() {
|
||||
return this.retryPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether to enable tracing. May be {@literal null} if not set.
|
||||
*/
|
||||
@@ -156,25 +157,25 @@ public class QueryOptions {
|
||||
*/
|
||||
public static class QueryOptionsBuilder {
|
||||
|
||||
protected @Nullable Boolean tracing;
|
||||
|
||||
protected @Nullable ConsistencyLevel consistencyLevel;
|
||||
|
||||
protected @Nullable RetryPolicy retryPolicy;
|
||||
|
||||
protected @Nullable Boolean tracing;
|
||||
protected Duration readTimeout = Duration.ofMillis(-1);
|
||||
|
||||
protected @Nullable Integer fetchSize;
|
||||
|
||||
protected Duration readTimeout = Duration.ofMillis(-1);
|
||||
protected @Nullable RetryPolicy retryPolicy;
|
||||
|
||||
QueryOptionsBuilder() {}
|
||||
|
||||
QueryOptionsBuilder(QueryOptions queryOptions) {
|
||||
|
||||
this.consistencyLevel = queryOptions.consistencyLevel;
|
||||
this.retryPolicy = queryOptions.retryPolicy;
|
||||
this.tracing = queryOptions.tracing;
|
||||
this.fetchSize = queryOptions.fetchSize;
|
||||
this.readTimeout = queryOptions.readTimeout;
|
||||
this.retryPolicy = queryOptions.retryPolicy;
|
||||
this.tracing = queryOptions.tracing;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,7 +312,8 @@ public class QueryOptions {
|
||||
* @return a new {@link QueryOptions} with the configured values
|
||||
*/
|
||||
public QueryOptions build() {
|
||||
return new QueryOptions(consistencyLevel, retryPolicy, tracing, fetchSize, readTimeout);
|
||||
return new QueryOptions(this.consistencyLevel, this.retryPolicy, this.tracing,
|
||||
this.fetchSize, this.readTimeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -73,6 +74,7 @@ public class WriteOptions extends QueryOptions {
|
||||
@Nullable Boolean tracing, @Nullable Integer fetchSize, Duration readTimeout, Duration ttl) {
|
||||
|
||||
super(consistencyLevel, retryPolicy, tracing, fetchSize, readTimeout);
|
||||
|
||||
this.ttl = ttl;
|
||||
}
|
||||
|
||||
@@ -129,6 +131,7 @@ public class WriteOptions extends QueryOptions {
|
||||
protected WriteOptionsBuilder(WriteOptions writeOptions) {
|
||||
|
||||
super(writeOptions);
|
||||
|
||||
this.ttl = writeOptions.ttl;
|
||||
}
|
||||
|
||||
@@ -239,7 +242,8 @@ public class WriteOptions extends QueryOptions {
|
||||
* @return a new {@link WriteOptions} with the configured values
|
||||
*/
|
||||
public WriteOptions build() {
|
||||
return new WriteOptions(consistencyLevel, retryPolicy, tracing, fetchSize, readTimeout, ttl);
|
||||
return new WriteOptions(this.consistencyLevel, this.retryPolicy, this.tracing,
|
||||
this.fetchSize, this.readTimeout, this.ttl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class CassandraPageRequest extends PageRequest {
|
||||
*/
|
||||
@Nullable
|
||||
public PagingState getPagingState() {
|
||||
return pagingState;
|
||||
return this.pagingState;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,7 +187,7 @@ public class CassandraPageRequest extends PageRequest {
|
||||
* @return {@literal true } if there's a next {@link Pageable} we can access from the current one.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return getPagingState() != null && nextAllowed;
|
||||
return (getPagingState() != null && this.nextAllowed);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -198,7 +198,8 @@ public class CassandraPageRequest extends PageRequest {
|
||||
|
||||
Assert.state(hasNext(), "Cannot create a next page request without a PagingState");
|
||||
|
||||
return new CassandraPageRequest(getPageNumber() + 1, getPageSize(), getSort(), pagingState, false);
|
||||
return new CassandraPageRequest(getPageNumber() + 1, getPageSize(), getSort(),
|
||||
this.pagingState, false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -216,20 +217,25 @@ public class CassandraPageRequest extends PageRequest {
|
||||
* @see org.springframework.data.domain.PageRequest#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
|
||||
if (this == o)
|
||||
if (this == obj) {
|
||||
return true;
|
||||
if (!(o instanceof CassandraPageRequest))
|
||||
}
|
||||
if (!(obj instanceof CassandraPageRequest)) {
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
}
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CassandraPageRequest that = (CassandraPageRequest) o;
|
||||
CassandraPageRequest that = (CassandraPageRequest) obj;
|
||||
|
||||
if (nextAllowed != that.nextAllowed)
|
||||
if (nextAllowed != that.nextAllowed) {
|
||||
return false;
|
||||
return pagingState != null ? pagingState.equals(that.pagingState) : that.pagingState == null;
|
||||
}
|
||||
|
||||
return (pagingState != null ? pagingState.equals(that.pagingState) : that.pagingState == null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -239,8 +245,10 @@ public class CassandraPageRequest extends PageRequest {
|
||||
public int hashCode() {
|
||||
|
||||
int result = super.hashCode();
|
||||
|
||||
result = 31 * result + (pagingState != null ? pagingState.hashCode() : 0);
|
||||
result = 31 * result + (nextAllowed ? 1 : 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.query;
|
||||
|
||||
import static org.springframework.util.ObjectUtils.*;
|
||||
import static java.util.stream.StreamSupport.stream;
|
||||
import static org.springframework.util.ObjectUtils.nullSafeEquals;
|
||||
import static org.springframework.util.ObjectUtils.nullSafeHashCode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -23,7 +25,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.QueryOptions;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -45,19 +46,19 @@ import com.datastax.driver.core.PagingState;
|
||||
*/
|
||||
public class Query implements Filter {
|
||||
|
||||
private final List<CriteriaDefinition> criteriaDefinitions;
|
||||
private final boolean allowFiltering;
|
||||
|
||||
private final Columns columns;
|
||||
|
||||
private final Sort sort;
|
||||
private final List<CriteriaDefinition> criteriaDefinitions;
|
||||
|
||||
private final Optional<Long> limit;
|
||||
|
||||
private final Optional<PagingState> pagingState;
|
||||
|
||||
private final Optional<QueryOptions> queryOptions;
|
||||
|
||||
private final Optional<Long> limit;
|
||||
|
||||
private final boolean allowFiltering;
|
||||
private final Sort sort;
|
||||
|
||||
private Query(List<CriteriaDefinition> criteriaDefinitions, Columns columns, Sort sort,
|
||||
Optional<PagingState> pagingState, Optional<QueryOptions> queryOptions, Optional<Long> limit,
|
||||
@@ -105,7 +106,7 @@ public class Query implements Filter {
|
||||
|
||||
Assert.notNull(criteriaDefinitions, "CriteriaDefinitions must not be null");
|
||||
|
||||
List<CriteriaDefinition> collect = StreamSupport.stream(criteriaDefinitions.spliterator(), false)
|
||||
List<CriteriaDefinition> collect = stream(criteriaDefinitions.spliterator(), false)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new Query(collect, Columns.empty(), Sort.unsorted(), Optional.empty(), Optional.empty(), Optional.empty(),
|
||||
@@ -176,13 +177,13 @@ public class Query implements Filter {
|
||||
|
||||
for (Order order : sort) {
|
||||
if (order.isIgnoreCase()) {
|
||||
throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case; "
|
||||
+ "Apache Cassandra does not support sorting ignoring case currently", order.getProperty()));
|
||||
throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case;"
|
||||
+ " Apache Cassandra does not support sorting ignoring case currently", order.getProperty()));
|
||||
}
|
||||
}
|
||||
|
||||
return new Query(this.criteriaDefinitions, this.columns, this.sort.and(sort), this.pagingState, this.queryOptions,
|
||||
this.limit, this.allowFiltering);
|
||||
return new Query(this.criteriaDefinitions, this.columns, this.sort.and(sort), this.pagingState,
|
||||
this.queryOptions, this.limit, this.allowFiltering);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,8 +287,8 @@ public class Query implements Filter {
|
||||
* @return a new {@link Query} object containing the former settings with {@code allowFiltering} applied.
|
||||
*/
|
||||
public Query withAllowFiltering() {
|
||||
return new Query(this.criteriaDefinitions, this.columns, this.sort, this.pagingState, this.queryOptions, this.limit,
|
||||
true);
|
||||
return new Query(this.criteriaDefinitions, this.columns, this.sort, this.pagingState, this.queryOptions,
|
||||
this.limit, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,8 +331,8 @@ public class Query implements Filter {
|
||||
boolean limitEqual = this.limit == that.limit;
|
||||
boolean allowFilteringEqual = this.allowFiltering == that.allowFiltering;
|
||||
|
||||
return criteriaEqual && columnsEqual && sortEqual && pagingStateEqual && queryOptionsEqual && limitEqual
|
||||
&& allowFilteringEqual;
|
||||
return (criteriaEqual && columnsEqual && sortEqual && pagingStateEqual && queryOptionsEqual && limitEqual
|
||||
&& allowFilteringEqual);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -359,8 +360,8 @@ public class Query implements Filter {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
String query = StreamSupport.stream(this.spliterator(), false) //
|
||||
.map(SerializationUtils::serializeToCqlSafely) //
|
||||
String query = stream(this.spliterator(), false)
|
||||
.map(SerializationUtils::serializeToCqlSafely)
|
||||
.collect(Collectors.joining(" AND "));
|
||||
|
||||
return String.format("Query: %s, Columns: %s, Sort: %s, Limit: %d", query, getColumns(), getSort(), getLimit());
|
||||
|
||||
@@ -65,8 +65,8 @@ public interface CassandraRepository<T, ID> extends CrudRepository<T, ID> {
|
||||
*
|
||||
* @param pageable must not be {@literal null}.
|
||||
* @return a {@link Slice} of entities.
|
||||
* @since 2.0
|
||||
* @see CassandraPageRequest
|
||||
* @since 2.0
|
||||
*/
|
||||
Slice<T> findAll(Pageable pageable);
|
||||
|
||||
@@ -91,4 +91,5 @@ public interface CassandraRepository<T, ID> extends CrudRepository<T, ID> {
|
||||
* @since 2.0
|
||||
*/
|
||||
<S extends T> List<S> insert(Iterable<S> entities);
|
||||
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.datastax.driver.core.querybuilder.Select;
|
||||
* @author Alex Shvid
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @see org.springframework.data.cassandra.repository.CassandraRepository
|
||||
*/
|
||||
public class SimpleCassandraRepository<T, ID> implements CassandraRepository<T, ID> {
|
||||
|
||||
@@ -50,8 +51,8 @@ public class SimpleCassandraRepository<T, ID> implements CassandraRepository<T,
|
||||
private final CassandraOperations operations;
|
||||
|
||||
/**
|
||||
* Create a new {@link SimpleCassandraRepository} for the given {@link CassandraEntityInformation} and
|
||||
* {@link CassandraTemplate}.
|
||||
* Create a new {@link SimpleCassandraRepository} for the given {@link CassandraEntityInformation}
|
||||
* and {@link CassandraTemplate}.
|
||||
*
|
||||
* @param metadata must not be {@literal null}.
|
||||
* @param operations must not be {@literal null}.
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -24,6 +24,7 @@ import java.util.concurrent.Future;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
|
||||
import org.springframework.data.cassandra.core.cql.AsyncCqlTemplate;
|
||||
import org.springframework.data.cassandra.core.query.CassandraPageRequest;
|
||||
@@ -265,9 +266,8 @@ public class AsyncCassandraTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
Set<String> expectedIds = new LinkedHashSet<>();
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
User user = new User("heisenberg" + i, "Walter", "White");
|
||||
for (int count = 0; count < 100; count++) {
|
||||
User user = new User("heisenberg" + count, "Walter", "White");
|
||||
expectedIds.add(user.getId());
|
||||
template.insert(user);
|
||||
}
|
||||
@@ -275,12 +275,16 @@ public class AsyncCassandraTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
Set<String> ids = new HashSet<>();
|
||||
|
||||
Query query = Query.empty();
|
||||
|
||||
Slice<User> slice = getUninterruptibly(
|
||||
template.slice(query.pageRequest(CassandraPageRequest.first(10)), User.class));
|
||||
|
||||
int iterations = 0;
|
||||
|
||||
do {
|
||||
|
||||
iterations++;
|
||||
|
||||
assertThat(slice).hasSize(10);
|
||||
|
||||
slice.stream().map(User::getId).forEach(ids::add);
|
||||
@@ -304,8 +308,8 @@ public class AsyncCassandraTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
try {
|
||||
return future.get();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
} catch (Exception cause) {
|
||||
throw new IllegalStateException(cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -29,6 +29,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
|
||||
import org.springframework.data.cassandra.core.cql.CqlTemplate;
|
||||
import org.springframework.data.cassandra.core.mapping.BasicMapId;
|
||||
@@ -402,9 +403,8 @@ public class CassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingI
|
||||
|
||||
Set<String> expectedIds = new LinkedHashSet<>();
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
User user = new User("heisenberg" + i, "Walter", "White");
|
||||
for (int count = 0; count < 100; count++) {
|
||||
User user = new User("heisenberg" + count, "Walter", "White");
|
||||
expectedIds.add(user.getId());
|
||||
template.insert(user);
|
||||
}
|
||||
@@ -412,11 +412,15 @@ public class CassandraTemplateIntegrationTests extends AbstractKeyspaceCreatingI
|
||||
Set<String> ids = new HashSet<>();
|
||||
|
||||
Query query = Query.empty().pageRequest(CassandraPageRequest.first(10));
|
||||
|
||||
Slice<User> slice = template.slice(query, User.class);
|
||||
|
||||
int iterations = 0;
|
||||
|
||||
do {
|
||||
|
||||
iterations++;
|
||||
|
||||
assertThat(slice).hasSize(10);
|
||||
|
||||
slice.stream().map(User::getId).forEach(ids::add);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@@ -31,9 +31,9 @@ public class InsertOptionsUnitTests {
|
||||
@Test // DATACASS-250
|
||||
public void shouldConfigureInsertOptions() {
|
||||
|
||||
InsertOptions insertOptions = InsertOptions.builder() //
|
||||
.ttl(10) //
|
||||
.withIfNotExists() //
|
||||
InsertOptions insertOptions = InsertOptions.builder()
|
||||
.ttl(10)
|
||||
.withIfNotExists()
|
||||
.build();
|
||||
|
||||
assertThat(insertOptions.getTtl()).isEqualTo(Duration.ofSeconds(10));
|
||||
@@ -43,13 +43,15 @@ public class InsertOptionsUnitTests {
|
||||
@Test // DATACASS-56
|
||||
public void buildInsertOptionsMutate() {
|
||||
|
||||
InsertOptions insertOptions = InsertOptions.builder() //
|
||||
.ttl(10) //
|
||||
.withIfNotExists() //
|
||||
InsertOptions insertOptions = InsertOptions.builder()
|
||||
.ttl(10)
|
||||
.withIfNotExists()
|
||||
.build();
|
||||
|
||||
InsertOptions mutated = insertOptions.mutate().ttl(Duration.ofSeconds(5)).build();
|
||||
|
||||
assertThat(mutated).isNotNull();
|
||||
assertThat(mutated).isNotSameAs(insertOptions);
|
||||
assertThat(mutated.getTtl()).isEqualTo(Duration.ofSeconds(5));
|
||||
assertThat(mutated.isIfNotExists()).isTrue();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
@@ -31,9 +31,9 @@ public class UpdateOptionsUnitTests {
|
||||
@Test // DATACASS-250
|
||||
public void shouldConfigureUpdateOptions() {
|
||||
|
||||
UpdateOptions updateOptions = UpdateOptions.builder() //
|
||||
.ttl(10) //
|
||||
.withIfExists() //
|
||||
UpdateOptions updateOptions = UpdateOptions.builder()
|
||||
.ttl(10)
|
||||
.withIfExists()
|
||||
.build();
|
||||
|
||||
assertThat(updateOptions.getTtl()).isEqualTo(Duration.ofSeconds(10));
|
||||
@@ -43,13 +43,15 @@ public class UpdateOptionsUnitTests {
|
||||
@Test // DATACASS-56
|
||||
public void buildUpdateOptionsMutate() {
|
||||
|
||||
UpdateOptions updateOptions = UpdateOptions.builder() //
|
||||
.ttl(10) //
|
||||
.withIfExists() //
|
||||
UpdateOptions updateOptions = UpdateOptions.builder()
|
||||
.ttl(10)
|
||||
.withIfExists()
|
||||
.build();
|
||||
|
||||
UpdateOptions mutated = updateOptions.mutate().ttl(20).build();
|
||||
|
||||
assertThat(mutated).isNotNull();
|
||||
assertThat(mutated).isNotSameAs(updateOptions);
|
||||
assertThat(mutated.getTtl()).isEqualTo(Duration.ofSeconds(20));
|
||||
assertThat(mutated.isIfExists()).isTrue();
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -38,13 +37,13 @@ public class QueryOptionsUnitTests {
|
||||
@Test // DATACASS-202
|
||||
public void buildQueryOptions() {
|
||||
|
||||
QueryOptions queryOptions = QueryOptions.builder() //
|
||||
.consistencyLevel(ConsistencyLevel.ANY) //
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE) //
|
||||
.readTimeout(1, TimeUnit.SECONDS)//
|
||||
.fetchSize(10)//
|
||||
.tracing(true)//
|
||||
.build(); //
|
||||
QueryOptions queryOptions = QueryOptions.builder()
|
||||
.consistencyLevel(ConsistencyLevel.ANY)
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE)
|
||||
.readTimeout(Duration.ofSeconds(1))
|
||||
.fetchSize(10)
|
||||
.tracing(true)
|
||||
.build();
|
||||
|
||||
assertThat(queryOptions.getClass()).isEqualTo(QueryOptions.class);
|
||||
assertThat(queryOptions.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE);
|
||||
@@ -57,9 +56,9 @@ public class QueryOptionsUnitTests {
|
||||
@Test // DATACASS-202
|
||||
public void buildQueryOptionsWithDriverRetryPolicy() {
|
||||
|
||||
QueryOptions writeOptions = QueryOptions.builder() //
|
||||
.retryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE)) //
|
||||
.build(); //
|
||||
QueryOptions writeOptions = QueryOptions.builder()
|
||||
.retryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE))
|
||||
.build();
|
||||
|
||||
assertThat(writeOptions.getRetryPolicy()).isInstanceOf(LoggingRetryPolicy.class);
|
||||
}
|
||||
@@ -67,9 +66,9 @@ public class QueryOptionsUnitTests {
|
||||
@Test // DATACASS-202
|
||||
public void buildQueryOptionsWithRetryPolicy() {
|
||||
|
||||
QueryOptions writeOptions = QueryOptions.builder() //
|
||||
.retryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE) //
|
||||
.build(); //
|
||||
QueryOptions writeOptions = QueryOptions.builder()
|
||||
.retryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
|
||||
.build();
|
||||
|
||||
assertThat(writeOptions.getRetryPolicy()).isEqualTo(DowngradingConsistencyRetryPolicy.INSTANCE);
|
||||
}
|
||||
@@ -77,16 +76,18 @@ public class QueryOptionsUnitTests {
|
||||
@Test // DATACASS-56
|
||||
public void buildQueryOptionsMutate() {
|
||||
|
||||
QueryOptions queryOptions = QueryOptions.builder() //
|
||||
.consistencyLevel(ConsistencyLevel.ANY) //
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE) //
|
||||
.readTimeout(1, TimeUnit.SECONDS)//
|
||||
.fetchSize(10)//
|
||||
.tracing(true)//
|
||||
.build(); //
|
||||
QueryOptions queryOptions = QueryOptions.builder()
|
||||
.consistencyLevel(ConsistencyLevel.ANY)
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE)
|
||||
.readTimeout(Duration.ofSeconds(1))
|
||||
.fetchSize(10)
|
||||
.tracing(true)
|
||||
.build();
|
||||
|
||||
QueryOptions mutated = queryOptions.mutate().readTimeout(Duration.ofSeconds(5)).build();
|
||||
|
||||
assertThat(mutated).isNotNull();
|
||||
assertThat(mutated).isNotSameAs(queryOptions);
|
||||
assertThat(mutated.getClass()).isEqualTo(QueryOptions.class);
|
||||
assertThat(mutated.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE);
|
||||
assertThat(mutated.getConsistencyLevel()).isEqualTo(ConsistencyLevel.ANY);
|
||||
|
||||
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy;
|
||||
import com.datastax.driver.core.policies.FallthroughRetryPolicy;
|
||||
|
||||
/**
|
||||
@@ -36,14 +35,14 @@ public class WriteOptionsUnitTests {
|
||||
@Test // DATACASS-202
|
||||
public void buildWriteOptions() {
|
||||
|
||||
WriteOptions writeOptions = WriteOptions.builder() //
|
||||
.consistencyLevel(com.datastax.driver.core.ConsistencyLevel.ANY) //
|
||||
.ttl(123) //
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE) //
|
||||
.readTimeout(1)//
|
||||
.fetchSize(10)//
|
||||
.withTracing()//
|
||||
.build(); //
|
||||
WriteOptions writeOptions = WriteOptions.builder()
|
||||
.consistencyLevel(com.datastax.driver.core.ConsistencyLevel.ANY)
|
||||
.ttl(123)
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE)
|
||||
.readTimeout(1)
|
||||
.fetchSize(10)
|
||||
.withTracing()
|
||||
.build();
|
||||
|
||||
assertThat(writeOptions.getTtl()).isEqualTo(Duration.ofSeconds(123));
|
||||
assertThat(writeOptions.getRetryPolicy()).isEqualTo(FallthroughRetryPolicy.INSTANCE);
|
||||
@@ -56,7 +55,7 @@ public class WriteOptionsUnitTests {
|
||||
@Test // DATACASS-202
|
||||
public void buildReadTimeoutOptionsWriteOptions() {
|
||||
|
||||
WriteOptions writeOptions = WriteOptions.builder().readTimeout(1, TimeUnit.MINUTES).build();
|
||||
WriteOptions writeOptions = WriteOptions.builder().readTimeout(Duration.ofMinutes(1)).build();
|
||||
|
||||
assertThat(writeOptions.getReadTimeout()).isEqualTo(Duration.ofSeconds(60));
|
||||
assertThat(writeOptions.getFetchSize()).isNull();
|
||||
@@ -82,17 +81,19 @@ public class WriteOptionsUnitTests {
|
||||
@Test // DATACASS-56
|
||||
public void buildWriteOptionsMutate() {
|
||||
|
||||
WriteOptions writeOptions = WriteOptions.builder() //
|
||||
.consistencyLevel(com.datastax.driver.core.ConsistencyLevel.ANY) //
|
||||
.ttl(123) //
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE) //
|
||||
.readTimeout(1)//
|
||||
.fetchSize(10)//
|
||||
.withTracing()//
|
||||
.build(); //
|
||||
WriteOptions writeOptions = WriteOptions.builder()
|
||||
.consistencyLevel(com.datastax.driver.core.ConsistencyLevel.ANY)
|
||||
.ttl(123)
|
||||
.retryPolicy(FallthroughRetryPolicy.INSTANCE)
|
||||
.readTimeout(1)
|
||||
.fetchSize(10)
|
||||
.withTracing()
|
||||
.build();
|
||||
|
||||
WriteOptions mutated = writeOptions.mutate().retryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE).build();
|
||||
|
||||
assertThat(mutated).isNotNull();
|
||||
assertThat(mutated).isNotSameAs(writeOptions);
|
||||
assertThat(mutated.getTtl()).isEqualTo(Duration.ofSeconds(123));
|
||||
assertThat(mutated.getRetryPolicy()).isEqualTo(DowngradingConsistencyRetryPolicy.INSTANCE);
|
||||
assertThat(mutated.getConsistencyLevel()).isEqualTo(ConsistencyLevel.ANY);
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.Sort.Order.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.springframework.data.domain.Sort.Order.asc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
@@ -32,8 +34,8 @@ import com.datastax.driver.core.PagingState;
|
||||
*/
|
||||
public class CassandraPageRequestUnitTests {
|
||||
|
||||
PagingState pagingState = PagingState
|
||||
.fromString("001400100c68656973656e62657267313600f07ffffff5006f934c985d6110148e1385ca793a75780004");
|
||||
PagingState pagingState =
|
||||
PagingState.fromString("001400100c68656973656e62657267313600f07ffffff5006f934c985d6110148e1385ca793a75780004");
|
||||
|
||||
@Test // DATACASS-56
|
||||
public void shouldNotAllowNonZeroPageConstruction() {
|
||||
|
||||
@@ -15,10 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.Sort.Order.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.data.domain.Sort.Order.asc;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
@@ -73,18 +74,18 @@ public class QueryUnitTests {
|
||||
@Test // DATACASS-56
|
||||
public void shouldApplyPageRequests() {
|
||||
|
||||
PagingState pagingState = PagingState
|
||||
.fromString("001400100c68656973656e62657267313600f07ffffff5006f934c985d6110148e1385ca793a75780004");
|
||||
PagingState pagingState =
|
||||
PagingState.fromString("001400100c68656973656e62657267313600f07ffffff5006f934c985d6110148e1385ca793a75780004");
|
||||
|
||||
CassandraPageRequest pageRequest = CassandraPageRequest.of(PageRequest.of(0, 42, Direction.ASC, "foo"), pagingState)
|
||||
CassandraPageRequest pageRequest =
|
||||
CassandraPageRequest.of(PageRequest.of(0, 42, Direction.ASC, "foo"), pagingState)
|
||||
.next();
|
||||
|
||||
Query query = Query.empty().pageRequest(pageRequest);
|
||||
|
||||
assertThat(query.getSort()).isEqualTo(Sort.by(asc("foo")));
|
||||
assertThat(query.getPagingState()).contains(pagingState);
|
||||
assertThat(query.getQueryOptions()).hasValueSatisfying(actual -> {
|
||||
assertThat(actual).extracting("fetchSize").contains(42);
|
||||
});
|
||||
assertThat(query.getQueryOptions()).hasValueSatisfying(actual ->
|
||||
assertThat(actual).extracting("fetchSize").contains(42));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
@@ -26,10 +26,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -55,6 +55,8 @@ import org.springframework.data.util.Version;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -24,6 +24,7 @@ import java.util.Optional;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
|
||||
@@ -15,13 +15,15 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.repository.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.Data;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -29,6 +31,7 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.core.convert.MappingCassandraConverter;
|
||||
|
||||
Reference in New Issue
Block a user