use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class CassandraTemplateIntegrationTests method shouldSelectOneByQuery.
// DATACASS-343
@Test
void shouldSelectOneByQuery() {
UserToken token1 = new UserToken();
token1.setUserId(Uuids.endOf(System.currentTimeMillis()));
token1.setToken(Uuids.startOf(System.currentTimeMillis()));
token1.setUserComment("foo");
template.insert(token1);
Query query = Query.query(where("userId").is(token1.getUserId()));
UserToken loaded = template.selectOne(query, UserToken.class);
assertThat(loaded).isEqualTo(token1);
}
use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class CassandraTemplateIntegrationTests method updateShouldUpdateEntityByQuery.
// DATACASS-343
@Test
void updateShouldUpdateEntityByQuery() {
User person = new User("heisenberg", "Walter", "White");
template.insert(person);
Query query = Query.query(where("id").is("heisenberg"));
boolean result = template.update(query, Update.empty().set("firstname", "Walter Hartwell"), User.class);
assertThat(result).isTrue();
assertThat(template.selectOneById(person.getId(), User.class).getFirstname()).isEqualTo("Walter Hartwell");
}
use of org.springframework.data.cassandra.core.query.Query in project spring-data-cassandra by spring-projects.
the class CassandraTemplateIntegrationTests method shouldSelectByQueryWithAllowFiltering.
// DATACASS-343
@Test
void shouldSelectByQueryWithAllowFiltering() {
assumeTrue(cassandraVersion.isGreaterThanOrEqualTo(CASSANDRA_3));
UserToken userToken = new UserToken();
userToken.setUserId(Uuids.endOf(System.currentTimeMillis()));
userToken.setToken(Uuids.startOf(System.currentTimeMillis()));
userToken.setUserComment("cook");
template.insert(userToken);
Query query = Query.query(where("userId").is(userToken.getUserId())).and(where("userComment").is("cook")).withAllowFiltering();
UserToken loaded = template.selectOne(query, UserToken.class);
assertThat(loaded).isNotNull();
assertThat(loaded.getUserComment()).isEqualTo("cook");
}
use of org.springframework.data.cassandra.core.query.Query 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.Query in project spring-data-cassandra by spring-projects.
the class CassandraTemplateUnitTests method deleteShouldRemoveByQueryWithLwt.
// DATACASS-575
@Test
void deleteShouldRemoveByQueryWithLwt() {
DeleteOptions options = DeleteOptions.builder().ifCondition(where("firstname").is("Walter")).build();
Query query = Query.query(where("id").is("heisenberg")).queryOptions(options);
template.delete(query, User.class);
verify(session).execute(statementCaptor.capture());
assertThat(render(statementCaptor.getValue())).isEqualTo("DELETE FROM users WHERE id='heisenberg' IF firstname='Walter'");
}
Aggregations