Search in sources :

Example 1 with DefaultCodecRegistry

use of com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry in project dsbulk by datastax.

the class DefaultReadResultMapperTest method setUp.

@BeforeEach
void setUp() {
    recordMetadata = new TestRecordMetadata(ImmutableMap.of(F0, GenericType.of(Integer.class), F1, GenericType.of(String.class), F2, GenericType.of(String.class)));
    mapping = mock(Mapping.class);
    row = mock(Row.class);
    when(row.codecRegistry()).thenReturn(new DefaultCodecRegistry("test"));
    result = mock(ReadResult.class);
    when(result.getRow()).thenReturn(Optional.of(row));
    ColumnDefinition c1 = mockColumnDefinition(C1.asIdentifier(), DataTypes.INT);
    ColumnDefinition c2 = mockColumnDefinition(C2.asIdentifier(), DataTypes.TEXT);
    ColumnDefinition c3 = mockColumnDefinition(C3.asIdentifier(), DataTypes.TEXT);
    ColumnDefinitions variables = mockColumnDefinitions(c1, c2, c3);
    when(row.getColumnDefinitions()).thenReturn(variables);
    when(mapping.fields()).thenReturn(newLinkedHashSet(F0, F1, F2));
    when(mapping.fieldToVariables(F0)).thenReturn(singleton(C1));
    when(mapping.fieldToVariables(F1)).thenReturn(singleton(C2));
    when(mapping.fieldToVariables(F2)).thenReturn(singleton(C3));
    when(mapping.variableToFields(C1)).thenReturn(singleton(F0));
    when(mapping.variableToFields(C2)).thenReturn(singleton(F1));
    when(mapping.variableToFields(C3)).thenReturn(singleton(F2));
    codec1 = TypeCodecs.INT;
    TypeCodec<String> codec2 = TypeCodecs.TEXT;
    when(mapping.codec(C1, DataTypes.INT, GenericType.of(Integer.class))).thenReturn(codec1);
    when(mapping.codec(C2, DataTypes.TEXT, GenericType.of(String.class))).thenReturn(codec2);
    when(mapping.codec(C3, DataTypes.TEXT, GenericType.of(String.class))).thenReturn(codec2);
    when(row.get(C1.asIdentifier(), codec1)).thenReturn(42);
    when(row.get(C2.asIdentifier(), codec2)).thenReturn("foo");
    when(row.get(C3.asIdentifier(), codec2)).thenReturn("bar");
    // to generate locations
    BoundStatement boundStatement = mock(BoundStatement.class);
    PreparedStatement ps = mock(PreparedStatement.class);
    when(result.getStatement()).then(args -> boundStatement);
    when(boundStatement.getPreparedStatement()).thenReturn(ps);
    when(ps.getQuery()).thenReturn("irrelevant");
    ColumnDefinition start = mockColumnDefinition("start", DataTypes.BIGINT);
    ColumnDefinition end = mockColumnDefinition("end", DataTypes.BIGINT);
    ColumnDefinitions boundVariables = mockColumnDefinitions(start, end);
    when(ps.getVariableDefinitions()).thenReturn(boundVariables);
    when(row.getObject(C1.asIdentifier())).thenReturn(42);
    when(row.getObject(C2.asIdentifier())).thenReturn("foo");
    when(row.getObject(C3.asIdentifier())).thenReturn("bar");
    when(boundStatement.getObject(CqlIdentifier.fromInternal("start"))).thenReturn(1234L);
    when(boundStatement.getObject(CqlIdentifier.fromInternal("end"))).thenReturn(5678L);
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) DriverUtils.mockColumnDefinitions(com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockColumnDefinitions) DefaultCodecRegistry(com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry) Mapping(com.datastax.oss.dsbulk.mapping.Mapping) ReadResult(com.datastax.oss.dsbulk.executor.api.result.ReadResult) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) Row(com.datastax.oss.driver.api.core.cql.Row) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement) DriverUtils.mockColumnDefinition(com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockColumnDefinition) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with DefaultCodecRegistry

use of com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry in project java-driver by datastax.

the class DefaultDriverContext method buildCodecRegistry.

protected CodecRegistry buildCodecRegistry(ProgrammaticArguments arguments) {
    MutableCodecRegistry registry = arguments.getCodecRegistry();
    if (registry == null) {
        registry = new DefaultCodecRegistry(this.sessionName);
    }
    registry.register(arguments.getTypeCodecs());
    DseTypeCodecsRegistrar.registerDseCodecs(registry);
    return registry;
}
Also used : MutableCodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.MutableCodecRegistry) DefaultCodecRegistry(com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry)

Aggregations

DefaultCodecRegistry (com.datastax.oss.driver.internal.core.type.codec.registry.DefaultCodecRegistry)2 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)1 ColumnDefinition (com.datastax.oss.driver.api.core.cql.ColumnDefinition)1 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)1 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)1 Row (com.datastax.oss.driver.api.core.cql.Row)1 MutableCodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.MutableCodecRegistry)1 ReadResult (com.datastax.oss.dsbulk.executor.api.result.ReadResult)1 Mapping (com.datastax.oss.dsbulk.mapping.Mapping)1 DriverUtils.mockColumnDefinition (com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockColumnDefinition)1 DriverUtils.mockColumnDefinitions (com.datastax.oss.dsbulk.tests.driver.DriverUtils.mockColumnDefinitions)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1