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);
}
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;
}
Aggregations