use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class TuplesSimple method retrieveData.
private static void retrieveData(CqlSession session) {
for (int k = 1; k <= 2; k++) {
// Execute the SELECT query and retrieve the single row in the result set
SimpleStatement statement = SimpleStatement.newInstance("SELECT c FROM examples.tuples WHERE k = ?", k);
Row row = session.execute(statement).one();
assert row != null;
// Retrieve the value for column c
TupleValue coordinatesValue = row.getTupleValue("c");
assert coordinatesValue != null;
// Display the contents of the tuple
System.out.printf("found coordinate: (%d,%d)%n", coordinatesValue.getInt(0), coordinatesValue.getInt(1));
}
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class CachingCodecRegistryTestDataProviders method collectionsWithCqlAndJavaTypes.
@DataProvider
public static Object[][] collectionsWithCqlAndJavaTypes() throws UnknownHostException, ClassNotFoundException {
TupleType tupleType = DataTypes.tupleOf(DataTypes.INT, DataTypes.listOf(DataTypes.TEXT));
TupleValue tupleValue = tupleType.newValue();
UserDefinedType userType = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type")).withField(CqlIdentifier.fromInternal("field1"), DataTypes.INT).withField(CqlIdentifier.fromInternal("field2"), DataTypes.listOf(DataTypes.TEXT)).build();
UdtValue udtValue = userType.newValue();
return new Object[][] { // lists
{ DataTypes.listOf(DataTypes.INT), GenericType.listOf(Integer.class), GenericType.listOf(Integer.class), ImmutableList.of(1) }, { DataTypes.listOf(DataTypes.TEXT), GenericType.listOf(String.class), GenericType.listOf(String.class), ImmutableList.of("foo") }, { DataTypes.listOf(DataTypes.BLOB), GenericType.listOf(ByteBuffer.class), GenericType.listOf(Class.forName("java.nio.HeapByteBuffer")), ImmutableList.of(ByteBuffer.wrap(new byte[] { 127, 0, 0, 1 })) }, { DataTypes.listOf(DataTypes.INET), GenericType.listOf(InetAddress.class), GenericType.listOf(Inet4Address.class), ImmutableList.of(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })) }, { DataTypes.listOf(tupleType), GenericType.listOf(TupleValue.class), GenericType.listOf(DefaultTupleValue.class), ImmutableList.of(tupleValue) }, { DataTypes.listOf(userType), GenericType.listOf(UdtValue.class), GenericType.listOf(DefaultUdtValue.class), ImmutableList.of(udtValue) }, { DataTypes.listOf(DataTypes.listOf(DataTypes.INT)), GenericType.listOf(GenericType.listOf(Integer.class)), GenericType.listOf(GenericType.listOf(Integer.class)), ImmutableList.of(ImmutableList.of(1)) }, { DataTypes.listOf(DataTypes.listOf(tupleType)), GenericType.listOf(GenericType.listOf(TupleValue.class)), GenericType.listOf(GenericType.listOf(DefaultTupleValue.class)), ImmutableList.of(ImmutableList.of(tupleValue)) }, { DataTypes.listOf(DataTypes.listOf(userType)), GenericType.listOf(GenericType.listOf(UdtValue.class)), GenericType.listOf(GenericType.listOf(DefaultUdtValue.class)), ImmutableList.of(ImmutableList.of(udtValue)) }, // sets
{ DataTypes.setOf(DataTypes.INT), GenericType.setOf(Integer.class), GenericType.setOf(Integer.class), ImmutableSet.of(1) }, { DataTypes.setOf(DataTypes.TEXT), GenericType.setOf(String.class), GenericType.setOf(String.class), ImmutableSet.of("foo") }, { DataTypes.setOf(DataTypes.BLOB), GenericType.setOf(ByteBuffer.class), GenericType.setOf(Class.forName("java.nio.HeapByteBuffer")), ImmutableSet.of(ByteBuffer.wrap(new byte[] { 127, 0, 0, 1 })) }, { DataTypes.setOf(DataTypes.INET), GenericType.setOf(InetAddress.class), GenericType.setOf(Inet4Address.class), ImmutableSet.of(InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })) }, { DataTypes.setOf(tupleType), GenericType.setOf(TupleValue.class), GenericType.setOf(DefaultTupleValue.class), ImmutableSet.of(tupleValue) }, { DataTypes.setOf(userType), GenericType.setOf(UdtValue.class), GenericType.setOf(DefaultUdtValue.class), ImmutableSet.of(udtValue) }, { DataTypes.setOf(DataTypes.setOf(DataTypes.INT)), GenericType.setOf(GenericType.setOf(Integer.class)), GenericType.setOf(GenericType.setOf(Integer.class)), ImmutableSet.of(ImmutableSet.of(1)) }, { DataTypes.setOf(DataTypes.setOf(tupleType)), GenericType.setOf(GenericType.setOf(TupleValue.class)), GenericType.setOf(GenericType.setOf(DefaultTupleValue.class)), ImmutableSet.of(ImmutableSet.of(tupleValue)) }, { DataTypes.setOf(DataTypes.setOf(userType)), GenericType.setOf(GenericType.setOf(UdtValue.class)), GenericType.setOf(GenericType.setOf(DefaultUdtValue.class)), ImmutableSet.of(ImmutableSet.of(udtValue)) }, // maps
{ DataTypes.mapOf(DataTypes.INT, DataTypes.TEXT), GenericType.mapOf(Integer.class, String.class), GenericType.mapOf(Integer.class, String.class), ImmutableMap.of(1, "foo") }, { DataTypes.mapOf(DataTypes.BLOB, DataTypes.INET), GenericType.mapOf(ByteBuffer.class, InetAddress.class), GenericType.mapOf(Class.forName("java.nio.HeapByteBuffer"), Inet4Address.class), ImmutableMap.of(ByteBuffer.wrap(new byte[] { 127, 0, 0, 1 }), InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })) }, { DataTypes.mapOf(tupleType, tupleType), GenericType.mapOf(TupleValue.class, TupleValue.class), GenericType.mapOf(DefaultTupleValue.class, DefaultTupleValue.class), ImmutableMap.of(tupleValue, tupleValue) }, { DataTypes.mapOf(userType, userType), GenericType.mapOf(UdtValue.class, UdtValue.class), GenericType.mapOf(DefaultUdtValue.class, DefaultUdtValue.class), ImmutableMap.of(udtValue, udtValue) }, { DataTypes.mapOf(DataTypes.UUID, DataTypes.mapOf(DataTypes.INT, DataTypes.TEXT)), GenericType.mapOf(GenericType.UUID, GenericType.mapOf(Integer.class, String.class)), GenericType.mapOf(GenericType.UUID, GenericType.mapOf(Integer.class, String.class)), ImmutableMap.of(UUID.randomUUID(), ImmutableMap.of(1, "foo")) }, { DataTypes.mapOf(DataTypes.mapOf(userType, userType), DataTypes.mapOf(tupleType, tupleType)), GenericType.mapOf(GenericType.mapOf(UdtValue.class, UdtValue.class), GenericType.mapOf(TupleValue.class, TupleValue.class)), GenericType.mapOf(GenericType.mapOf(DefaultUdtValue.class, DefaultUdtValue.class), GenericType.mapOf(DefaultTupleValue.class, DefaultTupleValue.class)), ImmutableMap.of(ImmutableMap.of(udtValue, udtValue), ImmutableMap.of(tupleValue, tupleValue)) } };
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class CachingCodecRegistryTestDataProviders method tuplesWithCqlTypes.
@DataProvider
public static Object[][] tuplesWithCqlTypes() {
TupleType tupleType1 = DataTypes.tupleOf(DataTypes.INT, DataTypes.TEXT);
TupleType tupleType2 = DataTypes.tupleOf(DataTypes.INT, DataTypes.listOf(DataTypes.TEXT));
TupleType tupleType3 = DataTypes.tupleOf(DataTypes.mapOf(tupleType1, tupleType2));
TupleValue tupleValue1 = tupleType1.newValue(42, "foo");
TupleValue tupleValue2 = tupleType2.newValue(42, ImmutableList.of("foo", "bar"));
return new Object[][] { { tupleType1, tupleType1.newValue() }, { tupleType1, tupleValue1 }, { tupleType2, tupleType2.newValue() }, { tupleType2, tupleValue2 }, { tupleType3, tupleType3.newValue() }, { tupleType3, tupleType3.newValue(ImmutableMap.of(tupleValue1, tupleValue2)) } };
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class CachingCodecRegistryTest method should_create_tuple_codec_for_cql_type.
@Test
@UseDataProvider(value = "tuplesWithCqlTypes", location = CachingCodecRegistryTestDataProviders.class)
public void should_create_tuple_codec_for_cql_type(DataType cqlType, Object value) {
TestCachingCodecRegistry registry = new TestCachingCodecRegistry(mockCache);
InOrder inOrder = inOrder(mockCache);
TypeCodec<TupleValue> codec = registry.codecFor(cqlType);
assertThat(codec).isNotNull();
assertThat(codec.accepts(cqlType)).isTrue();
assertThat(codec.accepts(GenericType.TUPLE_VALUE)).isTrue();
assertThat(codec.accepts(TupleValue.class)).isTrue();
assertThat(codec.accepts(value)).isTrue();
inOrder.verify(mockCache).lookup(cqlType, null, false);
}
use of com.datastax.oss.driver.api.core.data.TupleValue in project java-driver by datastax.
the class TupleCodecTest method should_decode_tuple.
@Test
public void should_decode_tuple() {
TupleValue tuple = decode("0x" + ("00000004" + "00000001") + "ffffffff" + ("00000001" + "61"));
assertThat(tuple.getInt(0)).isEqualTo(1);
assertThat(tuple.isNull(1)).isTrue();
assertThat(tuple.getString(2)).isEqualTo("a");
verify(intCodec).decodePrimitive(Bytes.fromHexString("0x00000001"), ProtocolVersion.DEFAULT);
verifyZeroInteractions(doubleCodec);
verify(textCodec).decode(Bytes.fromHexString("0x61"), ProtocolVersion.DEFAULT);
}
Aggregations