use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class AsyncCassandraTemplateIntegrationTests method shouldSelectByQueryWithSorting.
// DATACASS-343
@Test
void shouldSelectByQueryWithSorting() {
UserToken token1 = new UserToken();
token1.setUserId(Uuids.endOf(System.currentTimeMillis()));
token1.setToken(Uuids.startOf(System.currentTimeMillis()));
token1.setUserComment("foo");
UserToken token2 = new UserToken();
token2.setUserId(token1.getUserId());
token2.setToken(Uuids.endOf(System.currentTimeMillis() + 100));
token2.setUserComment("bar");
getUninterruptibly(template.insert(token1));
getUninterruptibly(template.insert(token2));
Query query = Query.query(where("userId").is(token1.getUserId())).sort(Sort.by("token"));
assertThat(getUninterruptibly(template.select(query, UserToken.class))).containsSequence(token1, token2);
}
use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class AsyncCassandraTemplateIntegrationTests method deleteColumnsByQueryShouldRemoveColumn.
// DATACASS-343
@Test
void deleteColumnsByQueryShouldRemoveColumn() {
User user = new User("heisenberg", "Walter", "White");
getUninterruptibly(template.insert(user));
Query query = Query.query(where("id").is("heisenberg")).columns(Columns.from("lastname"));
assertThat(getUninterruptibly(template.delete(query, User.class))).isTrue();
User loaded = getUser(user.getId());
assertThat(loaded.getFirstname()).isEqualTo("Walter");
assertThat(loaded.getLastname()).isNull();
}
use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class AsyncCassandraTemplateIntegrationTests method updateShouldUpdateEntityByQuery.
// DATACASS-343
@Test
void updateShouldUpdateEntityByQuery() {
User user = new User("heisenberg", "Walter", "White");
getUninterruptibly(template.insert(user));
Query query = Query.query(where("id").is("heisenberg"));
boolean result = getUninterruptibly(template.update(query, Update.empty().set("firstname", "Walter Hartwell"), User.class));
assertThat(result).isTrue();
assertThat(getUser(user.getId()).getFirstname()).isEqualTo("Walter Hartwell");
}
use of org.springframework.data.cassandra.core.query.Query 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.Query 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