Search in sources :

Example 31 with TupleValue

use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.

the class TermTest method should_generate_literal_terms.

@Test
public void should_generate_literal_terms() {
    assertThat(literal(1)).hasCql("1");
    assertThat(literal("foo")).hasCql("'foo'");
    assertThat(literal(ImmutableList.of(1, 2, 3))).hasCql("[1,2,3]");
    TupleType tupleType = DataTypes.tupleOf(DataTypes.INT, DataTypes.TEXT);
    TupleValue tupleValue = tupleType.newValue().setInt(0, 1).setString(1, "foo");
    assertThat(literal(tupleValue)).hasCql("(1,'foo')");
    UserDefinedType udtType = new UserDefinedTypeBuilder(CqlIdentifier.fromCql("ks"), CqlIdentifier.fromCql("user")).withField(CqlIdentifier.fromCql("first_name"), DataTypes.TEXT).withField(CqlIdentifier.fromCql("last_name"), DataTypes.TEXT).build();
    UdtValue udtValue = udtType.newValue().setString("first_name", "Jane").setString("last_name", "Doe");
    assertThat(literal(udtValue)).hasCql("{first_name:'Jane',last_name:'Doe'}");
    assertThat(literal(null)).hasCql("NULL");
    assertThat(literal(Charsets.UTF_8, new CharsetCodec())).hasCql("'UTF-8'");
    assertThat(literal(Charsets.UTF_8, CharsetCodec.TEST_REGISTRY)).hasCql("'UTF-8'");
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) TupleType(com.datastax.oss.driver.api.core.type.TupleType) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) UserDefinedTypeBuilder(com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder) CharsetCodec(com.datastax.oss.driver.api.querybuilder.CharsetCodec) TupleValue(com.datastax.oss.driver.api.core.data.TupleValue) Test(org.junit.Test)

Aggregations

TupleValue (com.datastax.oss.driver.api.core.data.TupleValue)31 Test (org.junit.Test)18 DefaultTupleValue (com.datastax.oss.driver.internal.core.data.DefaultTupleValue)12 TupleType (com.datastax.oss.driver.api.core.type.TupleType)10 Row (com.datastax.oss.driver.api.core.cql.Row)6 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)5 DefaultTupleType (com.datastax.oss.driver.internal.core.type.DefaultTupleType)5 DataType (com.datastax.oss.driver.api.core.type.DataType)4 ByteBuffer (java.nio.ByteBuffer)4 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)3 Nullable (edu.umd.cs.findbugs.annotations.Nullable)3 InetAddress (java.net.InetAddress)3 List (java.util.List)3 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)2 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)2 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)2 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)2 CodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry)2 UserDefinedTypeBuilder (com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2