use of com.datastax.oss.driver.api.core.cql.ColumnDefinition in project java-driver by datastax.
the class DefaultAsyncResultSetTest method should_report_not_applied_if_column_present_and_false.
@Test
public void should_report_not_applied_if_column_present_and_false() {
// Given
when(columnDefinitions.contains("[applied]")).thenReturn(true);
ColumnDefinition columnDefinition = mock(ColumnDefinition.class);
when(columnDefinition.getType()).thenReturn(DataTypes.BOOLEAN);
when(columnDefinitions.get("[applied]")).thenReturn(columnDefinition);
when(columnDefinitions.firstIndexOf("[applied]")).thenReturn(0);
when(columnDefinitions.get(0)).thenReturn(columnDefinition);
Queue<List<ByteBuffer>> data = new ArrayDeque<>();
data.add(Lists.newArrayList(TypeCodecs.BOOLEAN.encode(false, DefaultProtocolVersion.DEFAULT)));
// When
DefaultAsyncResultSet resultSet = new DefaultAsyncResultSet(columnDefinitions, executionInfo, data, session, context);
// Then
assertThat(resultSet.wasApplied()).isFalse();
}
use of com.datastax.oss.driver.api.core.cql.ColumnDefinition in project java-driver by datastax.
the class SerializationIT method should_serialize_row.
@Test
public void should_serialize_row() {
// Given
SIMULACRON_RULE.cluster().prime(when("mock query").then(rows().row("t", "mock data").columnTypes("t", "varchar")));
Row row = SESSION_RULE.session().execute("mock query").one();
// When
row = SerializationHelper.serializeAndDeserialize(row);
// Then
ColumnDefinition columnDefinition = row.getColumnDefinitions().get("t");
assertThat(columnDefinition.getType()).isEqualTo(DataTypes.TEXT);
assertThat(row.getString("t")).isEqualTo("mock data");
}
use of com.datastax.oss.driver.api.core.cql.ColumnDefinition in project java-driver by datastax.
the class AsyncPagingIterableWrapperTest method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
// One single column "i" of type int:
when(columnDefinitions.contains("i")).thenReturn(true);
ColumnDefinition iDefinition = mock(ColumnDefinition.class);
when(iDefinition.getType()).thenReturn(DataTypes.INT);
when(columnDefinitions.get("i")).thenReturn(iDefinition);
when(columnDefinitions.firstIndexOf("i")).thenReturn(0);
when(columnDefinitions.get(0)).thenReturn(iDefinition);
when(context.getCodecRegistry()).thenReturn(CodecRegistry.DEFAULT);
when(context.getProtocolVersion()).thenReturn(DefaultProtocolVersion.DEFAULT);
}
use of com.datastax.oss.driver.api.core.cql.ColumnDefinition in project jnosql-diana-driver by eclipse.
the class CassandraConverter method toDocumentEntity.
public static ColumnEntity toDocumentEntity(Row row) {
List<Column> columns = new ArrayList<>();
String columnFamily = "";
for (ColumnDefinition definition : row.getColumnDefinitions()) {
columnFamily = definition.getTable().asInternal();
Object result = CassandraConverter.get(definition, row);
if (Objects.nonNull(result)) {
columns.add(getColumn(definition, result));
}
}
return ColumnEntity.of(columnFamily, columns);
}
use of com.datastax.oss.driver.api.core.cql.ColumnDefinition in project thingsboard by thingsboard.
the class AbstractBufferedRateExecutor method toStringWithValues.
private static String toStringWithValues(BoundStatement boundStatement, ProtocolVersion protocolVersion) {
CodecRegistry codecRegistry = boundStatement.codecRegistry();
PreparedStatement preparedStatement = boundStatement.getPreparedStatement();
String query = preparedStatement.getQuery();
ColumnDefinitions defs = preparedStatement.getVariableDefinitions();
int index = 0;
for (ColumnDefinition def : defs) {
DataType type = def.getType();
TypeCodec<Object> codec = codecRegistry.codecFor(type);
if (boundStatement.getBytesUnsafe(index) != null) {
Object value = codec.decode(boundStatement.getBytesUnsafe(index), protocolVersion);
String replacement = Matcher.quoteReplacement(codec.format(value));
query = query.replaceFirst("\\?", replacement);
}
index++;
}
return query;
}
Aggregations