Search in sources :

Example 6 with Update

use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.

the class StatementFactoryUnitTests method shouldCreateSetUpdateWithTtl.

// DATACASS-656
@Test
void shouldCreateSetUpdateWithTtl() {
    WriteOptions options = WriteOptions.builder().ttl(Duration.ofMinutes(1)).build();
    Query query = Query.query(Criteria.where("foo").is("bar")).queryOptions(options);
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(query, Update.empty().set("firstName", "baz"), personEntity);
    assertThat(update.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person USING TTL 60 SET first_name='baz' WHERE foo='bar'");
}
Also used : WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Query(org.springframework.data.cassandra.core.query.Query) Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 7 with Update

use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.

the class StatementFactoryUnitTests method shouldCreateSetUpdateFromObjectWithTimestamp.

// DATACASS-656
@Test
void shouldCreateSetUpdateFromObjectWithTimestamp() {
    WriteOptions options = WriteOptions.builder().timestamp(1234).build();
    Person person = new Person();
    person.id = "foo";
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(person, options);
    assertThat(update.build(ParameterHandling.INLINE).getQuery()).startsWith("UPDATE person USING TIMESTAMP 1234 SET");
}
Also used : WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 8 with Update

use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.

the class ReactiveCassandraTemplateUnitTests method updateShouldApplyUpdateQuery.

// DATACASS-575
@Test
void updateShouldApplyUpdateQuery() {
    when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
    Query query = Query.query(where("id").is("heisenberg"));
    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'");
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) Update(org.springframework.data.cassandra.core.query.Update) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 9 with Update

use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.

the class StatementFactoryUnitTests method shouldCreateSetUpdate.

// DATACASS-343
@Test
void shouldCreateSetUpdate() {
    Query query = Query.query(Criteria.where("foo").is("bar"));
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(query, Update.empty().set("firstName", "baz").set("boo", "baa"), personEntity);
    assertThat(update.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person SET first_name='baz', boo='baa' WHERE foo='bar'");
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 10 with Update

use of org.springframework.data.cassandra.core.query.Update in project spring-data-cassandra by spring-projects.

the class StatementFactoryUnitTests method shouldAddAllToSet.

// DATACASS-343
@Test
void shouldAddAllToSet() {
    Update update = Update.empty().addTo("set").appendAll("foo", "Euro");
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> updateStatementBuilder = statementFactory.update(Query.empty(), update, personEntity);
    assertThat(updateStatementBuilder.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person SET set_col=set_col+{'foo','Euro'}");
}
Also used : Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Aggregations

Update (org.springframework.data.cassandra.core.query.Update)51 Test (org.junit.jupiter.api.Test)49 Query (org.springframework.data.cassandra.core.query.Query)15 WriteOptions (org.springframework.data.cassandra.core.cql.WriteOptions)7 Filter (org.springframework.data.cassandra.core.query.Filter)5 LinkedHashMap (java.util.LinkedHashMap)3 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)2 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)2 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)2 BindMarker (com.datastax.oss.driver.api.querybuilder.BindMarker)2 QueryBuilder (com.datastax.oss.driver.api.querybuilder.QueryBuilder)2 Condition (com.datastax.oss.driver.api.querybuilder.condition.Condition)2 ConditionBuilder (com.datastax.oss.driver.api.querybuilder.condition.ConditionBuilder)2 Delete (com.datastax.oss.driver.api.querybuilder.delete.Delete)2 DeleteSelection (com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection)2 Insert (com.datastax.oss.driver.api.querybuilder.insert.Insert)2 RegularInsert (com.datastax.oss.driver.api.querybuilder.insert.RegularInsert)2 ColumnRelationBuilder (com.datastax.oss.driver.api.querybuilder.relation.ColumnRelationBuilder)2 Relation (com.datastax.oss.driver.api.querybuilder.relation.Relation)2 Select (com.datastax.oss.driver.api.querybuilder.select.Select)2