use of org.springframework.data.cassandra.core.query.Filter 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.Filter in project spring-data-cassandra by spring-projects.
the class CassandraTemplateUnitTests method updateShouldApplyUpdateQueryWitLwt.
// DATACASS-575
@Test
void updateShouldApplyUpdateQueryWitLwt() {
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);
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.Filter in project spring-data-cassandra by spring-projects.
the class StatementFactory method createSelect.
private StatementBuilder<Select> createSelect(Query query, CassandraPersistentEntity<?> entity, Filter filter, List<Selector> selectors, CqlIdentifier tableName) {
Sort sort = Optional.of(query.getSort()).map(querySort -> getQueryMapper().getMappedSort(querySort, entity)).orElse(Sort.unsorted());
StatementBuilder<Select> select = createSelectAndOrder(selectors, tableName, filter, sort);
if (query.getLimit() > 0) {
select.apply(it -> it.limit(Math.toIntExact(query.getLimit())));
}
if (query.isAllowFiltering()) {
select.apply(Select::allowFiltering);
}
select.onBuild(statementBuilder -> query.getPagingState().ifPresent(statementBuilder::setPagingState));
query.getQueryOptions().ifPresent(it -> select.transform(statement -> QueryOptionsUtil.addQueryOptions(statement, it)));
return select;
}
use of org.springframework.data.cassandra.core.query.Filter in project spring-data-cassandra by spring-projects.
the class StatementFactory method select.
/**
* Create a {@literal SELECT} statement by mapping {@link Query} to {@link Select}.
*
* @param query must not be {@literal null}.
* @param persistentEntity must not be {@literal null}.
* @param tableName must not be {@literal null}.
* @return the select builder.
* @since 2.1
*/
public StatementBuilder<Select> select(Query query, CassandraPersistentEntity<?> persistentEntity, CqlIdentifier tableName) {
Assert.notNull(query, "Query must not be null");
Assert.notNull(persistentEntity, "CassandraPersistentEntity must not be null");
Assert.notNull(persistentEntity, "Table name must not be null");
Filter filter = getQueryMapper().getMappedObject(query, persistentEntity);
List<Selector> selectors = getQueryMapper().getMappedSelectors(query.getColumns(), persistentEntity);
return createSelect(query, persistentEntity, filter, selectors, tableName);
}
use of org.springframework.data.cassandra.core.query.Filter in project spring-data-cassandra by spring-projects.
the class QueryMapperUnitTests method shouldMapPropertyToColumnName.
// DATACASS-343
@Test
void shouldMapPropertyToColumnName() {
Query query = Query.query(Criteria.where("firstName").is("bar"));
Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
assertThat(mappedCriteriaDefinition.getColumnName()).isEqualTo(ColumnName.from(CqlIdentifier.fromCql("first_name")));
assertThat(mappedCriteriaDefinition.getColumnName().toString()).isEqualTo("first_name");
}
Aggregations