use of com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder in project java-driver by datastax.
the class CachingCodecRegistryTestDataProviders method emptyCollectionsWithCqlAndJavaTypes.
@DataProvider
public static Object[][] emptyCollectionsWithCqlAndJavaTypes() {
TupleType tupleType = DataTypes.tupleOf(DataTypes.INT, DataTypes.listOf(DataTypes.TEXT));
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();
return new Object[][] { // lists
{ DataTypes.listOf(DataTypes.INT), GenericType.listOf(Integer.class), DataTypes.listOf(DataTypes.BOOLEAN), GenericType.listOf(Boolean.class), Collections.emptyList() }, { DataTypes.listOf(DataTypes.TEXT), GenericType.listOf(String.class), DataTypes.listOf(DataTypes.BOOLEAN), GenericType.listOf(Boolean.class), Collections.emptyList() }, { DataTypes.listOf(DataTypes.BLOB), GenericType.listOf(ByteBuffer.class), DataTypes.listOf(DataTypes.BOOLEAN), GenericType.listOf(Boolean.class), Collections.emptyList() }, { DataTypes.listOf(DataTypes.INET), GenericType.listOf(InetAddress.class), DataTypes.listOf(DataTypes.BOOLEAN), GenericType.listOf(Boolean.class), Collections.emptyList() }, { DataTypes.listOf(tupleType), GenericType.listOf(TupleValue.class), DataTypes.listOf(DataTypes.BOOLEAN), GenericType.listOf(Boolean.class), Collections.emptyList() }, { DataTypes.listOf(userType), GenericType.listOf(UdtValue.class), DataTypes.listOf(DataTypes.BOOLEAN), GenericType.listOf(Boolean.class), Collections.emptyList() }, { DataTypes.listOf(DataTypes.listOf(DataTypes.INT)), GenericType.listOf(GenericType.listOf(Integer.class)), DataTypes.listOf(DataTypes.listOf(DataTypes.BOOLEAN)), GenericType.listOf(GenericType.listOf(Boolean.class)), ImmutableList.of(Collections.emptyList()) }, { DataTypes.listOf(DataTypes.listOf(tupleType)), GenericType.listOf(GenericType.listOf(TupleValue.class)), DataTypes.listOf(DataTypes.listOf(DataTypes.BOOLEAN)), GenericType.listOf(GenericType.listOf(Boolean.class)), ImmutableList.of(Collections.emptyList()) }, { DataTypes.listOf(DataTypes.listOf(userType)), GenericType.listOf(GenericType.listOf(UdtValue.class)), DataTypes.listOf(DataTypes.listOf(DataTypes.BOOLEAN)), GenericType.listOf(GenericType.listOf(Boolean.class)), ImmutableList.of(Collections.emptyList()) }, // sets
{ DataTypes.setOf(DataTypes.INT), GenericType.setOf(Integer.class), DataTypes.setOf(DataTypes.BOOLEAN), GenericType.setOf(Boolean.class), Collections.emptySet() }, { DataTypes.setOf(DataTypes.TEXT), GenericType.setOf(String.class), DataTypes.setOf(DataTypes.BOOLEAN), GenericType.setOf(Boolean.class), Collections.emptySet() }, { DataTypes.setOf(DataTypes.BLOB), GenericType.setOf(ByteBuffer.class), DataTypes.setOf(DataTypes.BOOLEAN), GenericType.setOf(Boolean.class), Collections.emptySet() }, { DataTypes.setOf(DataTypes.INET), GenericType.setOf(InetAddress.class), DataTypes.setOf(DataTypes.BOOLEAN), GenericType.setOf(Boolean.class), Collections.emptySet() }, { DataTypes.setOf(tupleType), GenericType.setOf(TupleValue.class), DataTypes.setOf(DataTypes.BOOLEAN), GenericType.setOf(Boolean.class), Collections.emptySet() }, { DataTypes.setOf(userType), GenericType.setOf(UdtValue.class), DataTypes.setOf(DataTypes.BOOLEAN), GenericType.setOf(Boolean.class), Collections.emptySet() }, { DataTypes.setOf(DataTypes.setOf(DataTypes.INT)), GenericType.setOf(GenericType.setOf(Integer.class)), DataTypes.setOf(DataTypes.setOf(DataTypes.BOOLEAN)), GenericType.setOf(GenericType.setOf(Boolean.class)), ImmutableSet.of(Collections.emptySet()) }, { DataTypes.setOf(DataTypes.setOf(tupleType)), GenericType.setOf(GenericType.setOf(TupleValue.class)), DataTypes.setOf(DataTypes.setOf(DataTypes.BOOLEAN)), GenericType.setOf(GenericType.setOf(Boolean.class)), ImmutableSet.of(Collections.emptySet()) }, { DataTypes.setOf(DataTypes.setOf(userType)), GenericType.setOf(GenericType.setOf(UdtValue.class)), DataTypes.setOf(DataTypes.setOf(DataTypes.BOOLEAN)), GenericType.setOf(GenericType.setOf(Boolean.class)), ImmutableSet.of(Collections.emptySet()) }, // maps
{ DataTypes.mapOf(DataTypes.INT, DataTypes.TEXT), GenericType.mapOf(Integer.class, String.class), DataTypes.mapOf(DataTypes.BOOLEAN, DataTypes.BOOLEAN), GenericType.mapOf(Boolean.class, Boolean.class), Collections.emptyMap() }, { DataTypes.mapOf(DataTypes.BLOB, DataTypes.INET), GenericType.mapOf(ByteBuffer.class, InetAddress.class), DataTypes.mapOf(DataTypes.BOOLEAN, DataTypes.BOOLEAN), GenericType.mapOf(Boolean.class, Boolean.class), Collections.emptyMap() }, { DataTypes.mapOf(tupleType, tupleType), GenericType.mapOf(TupleValue.class, TupleValue.class), DataTypes.mapOf(DataTypes.BOOLEAN, DataTypes.BOOLEAN), GenericType.mapOf(Boolean.class, Boolean.class), Collections.emptyMap() }, { DataTypes.mapOf(userType, userType), GenericType.mapOf(UdtValue.class, UdtValue.class), DataTypes.mapOf(DataTypes.BOOLEAN, DataTypes.BOOLEAN), GenericType.mapOf(Boolean.class, Boolean.class), Collections.emptyMap() }, { DataTypes.mapOf(DataTypes.UUID, DataTypes.mapOf(DataTypes.INT, DataTypes.TEXT)), GenericType.mapOf(GenericType.UUID, GenericType.mapOf(Integer.class, String.class)), DataTypes.mapOf(DataTypes.UUID, DataTypes.mapOf(DataTypes.BOOLEAN, DataTypes.BOOLEAN)), GenericType.mapOf(GenericType.UUID, GenericType.mapOf(Boolean.class, Boolean.class)), ImmutableMap.of(UUID.randomUUID(), Collections.emptyMap()) }, { DataTypes.mapOf(DataTypes.mapOf(DataTypes.INT, DataTypes.TEXT), DataTypes.UUID), GenericType.mapOf(GenericType.mapOf(Integer.class, String.class), GenericType.UUID), DataTypes.mapOf(DataTypes.mapOf(DataTypes.BOOLEAN, DataTypes.BOOLEAN), DataTypes.UUID), GenericType.mapOf(GenericType.mapOf(Boolean.class, Boolean.class), GenericType.UUID), ImmutableMap.of(Collections.emptyMap(), UUID.randomUUID()) }, { DataTypes.mapOf(DataTypes.mapOf(userType, userType), DataTypes.mapOf(tupleType, tupleType)), GenericType.mapOf(GenericType.mapOf(UdtValue.class, UdtValue.class), GenericType.mapOf(TupleValue.class, TupleValue.class)), DataTypes.mapOf(DataTypes.mapOf(DataTypes.BOOLEAN, DataTypes.BOOLEAN), DataTypes.mapOf(DataTypes.BOOLEAN, DataTypes.BOOLEAN)), GenericType.mapOf(GenericType.mapOf(Boolean.class, Boolean.class), GenericType.mapOf(Boolean.class, Boolean.class)), ImmutableMap.of(Collections.emptyMap(), Collections.emptyMap()) } };
}
use of com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder in project java-driver by datastax.
the class GraphDataTypesTest method complexTypesAndGeoTests.
@Test
public void complexTypesAndGeoTests() throws IOException {
TupleType tuple = tupleOf(DseDataTypes.POINT, DseDataTypes.LINE_STRING, DseDataTypes.POLYGON);
tuple.attach(context);
verifySerDeBinary(tuple.newValue(Point.fromCoordinates(3.3, 4.4), LineString.fromPoints(Point.fromCoordinates(1, 1), Point.fromCoordinates(2, 2), Point.fromCoordinates(3, 3)), Polygon.fromPoints(Point.fromCoordinates(3, 4), Point.fromCoordinates(5, 4), Point.fromCoordinates(6, 6))));
UserDefinedType udt = new UserDefinedTypeBuilder("ks", "udt1").withField("a", DseDataTypes.POINT).withField("b", DseDataTypes.LINE_STRING).withField("c", DseDataTypes.POLYGON).build();
udt.attach(context);
verifySerDeBinary(udt.newValue(Point.fromCoordinates(3.3, 4.4), LineString.fromPoints(Point.fromCoordinates(1, 1), Point.fromCoordinates(2, 2), Point.fromCoordinates(3, 3)), Polygon.fromPoints(Point.fromCoordinates(3, 4), Point.fromCoordinates(5, 4), Point.fromCoordinates(6, 6))));
}
use of com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder in project java-driver by datastax.
the class DefaultUdtValueTest method should_format_to_string.
@Test
public void should_format_to_string() {
UserDefinedType type = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type")).withField(CqlIdentifier.fromInternal("t"), DataTypes.TEXT).withField(CqlIdentifier.fromInternal("i"), DataTypes.INT).withField(CqlIdentifier.fromInternal("d"), DataTypes.DOUBLE).build();
UdtValue udt = type.newValue().setString("t", "foobar").setDouble("d", 3.14);
assertThat(udt.getFormattedContents()).isEqualTo("{t:'foobar',i:NULL,d:3.14}");
}
use of com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder in project java-driver by datastax.
the class DefaultUdtValueTest method should_equate_instances_with_different_protocol_versions.
@Test
public void should_equate_instances_with_different_protocol_versions() {
UserDefinedType type1 = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type")).withField(CqlIdentifier.fromInternal("t"), DataTypes.TEXT).withField(CqlIdentifier.fromInternal("i"), DataTypes.INT).withField(CqlIdentifier.fromInternal("d"), DataTypes.DOUBLE).build();
type1.attach(attachmentPoint);
// create an idential type, but with a different attachment point
UserDefinedType type2 = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type")).withField(CqlIdentifier.fromInternal("t"), DataTypes.TEXT).withField(CqlIdentifier.fromInternal("i"), DataTypes.INT).withField(CqlIdentifier.fromInternal("d"), DataTypes.DOUBLE).build();
type2.attach(v3AttachmentPoint);
UdtValue udt1 = type1.newValue().setString("t", "some text string").setInt("i", 42).setDouble("d", 3.14);
UdtValue udt2 = type2.newValue().setString("t", "some text string").setInt("i", 42).setDouble("d", 3.14);
assertThat(udt1).isEqualTo(udt2);
}
use of com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder in project java-driver by datastax.
the class DefaultUdtValueTest method newInstance.
@Override
protected UdtValue newInstance(List<DataType> dataTypes, AttachmentPoint attachmentPoint) {
UserDefinedTypeBuilder builder = new UserDefinedTypeBuilder(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type"));
for (int i = 0; i < dataTypes.size(); i++) {
builder.withField(CqlIdentifier.fromInternal("field" + i), dataTypes.get(i));
}
UserDefinedType userDefinedType = builder.build();
userDefinedType.attach(attachmentPoint);
return userDefinedType.newValue();
}
Aggregations