Search in sources :

Example 1 with Literal

use of com.datastax.oss.driver.api.querybuilder.Literal in project java-driver by datastax.

the class UpdateFluentAssignmentTest method should_generate_set_operations.

@Test
public void should_generate_set_operations() {
    Literal setLiteral = literal(ImmutableSet.of(1, 2, 3));
    assertThat(update("foo").append("s", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET s=s+? WHERE k=?");
    assertThat(update("foo").append("s", setLiteral).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET s=s+{1,2,3} WHERE k=?");
    assertThat(update("foo").appendSetElement("s", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET s=s+{?} WHERE k=?");
    assertThat(update("foo").prepend("s", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET s=?+s WHERE k=?");
    assertThat(update("foo").prepend("s", setLiteral).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET s={1,2,3}+s WHERE k=?");
    assertThat(update("foo").prependSetElement("s", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET s={?}+s WHERE k=?");
    assertThat(update("foo").remove("s", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET s=s-? WHERE k=?");
    assertThat(update("foo").remove("s", setLiteral).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET s=s-{1,2,3} WHERE k=?");
    assertThat(update("foo").removeSetElement("s", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET s=s-{?} WHERE k=?");
}
Also used : Literal(com.datastax.oss.driver.api.querybuilder.Literal) Test(org.junit.Test)

Example 2 with Literal

use of com.datastax.oss.driver.api.querybuilder.Literal in project java-driver by datastax.

the class UpdateFluentAssignmentTest method should_generate_map_operations.

@Test
public void should_generate_map_operations() {
    Literal mapLiteral = literal(ImmutableMap.of(1, "foo", 2, "bar"));
    assertThat(update("foo").append("m", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET m=m+? WHERE k=?");
    assertThat(update("foo").append("m", mapLiteral).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET m=m+{1:'foo',2:'bar'} WHERE k=?");
    assertThat(update("foo").appendMapEntry("m", literal(1), literal("foo")).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET m=m+{1:'foo'} WHERE k=?");
    assertThat(update("foo").prepend("m", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET m=?+m WHERE k=?");
    assertThat(update("foo").prepend("m", mapLiteral).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET m={1:'foo',2:'bar'}+m WHERE k=?");
    assertThat(update("foo").prependMapEntry("m", literal(1), literal("foo")).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET m={1:'foo'}+m WHERE k=?");
    assertThat(update("foo").remove("m", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET m=m-? WHERE k=?");
    assertThat(update("foo").remove("m", mapLiteral).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET m=m-{1:'foo',2:'bar'} WHERE k=?");
    assertThat(update("foo").removeMapEntry("m", literal(1), literal("foo")).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET m=m-{1:'foo'} WHERE k=?");
}
Also used : Literal(com.datastax.oss.driver.api.querybuilder.Literal) Test(org.junit.Test)

Example 3 with Literal

use of com.datastax.oss.driver.api.querybuilder.Literal in project java-driver by datastax.

the class UpdateFluentAssignmentTest method should_generate_list_operations.

@Test
public void should_generate_list_operations() {
    Literal listLiteral = literal(ImmutableList.of(1, 2, 3));
    assertThat(update("foo").append("l", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET l=l+? WHERE k=?");
    assertThat(update("foo").append("l", listLiteral).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET l=l+[1,2,3] WHERE k=?");
    assertThat(update("foo").appendListElement("l", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET l=l+[?] WHERE k=?");
    assertThat(update("foo").prepend("l", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET l=?+l WHERE k=?");
    assertThat(update("foo").prepend("l", listLiteral).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET l=[1,2,3]+l WHERE k=?");
    assertThat(update("foo").prependListElement("l", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET l=[?]+l WHERE k=?");
    assertThat(update("foo").remove("l", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET l=l-? WHERE k=?");
    assertThat(update("foo").remove("l", listLiteral).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET l=l-[1,2,3] WHERE k=?");
    assertThat(update("foo").removeListElement("l", bindMarker()).whereColumn("k").isEqualTo(bindMarker())).hasCql("UPDATE foo SET l=l-[?] WHERE k=?");
}
Also used : Literal(com.datastax.oss.driver.api.querybuilder.Literal) Test(org.junit.Test)

Aggregations

Literal (com.datastax.oss.driver.api.querybuilder.Literal)3 Test (org.junit.Test)3