use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraTemplateUnitTests method updateShouldApplyUpdateQueryWitLwt.
// DATACASS-575
@Test
void updateShouldApplyUpdateQueryWitLwt() {
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
Filter ifCondition = Filter.from(where("firstname").is("Walter"), where("lastname").is("White"));
Query query = Query.query(where("id").is("heisenberg")).queryOptions(UpdateOptions.builder().ifCondition(ifCondition).build());
Update update = Update.update("firstname", "Walter");
//
template.update(query, update, User.class).as(//
StepVerifier::create).expectNextCount(//
1).verifyComplete();
verify(session).execute(statementCaptor.capture());
assertThat(render(statementCaptor.getValue())).isEqualTo("UPDATE users SET firstname='Walter' WHERE id='heisenberg' IF firstname='Walter' AND lastname='White'");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldRemoveFromSet.
// DATACASS-343
@Test
void shouldRemoveFromSet() {
Update update = Update.empty().remove("set", "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 set_col=set_col-{'Euro'}");
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method updateObjectShouldApplyQueryOptions.
// DATACASS-708
@Test
void updateObjectShouldApplyQueryOptions() {
WriteOptions queryOptions = //
WriteOptions.builder().executionProfile(//
"foo").serialConsistencyLevel(//
DefaultConsistencyLevel.QUORUM).build();
Person person = new Person();
person.id = "foo";
person.set = Collections.emptySet();
person.list = Collections.emptyList();
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(person, queryOptions);
SimpleStatement statement = update.build();
assertThat(statement.getExecutionProfileName()).isEqualTo("foo");
assertThat(statement.getSerialConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.QUORUM);
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method updateShouldApplyQueryOptions.
// DATACASS-708
@Test
void updateShouldApplyQueryOptions() {
UpdateOptions queryOptions = //
UpdateOptions.builder().executionProfile(//
"foo").serialConsistencyLevel(//
DefaultConsistencyLevel.QUORUM).build();
Query query = Query.query(Criteria.where("foo").is("bar")).queryOptions(queryOptions);
StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(query, Update.empty().set("firstName", "baz"), personEntity);
SimpleStatement statement = update.build();
assertThat(statement.getExecutionProfileName()).isEqualTo("foo");
assertThat(statement.getSerialConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.QUORUM);
}
use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldCreateSetUpdateIfExists.
// DATACASS-569
@Test
void shouldCreateSetUpdateIfExists() {
Query query = Query.query(Criteria.where("foo").is("bar")).queryOptions(UpdateOptions.builder().withIfExists().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 EXISTS");
}
Aggregations