Search in sources :

Example 6 with ColumnDefinition

use of com.datastax.oss.driver.api.core.cql.ColumnDefinition in project java-driver by datastax.

the class ConversionsTest method variables.

private ColumnDefinitions variables(String... columnNames) {
    ImmutableList.Builder<ColumnDefinition> columns = ImmutableList.builderWithExpectedSize(columnNames.length);
    for (String columnName : columnNames) {
        ColumnDefinition column = mock(ColumnDefinition.class);
        when(column.getName()).thenReturn(CqlIdentifier.fromInternal(columnName));
        columns.add(column);
    }
    return DefaultColumnDefinitions.valueOf(columns.build());
}
Also used : ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition)

Example 7 with ColumnDefinition

use of com.datastax.oss.driver.api.core.cql.ColumnDefinition in project java-driver by datastax.

the class DefaultAsyncResultSetTest method should_fail_to_report_if_applied_if_column_present_but_empty.

@Test(expected = IllegalStateException.class)
public void should_fail_to_report_if_applied_if_column_present_but_empty() {
    // 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
    DefaultAsyncResultSet resultSet = new DefaultAsyncResultSet(columnDefinitions, executionInfo, new ArrayDeque<>(), session, context);
    // Then
    resultSet.wasApplied();
}
Also used : ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) Test(org.junit.Test)

Example 8 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_true.

@Test
public void should_report_not_applied_if_column_present_and_true() {
    // 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(true, DefaultProtocolVersion.DEFAULT)));
    // When
    DefaultAsyncResultSet resultSet = new DefaultAsyncResultSet(columnDefinitions, executionInfo, data, session, context);
    // Then
    assertThat(resultSet.wasApplied()).isTrue();
}
Also used : List(java.util.List) ArrayDeque(java.util.ArrayDeque) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition) Test(org.junit.Test)

Example 9 with ColumnDefinition

use of com.datastax.oss.driver.api.core.cql.ColumnDefinition in project java-driver by datastax.

the class Conversions method toColumnDefinitions.

public static ColumnDefinitions toColumnDefinitions(RowsMetadata metadata, InternalDriverContext context) {
    ColumnDefinition[] values = new ColumnDefinition[metadata.columnSpecs.size()];
    int i = 0;
    for (ColumnSpec columnSpec : metadata.columnSpecs) {
        values[i++] = new DefaultColumnDefinition(columnSpec, context);
    }
    return DefaultColumnDefinitions.valueOf(ImmutableList.copyOf(values));
}
Also used : ColumnSpec(com.datastax.oss.protocol.internal.response.result.ColumnSpec) ColumnDefinition(com.datastax.oss.driver.api.core.cql.ColumnDefinition)

Example 10 with ColumnDefinition

use of com.datastax.oss.driver.api.core.cql.ColumnDefinition in project java-driver by datastax.

the class RequestLogFormatterTest method mockPreparedStatement.

private PreparedStatement mockPreparedStatement(String query, Map<String, DataType> variables) {
    ImmutableList.Builder<ColumnDefinition> definitions = ImmutableList.builder();
    int i = 0;
    for (Map.Entry<String, DataType> entry : variables.entrySet()) {
        definitions.add(new DefaultColumnDefinition(new ColumnSpec("test", "foo", entry.getKey(), i, RawType.PRIMITIVES.get(entry.getValue().getProtocolCode())), context));
    }
    return new DefaultPreparedStatement(Bytes.fromHexString("0x"), query, DefaultColumnDefinitions.valueOf(definitions.build()), Collections.emptyList(), null, null, null, Collections.emptyMap(), null, null, null, null, null, Collections.emptyMap(), null, null, null, Integer.MIN_VALUE, null, null, false, context.getCodecRegistry(), context.getProtocolVersion());
}
Also used : DefaultPreparedStatement(com.datastax.oss.driver.internal.core.cql.DefaultPreparedStatement) ColumnSpec(com.datastax.oss.protocol.internal.response.result.ColumnSpec) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) DefaultColumnDefinition(com.datastax.oss.driver.internal.core.cql.DefaultColumnDefinition) DataType(com.datastax.oss.driver.api.core.type.DataType) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap) Map(java.util.Map) DefaultColumnDefinition(com.datastax.oss.driver.internal.core.cql.DefaultColumnDefinition) 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