Search in sources :

Example 1 with UserDefinedTypeBuilder

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()) } };
}
Also used : BigInteger(java.math.BigInteger) UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) DefaultUdtValue(com.datastax.oss.driver.internal.core.data.DefaultUdtValue) 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) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) DefaultTupleValue(com.datastax.oss.driver.internal.core.data.DefaultTupleValue) TupleValue(com.datastax.oss.driver.api.core.data.TupleValue) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider)

Example 2 with UserDefinedTypeBuilder

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))));
}
Also used : 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) Test(org.junit.Test)

Example 3 with UserDefinedTypeBuilder

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}");
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) UserDefinedTypeBuilder(com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder) Test(org.junit.Test)

Example 4 with UserDefinedTypeBuilder

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);
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) UserDefinedTypeBuilder(com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder) Test(org.junit.Test)

Example 5 with UserDefinedTypeBuilder

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();
}
Also used : UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) UserDefinedTypeBuilder(com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder) AttachmentPoint(com.datastax.oss.driver.api.core.detach.AttachmentPoint)

Aggregations

UserDefinedTypeBuilder (com.datastax.oss.driver.internal.core.type.UserDefinedTypeBuilder)16 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)15 Test (org.junit.Test)10 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)9 TupleType (com.datastax.oss.driver.api.core.type.TupleType)5 TupleValue (com.datastax.oss.driver.api.core.data.TupleValue)3 DefaultUdtValue (com.datastax.oss.driver.internal.core.data.DefaultUdtValue)3 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)3 AttachmentPoint (com.datastax.oss.driver.api.core.detach.AttachmentPoint)2 DefaultTupleValue (com.datastax.oss.driver.internal.core.data.DefaultTupleValue)2 MetadataRefresh (com.datastax.oss.driver.internal.core.metadata.MetadataRefresh)2 DefaultKeyspaceMetadata (com.datastax.oss.driver.internal.core.metadata.schema.DefaultKeyspaceMetadata)2 BigInteger (java.math.BigInteger)2 InetAddress (java.net.InetAddress)2 ByteBuffer (java.nio.ByteBuffer)2 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 DataType (com.datastax.oss.driver.api.core.type.DataType)1 CharsetCodec (com.datastax.oss.driver.api.querybuilder.CharsetCodec)1 DefaultTupleType (com.datastax.oss.driver.internal.core.type.DefaultTupleType)1 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)1