use of org.springframework.data.cassandra.core.query.Query 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");
}
use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldMapSelectQueryWithLimitAndAllowFiltering.
// DATACASS-343
@Test
void shouldMapSelectQueryWithLimitAndAllowFiltering() {
Query query = Query.empty().limit(10).withAllowFiltering();
StatementBuilder<Select> select = statementFactory.select(query, converter.getMappingContext().getRequiredPersistentEntity(Group.class));
assertThat(select.build(ParameterHandling.INLINE).getQuery()).isEqualTo("SELECT * FROM group LIMIT 10 ALLOW FILTERING");
}
use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldCreateSetUpdateWithTtl.
// DATACASS-656
@Test
void shouldCreateSetUpdateWithTtl() {
WriteOptions options = WriteOptions.builder().ttl(Duration.ofMinutes(1)).build();
Query query = Query.query(Criteria.where("foo").is("bar")).queryOptions(options);
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 USING TTL 60 SET first_name='baz' WHERE foo='bar'");
}
use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldMapDeleteQueryWithTimestampColumns.
// DATACASS-343
@Test
void shouldMapDeleteQueryWithTimestampColumns() {
DeleteOptions options = DeleteOptions.builder().timestamp(1234).build();
Query query = Query.query(Criteria.where("foo").is("bar")).queryOptions(options);
StatementBuilder<Delete> delete = statementFactory.delete(query, converter.getMappingContext().getRequiredPersistentEntity(Group.class));
assertThat(delete.build(ParameterHandling.INLINE).getQuery()).isEqualTo("DELETE FROM group USING TIMESTAMP 1234 WHERE foo='bar'");
}
use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraTemplateUnitTests method updateShouldApplyUpdateQuery.
// DATACASS-575
@Test
void updateShouldApplyUpdateQuery() {
when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
Query query = Query.query(where("id").is("heisenberg"));
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'");
}
Aggregations