use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class CassandraTemplateIntegrationTests method shouldPartiallyUpdateListOfMappedUdt.
// DATACASS-829
@Test
void shouldPartiallyUpdateListOfMappedUdt() {
WithMappedUdtList entity = new WithMappedUdtList();
entity.id = "id-1";
entity.mappedUdts = Arrays.asList(new MappedUdt("one"), new MappedUdt("two"), new MappedUdt("three"));
template.insert(entity);
Update update = Update.empty().set("mappedUdts").atIndex(1).to(new MappedUdt("replacement"));
template.update(Query.query(where("id").is("id-1")), update, WithMappedUdtList.class);
WithMappedUdtList updated = template.selectOne(Query.query(where("id").is("id-1")), WithMappedUdtList.class);
assertThat(updated.getMappedUdts()).extracting(MappedUdt::getName).containsExactly("one", "replacement", "three");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class CassandraTemplateUnitTests method updateShouldApplyUpdateQuery.
// DATACASS-575
@Test
void updateShouldApplyUpdateQuery() {
Query query = Query.query(where("id").is("heisenberg"));
Update update = Update.update("firstname", "Walter");
template.update(query, update, User.class);
verify(session).execute(statementCaptor.capture());
assertThat(render(statementCaptor.getValue())).isEqualTo("UPDATE users SET firstname='Walter' WHERE id='heisenberg'");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldAppendAllToList.
// DATACASS-343
@Test
void shouldAppendAllToList() {
Update update = Update.empty().addTo("list").appendAll("foo", "Euro");
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> updateStatementBuilder = statementFactory.update(Query.empty(), update, personEntity);
assertThat(updateStatementBuilder.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person SET list=list+['foo','Euro']");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldPrependAllToList.
// DATACASS-343
@Test
void shouldPrependAllToList() {
Update update = Update.empty().addTo("list").prependAll("foo", "Euro");
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> updateStatementBuilder = statementFactory.update(Query.empty(), update, personEntity);
assertThat(updateStatementBuilder.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person SET list=['foo','Euro']+list");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldCreateSetUpdateIfCondition.
// DATACASS-656
@Test
void shouldCreateSetUpdateIfCondition() {
Query query = Query.query(Criteria.where("foo").is("bar")).queryOptions(UpdateOptions.builder().ifCondition(Criteria.where("foo").is("baz")).build());
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(query, Update.empty().set("firstName", "baz"), personEntity);
assertThat(update.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person SET first_name='baz' WHERE foo='bar' IF foo='baz'");
}
Aggregations