use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class UpdateMapperUnitTests method shouldPrependAllToSetViaColumnNameCollectionOfElements.
// DATACASS-770
@Test
void shouldPrependAllToSetViaColumnNameCollectionOfElements() {
Update update = updateMapper.getMappedObject(Update.empty().addTo("set_col").prependAll(new LinkedHashSet<>(Arrays.asList(currencyUSD, currencyEUR))), persistentEntity);
assertThat(update.getUpdateOperations()).hasSize(1);
assertThat(update).hasToString("set_col = {'US Dollar','Euro'} + set_col");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class UpdateMapperUnitTests method shouldClearList.
// DATACASS-343
@Test
void shouldClearList() {
Update update = updateMapper.getMappedObject(Update.empty().clear("list"), persistentEntity);
assertThat(update.getUpdateOperations()).hasSize(1);
assertThat(update).hasToString("list = []");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class UpdateMapperUnitTests method shouldMapPrefixedEmbeddedEntity.
// DATACASS-167
@Test
void shouldMapPrefixedEmbeddedEntity() {
Update update = this.updateMapper.getMappedObject(Update.empty().set("nested.firstname", "spring"), mappingContext.getRequiredPersistentEntity(WithPrefixedNullableEmbeddedType.class));
assertThat(update.getUpdateOperations()).hasSize(1);
assertThat(update.toString()).startsWith("prefixfirstname = 'spring'");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class UpdateMapperUnitTests method shouldCreateSetAtKeyUpdate.
// DATACASS-343
@Test
void shouldCreateSetAtKeyUpdate() {
Update update = updateMapper.getMappedObject(Update.empty().set("map").atKey("baz").to(currencyEUR), persistentEntity);
assertThat(update.getUpdateOperations()).hasSize(1);
assertThat(update).hasToString("map['baz'] = 'Euro'");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class CassandraTemplateIntegrationTests method updateCollection.
// #1007
@Test
void updateCollection() {
BookReference bookReference = new BookReference();
bookReference.setIsbn("isbn");
bookReference.setBookmarks(Arrays.asList(1, 2, 3, 4));
bookReference.setReferences(new LinkedHashSet<>(Arrays.asList("one", "two", "three")));
Map<String, String> credits = new LinkedHashMap<>();
credits.put("hello", "world");
credits.put("other", "world");
credits.put("external", "place");
bookReference.setCredits(credits);
template.insert(bookReference);
Query query = Query.query(where("isbn").is(bookReference.getIsbn()));
Update update = Update.empty().removeFrom("bookmarks").values(3, 4).removeFrom("references").values("one", "three").removeFrom("credits").values("hello", "other", "place");
template.update(query, update, BookReference.class);
BookReference loaded = template.selectOneById(bookReference.getIsbn(), BookReference.class);
assertThat(loaded.getBookmarks()).containsOnly(1, 2);
assertThat(loaded.getReferences()).containsOnly("two");
assertThat(loaded.getCredits()).containsOnlyKeys("external");
}
Aggregations