use of org.springframework.data.cassandra.core.query.Filter in project spring-data-cassandra by spring-projects.
the class QueryMapperUnitTests method shouldMapEnumToNumberIn.
// DATACASS-343
@Test
void shouldMapEnumToNumberIn() {
Query query = Query.query(Criteria.where("number").in(State.Inactive));
Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
assertThat(mappedCriteriaDefinition.getPredicate().getValue()).isInstanceOf(Collection.class).isEqualTo(Collections.singletonList(1));
}
use of org.springframework.data.cassandra.core.query.Filter in project spring-data-cassandra by spring-projects.
the class AsyncCassandraTemplateUnitTests 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).executeAsync(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 CassandraQueryCreator method create.
/* (non-Javadoc)
* @see org.springframework.data.repository.query.parser.AbstractQueryCreator#create(org.springframework.data.repository.query.parser.Part, java.util.Iterator)
*/
@Override
protected Filter create(Part part, Iterator<Object> iterator) {
PersistentPropertyPath<CassandraPersistentProperty> path = getMappingContext().getPersistentPropertyPath(part.getProperty());
CassandraPersistentProperty property = path.getLeafProperty();
Assert.state(property != null && path.toDotPath() != null, "Leaf property must not be null");
Object filterOrCriteria = from(part, property, Criteria.where(path.toDotPath()), (PotentiallyConvertingIterator) iterator);
if (filterOrCriteria instanceof CriteriaDefinition) {
return Filter.from((CriteriaDefinition) filterOrCriteria);
}
return (Filter) filterOrCriteria;
}
use of org.springframework.data.cassandra.core.query.Filter in project spring-data-cassandra by spring-projects.
the class StatementFactory method count.
/**
* Create a {@literal COUNT} statement by mapping {@link Query} to {@link Select}.
*
* @param query user-defined count {@link Query} to execute; must not be {@literal null}.
* @param entity {@link CassandraPersistentEntity entity} to count; must not be {@literal null}.
* @param tableName must not be {@literal null}.
* @return the select builder.
* @since 2.1
*/
public StatementBuilder<Select> count(Query query, CassandraPersistentEntity<?> entity, CqlIdentifier tableName) {
Filter filter = getQueryMapper().getMappedObject(query, entity);
List<Selector> selectors = Collections.singletonList(FunctionCall.from("COUNT", 1L));
return createSelect(query, entity, filter, selectors, tableName);
}
use of org.springframework.data.cassandra.core.query.Filter in project spring-data-cassandra by spring-projects.
the class StatementFactory method delete.
/**
* Create a {@literal DELETE} statement by mapping {@link Query} to {@link Delete}.
*
* @param query must not be {@literal null}.
* @param persistentEntity must not be {@literal null}.
* @param tableName must not be {@literal null}.
* @return the delete builder.
* @see 2.1
*/
public StatementBuilder<Delete> delete(Query query, CassandraPersistentEntity<?> persistentEntity, CqlIdentifier tableName) {
Assert.notNull(query, "Query must not be null");
Assert.notNull(persistentEntity, "CassandraPersistentEntity must not be null");
Assert.notNull(tableName, "Table name must not be null");
Filter filter = getQueryMapper().getMappedObject(query, persistentEntity);
List<CqlIdentifier> columnNames = getQueryMapper().getMappedColumnNames(query.getColumns(), persistentEntity);
StatementBuilder<Delete> builder = delete(columnNames, tableName, filter);
query.getQueryOptions().filter(DeleteOptions.class::isInstance).map(DeleteOptions.class::cast).map(DeleteOptions::getIfCondition).ifPresent(criteriaDefinitions -> applyDeleteIfCondition(builder, criteriaDefinitions));
query.getQueryOptions().filter(WriteOptions.class::isInstance).map(WriteOptions.class::cast).ifPresent(writeOptions -> builder.apply(statement -> addWriteOptions(statement, writeOptions)));
query.getQueryOptions().ifPresent(options -> builder.transform(statement -> QueryOptionsUtil.addQueryOptions(statement, options)));
return builder;
}
Aggregations