@@ -62,6 +62,7 @@ import com.datastax.driver.core.querybuilder.Update;
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Antoine Toulme
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
* @see org.springframework.context.ApplicationContextAware
|
||||
* @see org.springframework.beans.factory.BeanClassLoaderAware
|
||||
@@ -102,13 +103,11 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <R> R readRow(Class<R> clazz, Row row) {
|
||||
public <R> R readRow(Class<R> type, Row row) {
|
||||
|
||||
Class<R> beanClassLoaderClass = transformClassToBeanClassLoaderClass(clazz);
|
||||
|
||||
TypeInformation<? extends R> type = ClassTypeInformation.from(beanClassLoaderClass);
|
||||
TypeInformation<? extends R> typeToUse = type;
|
||||
Class<? extends R> rawType = typeToUse.getType();
|
||||
Class<R> beanClassLoaderClass = transformClassToBeanClassLoaderClass(type);
|
||||
TypeInformation<? extends R> typeInfo = ClassTypeInformation.from(beanClassLoaderClass);
|
||||
Class<? extends R> rawType = typeInfo.getType();
|
||||
|
||||
if (Row.class.isAssignableFrom(rawType)) {
|
||||
return (R) row;
|
||||
@@ -118,12 +117,13 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
return conversionService.convert(row, rawType);
|
||||
}
|
||||
|
||||
if (type.isCollectionLike() || type.isMap()) {
|
||||
return conversionService.convert(row, clazz);
|
||||
if (typeInfo.isCollectionLike() || typeInfo.isMap()) {
|
||||
return conversionService.convert(row, type);
|
||||
}
|
||||
|
||||
CassandraPersistentEntity<R> persistentEntity = (CassandraPersistentEntity<R>) mappingContext
|
||||
.getPersistentEntity(typeToUse);
|
||||
CassandraPersistentEntity<R> persistentEntity =
|
||||
(CassandraPersistentEntity<R>) mappingContext.getPersistentEntity(typeInfo);
|
||||
|
||||
if (persistentEntity == null) {
|
||||
throw new MappingException("No mapping metadata found for " + rawType.getName());
|
||||
}
|
||||
@@ -139,11 +139,11 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
|
||||
protected <S> S readEntityFromRow(final CassandraPersistentEntity<S> entity, final Row row) {
|
||||
|
||||
DefaultSpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(row, spELContext);
|
||||
BasicCassandraRowValueProvider rowValueProvider = new BasicCassandraRowValueProvider(row, evaluator);
|
||||
DefaultSpELExpressionEvaluator expressionEvaluator = new DefaultSpELExpressionEvaluator(row, spELContext);
|
||||
BasicCassandraRowValueProvider rowValueProvider = new BasicCassandraRowValueProvider(row, expressionEvaluator);
|
||||
|
||||
CassandraPersistentEntityParameterValueProvider parameterProvider = new CassandraPersistentEntityParameterValueProvider(
|
||||
entity, rowValueProvider, null);
|
||||
CassandraPersistentEntityParameterValueProvider parameterProvider =
|
||||
new CassandraPersistentEntityParameterValueProvider(entity, rowValueProvider, null);
|
||||
|
||||
EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity);
|
||||
S instance = instantiator.createInstance(entity, parameterProvider);
|
||||
@@ -160,22 +160,22 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
|
||||
@Override
|
||||
public void doWithPersistentProperty(CassandraPersistentProperty prop) {
|
||||
|
||||
MappingCassandraConverter.this.readPropertyFromRow(entity, prop, row, accessor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void readPropertyFromRow(final CassandraPersistentEntity<?> entity, final CassandraPersistentProperty prop,
|
||||
// TODO argh! too many return statements!
|
||||
protected void readPropertyFromRow(final CassandraPersistentEntity<?> entity, final CassandraPersistentProperty property,
|
||||
final BasicCassandraRowValueProvider row, final PersistentPropertyAccessor accessor) {
|
||||
|
||||
if (entity.isConstructorArgument(prop)) { // skip 'cause prop was set in ctor
|
||||
// if true then skip; property was set in constructor
|
||||
if (entity.isConstructorArgument(property)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (prop.isCompositePrimaryKey()) {
|
||||
if (property.isCompositePrimaryKey()) {
|
||||
|
||||
// get the key
|
||||
CassandraPersistentProperty keyProperty = entity.getIdProperty();
|
||||
CassandraPersistentEntity<?> keyEntity = keyProperty.getCompositePrimaryKeyEntity();
|
||||
|
||||
@@ -186,60 +186,60 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
|
||||
// now recurse on using the key this time
|
||||
readPropertiesFromRow(prop.getCompositePrimaryKeyEntity(), row, getConvertingAccessor(key, keyEntity));
|
||||
readPropertiesFromRow(property.getCompositePrimaryKeyEntity(), row, getConvertingAccessor(key, keyEntity));
|
||||
|
||||
// now that the key's properties have been populated, set the key property on the entity
|
||||
accessor.setProperty(keyProperty, key);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!row.getRow().getColumnDefinitions().contains(prop.getColumnName().toCql())) {
|
||||
if (!row.getRow().getColumnDefinitions().contains(property.getColumnName().toCql())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object obj = row.getPropertyValue(prop);
|
||||
accessor.setProperty(prop, obj);
|
||||
accessor.setProperty(property, row.getPropertyValue(property));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected Object instantiatePrimaryKey(CassandraPersistentEntity<?> entity, CassandraPersistentProperty keyProperty,
|
||||
BasicCassandraRowValueProvider propertyProvider) {
|
||||
|
||||
EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity);
|
||||
|
||||
return instantiator.createInstance(entity,
|
||||
new CassandraPersistentEntityParameterValueProvider(entity, propertyProvider, null));
|
||||
return instantiators.getInstantiatorFor(entity).createInstance(entity,
|
||||
new CassandraPersistentEntityParameterValueProvider(entity, propertyProvider, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R> R read(Class<R> type, Object row) {
|
||||
|
||||
if (row instanceof Row) {
|
||||
return readRow(type, (Row) row);
|
||||
}
|
||||
|
||||
throw new MappingException("Unknown row object " + row.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Object source, Object sink) {
|
||||
|
||||
if (source == null) {
|
||||
return;
|
||||
}
|
||||
if (source != null) {
|
||||
Class<?> beanClassLoaderClass = transformClassToBeanClassLoaderClass(source.getClass());
|
||||
|
||||
Class<?> beanClassLoaderClass = transformClassToBeanClassLoaderClass(source.getClass());
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getPersistentEntity(beanClassLoaderClass);
|
||||
CassandraPersistentEntity<?> entity = mappingContext.getPersistentEntity(beanClassLoaderClass);
|
||||
|
||||
if (entity == null) {
|
||||
throw new MappingException("No mapping metadata found for " + source.getClass());
|
||||
}
|
||||
if (entity == null) {
|
||||
throw new MappingException("No mapping metadata found for " + source.getClass());
|
||||
}
|
||||
|
||||
if (sink instanceof Insert) {
|
||||
writeInsertFromObject(source, (Insert) sink, entity);
|
||||
} else if (sink instanceof Update) {
|
||||
writeUpdateFromObject(source, (Update) sink, entity);
|
||||
} else if (sink instanceof Where) {
|
||||
writeDeleteWhereFromObject(source, (Where) sink, entity);
|
||||
} else {
|
||||
throw new MappingException("Unknown write target " + sink.getClass().getName());
|
||||
if (sink instanceof Insert) {
|
||||
writeInsertFromObject(source, (Insert) sink, entity);
|
||||
} else if (sink instanceof Update) {
|
||||
writeUpdateFromObject(source, (Update) sink, entity);
|
||||
} else if (sink instanceof Where) {
|
||||
writeDeleteWhereFromObject(source, (Where) sink, entity);
|
||||
} else {
|
||||
throw new MappingException("Unknown write target " + sink.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,29 +253,31 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
entity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() {
|
||||
|
||||
@Override
|
||||
public void doWithPersistentProperty(CassandraPersistentProperty prop) {
|
||||
public void doWithPersistentProperty(CassandraPersistentProperty property) {
|
||||
|
||||
Object value = accessor.getProperty(prop,
|
||||
prop.isCompositePrimaryKey() ? prop.getType() : CodecRegistry.DEFAULT_INSTANCE.codecFor(prop.getDataType()).getJavaType().getRawType());
|
||||
Object value = accessor.getProperty(property, property.isCompositePrimaryKey() ? property.getType()
|
||||
: CodecRegistry.DEFAULT_INSTANCE.codecFor(property.getDataType()).getJavaType().getRawType());
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("doWithProperties Property.type {}, Property.value {}", prop.getType().getName(), value);
|
||||
log.debug("doWithProperties Property.type {}, Property.value {}", property.getType().getName(), value);
|
||||
}
|
||||
|
||||
if (prop.isCompositePrimaryKey()) {
|
||||
if (property.isCompositePrimaryKey()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Property is a compositeKey");
|
||||
}
|
||||
|
||||
writeInsertFromWrapper(getConvertingAccessor(value, prop.getCompositePrimaryKeyEntity()), insert,
|
||||
prop.getCompositePrimaryKeyEntity());
|
||||
writeInsertFromWrapper(getConvertingAccessor(value, property.getCompositePrimaryKeyEntity()), insert,
|
||||
property.getCompositePrimaryKeyEntity());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Adding insert.value [{}] - [{}]", prop.getColumnName().toCql(), value);
|
||||
log.debug("Adding insert.value [{}] - [{}]", property.getColumnName().toCql(), value);
|
||||
}
|
||||
insert.value(prop.getColumnName().toCql(), value);
|
||||
|
||||
insert.value(property.getColumnName().toCql(), value);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -290,21 +292,21 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
entity.doWithProperties(new PropertyHandler<CassandraPersistentProperty>() {
|
||||
|
||||
@Override
|
||||
public void doWithPersistentProperty(CassandraPersistentProperty prop) {
|
||||
public void doWithPersistentProperty(CassandraPersistentProperty property) {
|
||||
|
||||
Object value = accessor.getProperty(prop,
|
||||
prop.isCompositePrimaryKey() ? prop.getType() : CodecRegistry.DEFAULT_INSTANCE.codecFor(prop.getDataType()).getJavaType().getRawType());
|
||||
Object value = accessor.getProperty(property, property.isCompositePrimaryKey() ? property.getType()
|
||||
: CodecRegistry.DEFAULT_INSTANCE.codecFor(property.getDataType()).getJavaType().getRawType());
|
||||
|
||||
if (prop.isCompositePrimaryKey()) {
|
||||
CassandraPersistentEntity<?> keyEntity = prop.getCompositePrimaryKeyEntity();
|
||||
if (property.isCompositePrimaryKey()) {
|
||||
CassandraPersistentEntity<?> keyEntity = property.getCompositePrimaryKeyEntity();
|
||||
writeUpdateFromWrapper(getConvertingAccessor(value, keyEntity), update, keyEntity);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPrimaryKeyPart(prop)) {
|
||||
update.where(QueryBuilder.eq(prop.getColumnName().toCql(), value));
|
||||
if (isPrimaryKeyPart(property)) {
|
||||
update.where(QueryBuilder.eq(property.getColumnName().toCql(), value));
|
||||
} else {
|
||||
update.with(QueryBuilder.set(prop.getColumnName().toCql(), value));
|
||||
update.with(QueryBuilder.set(property.getColumnName().toCql(), value));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -361,7 +363,6 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
|
||||
where.and(QueryBuilder.eq(idProperty.getColumnName().toCql(), id));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,12 +432,12 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @param entity must not be {@literal null}.
|
||||
* @return
|
||||
* @return a new {@link ConvertingPropertyAccessor} for the given source and entity.
|
||||
*/
|
||||
private ConvertingPropertyAccessor getConvertingAccessor(Object source, CassandraPersistentEntity<?> entity) {
|
||||
|
||||
PersistentPropertyAccessor accessor = source instanceof PersistentPropertyAccessor
|
||||
? (PersistentPropertyAccessor) source : entity.getPropertyAccessor(source);
|
||||
PersistentPropertyAccessor accessor = (source instanceof PersistentPropertyAccessor
|
||||
? (PersistentPropertyAccessor) source : entity.getPropertyAccessor(source));
|
||||
|
||||
return new ConvertingPropertyAccessor(accessor, conversionService);
|
||||
}
|
||||
@@ -444,10 +445,10 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
/**
|
||||
* Returns whether the property is part of the primary key.
|
||||
*
|
||||
* @param property
|
||||
* @return
|
||||
* @param property {@link CassandraPersistentProperty} to evaluate.
|
||||
* @return a boolean value indicating whether the given property is party of a primary key.
|
||||
*/
|
||||
private boolean isPrimaryKeyPart(CassandraPersistentProperty property) {
|
||||
return property.isCompositePrimaryKey() || property.isPrimaryKeyColumn() || property.isIdProperty();
|
||||
return (property.isCompositePrimaryKey() || property.isPrimaryKeyColumn() || property.isIdProperty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.cassandra.core.RetryPolicy;
|
||||
import org.springframework.cassandra.core.WriteOptions;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.core.CassandraTemplate;
|
||||
import org.springframework.data.cassandra.test.integration.simpletons.Book;
|
||||
import org.springframework.data.cassandra.test.integration.simpletons.BookCondition;
|
||||
import org.springframework.data.cassandra.test.integration.simpletons.BookReference;
|
||||
@@ -45,7 +44,6 @@ import org.springframework.data.cassandra.test.integration.support.IntegrationTe
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.datastax.driver.core.querybuilder.Delete;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
|
||||
@@ -54,6 +52,7 @@ import com.datastax.driver.core.querybuilder.Select;
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Mark Paluch
|
||||
* @author John Blum
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@@ -68,7 +67,8 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired CassandraOperations template;
|
||||
@Autowired
|
||||
CassandraOperations template;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@@ -105,10 +105,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
b3.setPages(265);
|
||||
b3.setCondition(BookCondition.USED);
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
template.insert(b3, options);
|
||||
|
||||
@@ -120,10 +117,10 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
b5.setCondition(BookCondition.USED);
|
||||
|
||||
template.insert(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void insertAsynchronouslyTest() {
|
||||
|
||||
Book b1 = new Book();
|
||||
@@ -154,10 +151,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
b3.setPages(265);
|
||||
b3.setCondition(BookCondition.USED);
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
template.insertAsynchronously(b3, options);
|
||||
|
||||
@@ -182,7 +176,6 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
b5.setCondition(BookCondition.USED);
|
||||
|
||||
template.insertAsynchronously(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -203,14 +196,9 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
@Test
|
||||
public void insertBatchTest() {
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
List<Book> books = null;
|
||||
|
||||
books = getBookList(20);
|
||||
List<Book> books = getBookList(20);
|
||||
|
||||
template.insert(books);
|
||||
|
||||
@@ -226,19 +214,16 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
|
||||
template.insert(books, options);
|
||||
|
||||
assertThat(template.count(Book.class), is(equalTo(80l)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void insertBatchAsynchronouslyTest() {
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
List<Book> books = null;
|
||||
|
||||
books = getBookList(20);
|
||||
List<Book> books = getBookList(20);
|
||||
|
||||
template.insertAsynchronously(books);
|
||||
|
||||
@@ -253,12 +238,8 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
books = getBookList(20);
|
||||
|
||||
template.insertAsynchronously(books, options);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private List<Book> getBookList(long numBooks) {
|
||||
|
||||
List<Book> books = new ArrayList<Book>();
|
||||
@@ -284,10 +265,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
|
||||
insertTest();
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -329,18 +307,15 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
b5.setPages(265);
|
||||
|
||||
template.update(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void updateAsynchronouslyTest() {
|
||||
|
||||
insertTest();
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
@@ -382,20 +357,14 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
b5.setPages(265);
|
||||
|
||||
template.updateAsynchronously(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBatchTest() {
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
List<Book> books = null;
|
||||
|
||||
books = getBookList(20);
|
||||
List<Book> books = getBookList(20);
|
||||
|
||||
template.insert(books);
|
||||
|
||||
@@ -426,20 +395,15 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
alterBooks(books);
|
||||
|
||||
template.update(books, options);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void updateBatchAsynchronouslyTest() {
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
List<Book> books = null;
|
||||
|
||||
books = getBookList(20);
|
||||
List<Book> books = getBookList(20);
|
||||
|
||||
template.insert(books);
|
||||
|
||||
@@ -470,18 +434,14 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
alterBooks(books);
|
||||
|
||||
template.updateAsynchronously(books, options);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param books
|
||||
*/
|
||||
private void alterBooks(List<Book> books) {
|
||||
|
||||
for (Book b : books) {
|
||||
b.setAuthor("Ernest Hemmingway");
|
||||
b.setTitle("The Old Man and the Sea");
|
||||
b.setPages(115);
|
||||
for (Book book : books) {
|
||||
book.setAuthor("Ernest Hemmingway");
|
||||
book.setTitle("The Old Man and the Sea");
|
||||
book.setPages(115);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,9 +454,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
// Test Single Insert with entity
|
||||
Book b1 = new Book();
|
||||
b1.setIsbn("123456-1");
|
||||
|
||||
@@ -507,22 +465,17 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
|
||||
template.delete(b2);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
// Test Single Insert with entity
|
||||
Book b3 = new Book();
|
||||
b3.setIsbn("123456-3");
|
||||
|
||||
template.delete(b3, options);
|
||||
|
||||
/*
|
||||
* Test Single Insert with entity
|
||||
*/
|
||||
// Test Single Insert with entity
|
||||
Book b5 = new Book();
|
||||
b5.setIsbn("123456-5");
|
||||
|
||||
template.delete(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -562,79 +515,58 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
b5.setIsbn("123456-5");
|
||||
|
||||
template.deleteAsynchronously(b5, options);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteBatchTest() {
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
List<Book> books = null;
|
||||
|
||||
books = getBookList(20);
|
||||
List<Book> books = getBookList(20);
|
||||
|
||||
template.insert(books);
|
||||
|
||||
template.delete(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
template.insert(books);
|
||||
|
||||
template.delete(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
template.insert(books, options);
|
||||
|
||||
template.delete(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
template.insert(books, options);
|
||||
|
||||
template.delete(books, options);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteBatchAsynchronouslyTest() {
|
||||
|
||||
WriteOptions options = new WriteOptions();
|
||||
options.setTtl(60);
|
||||
options.setConsistencyLevel(ConsistencyLevel.ONE);
|
||||
options.setRetryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY);
|
||||
WriteOptions options = newWriteOptions(ConsistencyLevel.ONE, RetryPolicy.DOWNGRADING_CONSISTENCY, 60);
|
||||
|
||||
List<Book> books = null;
|
||||
|
||||
books = getBookList(20);
|
||||
List<Book> books = getBookList(20);
|
||||
|
||||
template.insert(books);
|
||||
|
||||
template.deleteAsynchronously(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
template.insert(books);
|
||||
|
||||
template.deleteAsynchronously(books);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
template.insert(books, options);
|
||||
|
||||
template.deleteAsynchronously(books, options);
|
||||
|
||||
books = getBookList(20);
|
||||
|
||||
template.insert(books, options);
|
||||
|
||||
template.deleteAsynchronously(books, options);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -708,7 +640,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-182
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-182">DATACASS-182</a>
|
||||
*/
|
||||
@Test
|
||||
public void updateShouldRemoveFields() {
|
||||
@@ -730,7 +662,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-182
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-182">DATACASS-182</a>
|
||||
*/
|
||||
@Test
|
||||
public void insertShouldRemoveFields() {
|
||||
@@ -743,6 +675,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
template.insert(book);
|
||||
|
||||
book.setTitle(null);
|
||||
|
||||
template.insert(book);
|
||||
|
||||
Book loaded = template.selectOneById(Book.class, book.getIsbn());
|
||||
@@ -752,7 +685,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-182
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-182">DATACASS-182</a>
|
||||
*/
|
||||
@Test
|
||||
public void updateShouldInsertEntity() {
|
||||
@@ -767,10 +700,12 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
Book loaded = template.selectOneById(Book.class, book.getIsbn());
|
||||
|
||||
assertThat(loaded, is(notNullValue()));
|
||||
assertThat(loaded.getAuthor(), is(equalTo("author")));
|
||||
assertThat(loaded.getTitle(), is(equalTo("title")));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-182
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-182">DATACASS-182</a>
|
||||
*/
|
||||
@Test
|
||||
public void insertAndUpdateToEmptyCollection() {
|
||||
@@ -783,6 +718,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
template.insert(bookReference);
|
||||
|
||||
bookReference.setBookmarks(Collections.<Integer> emptyList());
|
||||
|
||||
template.update(bookReference);
|
||||
|
||||
BookReference loaded = template.selectOneById(BookReference.class, bookReference.getIsbn());
|
||||
@@ -792,7 +728,7 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-297
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-182">DATACASS-182</a>
|
||||
*/
|
||||
@Test
|
||||
public void stream() {
|
||||
@@ -813,6 +749,10 @@ public class CassandraOperationsIntegrationTests extends AbstractSpringDataEmbed
|
||||
assertThat(selectedBooks.get(0), is(instanceOf(Book.class)));
|
||||
}
|
||||
|
||||
WriteOptions newWriteOptions(ConsistencyLevel consistencyLevel, RetryPolicy retryPolicy, int timeToLive) {
|
||||
return new WriteOptions(consistencyLevel, retryPolicy, timeToLive);
|
||||
}
|
||||
|
||||
<T> Iterable<T> toIterable(final Iterator<T> iterator) {
|
||||
return new Iterable<T>() {
|
||||
@Override public Iterator<T> iterator() {
|
||||
|
||||
@@ -45,8 +45,6 @@ public class UserRepositoryIntegrationTests {
|
||||
|
||||
List<User> all;
|
||||
|
||||
public UserRepositoryIntegrationTests() {}
|
||||
|
||||
public UserRepositoryIntegrationTests(UserRepository repository, CassandraOperations template) {
|
||||
this.repository = repository;
|
||||
this.template = template;
|
||||
@@ -132,7 +130,7 @@ public class UserRepositoryIntegrationTests {
|
||||
|
||||
public void deletesUserByIdCorrectly() {
|
||||
|
||||
repository.delete(tom.getUsername().toString());
|
||||
repository.delete(tom.getUsername());
|
||||
|
||||
List<User> result = Lists.newArrayList(repository.findAll());
|
||||
|
||||
@@ -153,7 +151,7 @@ public class UserRepositoryIntegrationTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-182
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-182">DATACASS-182</a>
|
||||
*/
|
||||
public void save() {
|
||||
|
||||
|
||||
@@ -31,8 +31,11 @@ import org.springframework.data.cassandra.test.integration.support.AbstractSprin
|
||||
public abstract class UserRepositoryIntegrationTestsDelegator
|
||||
extends AbstractSpringDataEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Autowired UserRepository repository;
|
||||
@Autowired CassandraOperations template;
|
||||
@Autowired
|
||||
CassandraOperations template;
|
||||
|
||||
@Autowired
|
||||
UserRepository repository;
|
||||
|
||||
UserRepositoryIntegrationTests tests;
|
||||
|
||||
@@ -78,7 +81,7 @@ public abstract class UserRepositoryIntegrationTestsDelegator
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACASS-182
|
||||
* @see <a href="https://jira.spring.io/browse/DATACASS-182">DATACASS-182</a>
|
||||
*/
|
||||
@Test
|
||||
public void save() {
|
||||
|
||||
Reference in New Issue
Block a user