Search in sources :

Example 1 with ColumnDefinition

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();
}
Also used : List(java.util.List) ArrayDeque(java.util.ArrayDeque) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) Test(org.junit.Test)

Example 2 with ColumnDefinition

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");
}
Also used : Row(com.datastax.oss.driver.api.core.cql.Row) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) Test(org.junit.Test)

Example 3 with ColumnDefinition

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);
}
Also used : ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) Before(org.junit.Before)

Example 4 with ColumnDefinition

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);
}
Also used : Column(jakarta.nosql.column.Column) ArrayList(java.util.ArrayList) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition)

Example 5 with ColumnDefinition

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;
}
Also used : ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) DataType(com.datastax.oss.driver.api.core.type.DataType) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) CodecRegistry(com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition)

Aggregations

ColumnDefinition (com.datastax.oss.driver.api.core.cql.ColumnDefinition)10 Test (org.junit.Test)4 DataType (com.datastax.oss.driver.api.core.type.DataType)2 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)2 ColumnSpec (com.datastax.oss.protocol.internal.response.result.ColumnSpec)2 ArrayDeque (java.util.ArrayDeque)2 List (java.util.List)2 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 CodecRegistry (com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry)1 DefaultColumnDefinition (com.datastax.oss.driver.internal.core.cql.DefaultColumnDefinition)1 DefaultPreparedStatement (com.datastax.oss.driver.internal.core.cql.DefaultPreparedStatement)1 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)1 Column (jakarta.nosql.column.Column)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Before (org.junit.Before)1