Search in sources :

Example 1 with DefaultUserDefinedType

use of com.datastax.oss.driver.internal.core.type.DefaultUserDefinedType in project java-driver by datastax.

the class UdtCodecTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    when(attachmentPoint.getCodecRegistry()).thenReturn(codecRegistry);
    when(attachmentPoint.getProtocolVersion()).thenReturn(ProtocolVersion.DEFAULT);
    intCodec = spy(TypeCodecs.INT);
    doubleCodec = spy(TypeCodecs.DOUBLE);
    textCodec = spy(TypeCodecs.TEXT);
    // Called by the getters/setters
    when(codecRegistry.codecFor(DataTypes.INT, Integer.class)).thenAnswer(i -> intCodec);
    when(codecRegistry.codecFor(DataTypes.DOUBLE, Double.class)).thenAnswer(i -> doubleCodec);
    when(codecRegistry.codecFor(DataTypes.TEXT, String.class)).thenAnswer(i -> textCodec);
    // Called by format/parse
    when(codecRegistry.codecFor(DataTypes.INT)).thenAnswer(i -> intCodec);
    when(codecRegistry.codecFor(DataTypes.DOUBLE)).thenAnswer(i -> doubleCodec);
    when(codecRegistry.codecFor(DataTypes.TEXT)).thenAnswer(i -> textCodec);
    userType = new DefaultUserDefinedType(CqlIdentifier.fromInternal("ks"), CqlIdentifier.fromInternal("type"), false, ImmutableList.of(CqlIdentifier.fromInternal("field1"), CqlIdentifier.fromInternal("field2"), CqlIdentifier.fromInternal("field3")), ImmutableList.of(DataTypes.INT, DataTypes.DOUBLE, DataTypes.TEXT), attachmentPoint);
    codec = TypeCodecs.udtOf(userType);
}
Also used : DefaultUserDefinedType(com.datastax.oss.driver.internal.core.type.DefaultUserDefinedType) Before(org.junit.Before)

Example 2 with DefaultUserDefinedType

use of com.datastax.oss.driver.internal.core.type.DefaultUserDefinedType in project java-driver by datastax.

the class UserDefinedTypeParser method parseType.

private UserDefinedType parseType(AdminRow row, CqlIdentifier keyspaceId, Map<CqlIdentifier, UserDefinedType> userDefinedTypes) {
    // Cassandra < 3.0:
    // CREATE TABLE system.schema_usertypes (
    // keyspace_name text,
    // type_name text,
    // field_names list<text>,
    // field_types list<text>,
    // PRIMARY KEY (keyspace_name, type_name)
    // ) WITH CLUSTERING ORDER BY (type_name ASC)
    // 
    // Cassandra >= 3.0:
    // CREATE TABLE system_schema.types (
    // keyspace_name text,
    // type_name text,
    // field_names frozen<list<text>>,
    // field_types frozen<list<text>>,
    // PRIMARY KEY (keyspace_name, type_name)
    // ) WITH CLUSTERING ORDER BY (type_name ASC)
    CqlIdentifier name = CqlIdentifier.fromInternal(row.getString("type_name"));
    List<CqlIdentifier> fieldNames = ImmutableList.copyOf(Lists.transform(row.getListOfString("field_names"), CqlIdentifier::fromInternal));
    List<DataType> fieldTypes = dataTypeParser.parse(keyspaceId, row.getListOfString("field_types"), userDefinedTypes, context);
    return new DefaultUserDefinedType(keyspaceId, name, false, fieldNames, fieldTypes, context);
}
Also used : DataType(com.datastax.oss.driver.api.core.type.DataType) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) DefaultUserDefinedType(com.datastax.oss.driver.internal.core.type.DefaultUserDefinedType)

Aggregations

DefaultUserDefinedType (com.datastax.oss.driver.internal.core.type.DefaultUserDefinedType)2 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 DataType (com.datastax.oss.driver.api.core.type.DataType)1 Before (org.junit.Before)1