Search in sources :

Example 21 with Query

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);
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) UserToken(org.springframework.data.cassandra.domain.UserToken) Test(org.junit.jupiter.api.Test)

Example 22 with Query

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");
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) Test(org.junit.jupiter.api.Test)

Example 23 with Query

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");
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) UserToken(org.springframework.data.cassandra.domain.UserToken) Test(org.junit.jupiter.api.Test)

Example 24 with Query

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'");
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) Filter(org.springframework.data.cassandra.core.query.Filter) Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 25 with Query

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'");
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) Test(org.junit.jupiter.api.Test)

Aggregations

Query (org.springframework.data.cassandra.core.query.Query)72 Test (org.junit.jupiter.api.Test)65 User (org.springframework.data.cassandra.domain.User)22 Filter (org.springframework.data.cassandra.core.query.Filter)18 Update (org.springframework.data.cassandra.core.query.Update)17 CriteriaDefinition (org.springframework.data.cassandra.core.query.CriteriaDefinition)15 Select (com.datastax.oss.driver.api.querybuilder.select.Select)13 UserToken (org.springframework.data.cassandra.domain.UserToken)8 Group (org.springframework.data.cassandra.domain.Group)7 QueryOptions (org.springframework.data.cassandra.core.cql.QueryOptions)6 Columns (org.springframework.data.cassandra.core.query.Columns)6 Delete (com.datastax.oss.driver.api.querybuilder.delete.Delete)5 WriteOptions (org.springframework.data.cassandra.core.cql.WriteOptions)5 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)4 Collection (java.util.Collection)4 LinkedHashMap (java.util.LinkedHashMap)4 StepVerifier (reactor.test.StepVerifier)4 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)3 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)3 Uuids (com.datastax.oss.driver.api.core.uuid.Uuids)3