Search in sources :

Example 1 with RowsMetadata

use of com.datastax.oss.protocol.internal.response.result.RowsMetadata in project java-driver by datastax.

the class CqlPrepareHandlerTest method simplePrepared.

private static Message simplePrepared() {
    RowsMetadata variablesMetadata = new RowsMetadata(ImmutableList.of(new ColumnSpec("ks", "table", "key", 0, RawType.PRIMITIVES.get(ProtocolConstants.DataType.VARCHAR))), null, new int[] { 0 }, null);
    RowsMetadata resultMetadata = new RowsMetadata(ImmutableList.of(new ColumnSpec("ks", "table", "message", 0, RawType.PRIMITIVES.get(ProtocolConstants.DataType.VARCHAR))), null, new int[] {}, null);
    return new Prepared(Bytes.fromHexString("0xffff").array(), null, variablesMetadata, resultMetadata);
}
Also used : RowsMetadata(com.datastax.oss.protocol.internal.response.result.RowsMetadata) ColumnSpec(com.datastax.oss.protocol.internal.response.result.ColumnSpec) Prepared(com.datastax.oss.protocol.internal.response.result.Prepared)

Example 2 with RowsMetadata

use of com.datastax.oss.protocol.internal.response.result.RowsMetadata in project java-driver by datastax.

the class CqlRequestHandlerTestBase method singleRow.

// Returns a single row, with a single "message" column with the value "hello, world"
protected static Message singleRow() {
    RowsMetadata metadata = new RowsMetadata(ImmutableList.of(new ColumnSpec("ks", "table", "message", 0, RawType.PRIMITIVES.get(ProtocolConstants.DataType.VARCHAR))), null, new int[] {}, null);
    Queue<List<ByteBuffer>> data = new ArrayDeque<>();
    data.add(ImmutableList.of(Bytes.fromHexString("0x68656C6C6F2C20776F726C64")));
    return new DefaultRows(metadata, data);
}
Also used : RowsMetadata(com.datastax.oss.protocol.internal.response.result.RowsMetadata) ColumnSpec(com.datastax.oss.protocol.internal.response.result.ColumnSpec) DefaultRows(com.datastax.oss.protocol.internal.response.result.DefaultRows) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) List(java.util.List) ArrayDeque(java.util.ArrayDeque)

Example 3 with RowsMetadata

use of com.datastax.oss.protocol.internal.response.result.RowsMetadata in project java-driver by datastax.

the class Conversions method getResultDefinitions.

public static ColumnDefinitions getResultDefinitions(Rows rows, Statement<?> statement, InternalDriverContext context) {
    RowsMetadata rowsMetadata = rows.getMetadata();
    if (rowsMetadata.columnSpecs.isEmpty()) {
        // If the response has no metadata, it means the request had SKIP_METADATA set, the driver
        // only ever does that for bound statements.
        BoundStatement boundStatement = (BoundStatement) statement;
        return boundStatement.getPreparedStatement().getResultSetDefinitions();
    } else {
        // The response has metadata, always use it above anything else we might have locally.
        ColumnDefinitions definitions = toColumnDefinitions(rowsMetadata, context);
        // prepared statement's copy of the metadata
        if (rowsMetadata.newResultMetadataId != null) {
            BoundStatement boundStatement = (BoundStatement) statement;
            PreparedStatement preparedStatement = boundStatement.getPreparedStatement();
            preparedStatement.setResultMetadata(ByteBuffer.wrap(rowsMetadata.newResultMetadataId).asReadOnlyBuffer(), definitions);
        }
        return definitions;
    }
}
Also used : RowsMetadata(com.datastax.oss.protocol.internal.response.result.RowsMetadata) ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) BoundStatement(com.datastax.oss.driver.api.core.cql.BoundStatement)

Example 4 with RowsMetadata

use of com.datastax.oss.protocol.internal.response.result.RowsMetadata in project java-driver by datastax.

the class ReprepareOnUpTest method preparedIdRows.

private Rows preparedIdRows(char... values) {
    ColumnSpec preparedIdSpec = new ColumnSpec("system", "prepared_statements", "prepared_id", 0, RawType.PRIMITIVES.get(ProtocolConstants.DataType.BLOB));
    RowsMetadata rowsMetadata = new RowsMetadata(ImmutableList.of(preparedIdSpec), null, null, null);
    Queue<List<ByteBuffer>> data = new ArrayDeque<>();
    for (char value : values) {
        data.add(ImmutableList.of(Bytes.fromHexString("0x0" + value)));
    }
    return new DefaultRows(rowsMetadata, data);
}
Also used : RowsMetadata(com.datastax.oss.protocol.internal.response.result.RowsMetadata) ColumnSpec(com.datastax.oss.protocol.internal.response.result.ColumnSpec) DefaultRows(com.datastax.oss.protocol.internal.response.result.DefaultRows) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) List(java.util.List) ArrayDeque(java.util.ArrayDeque)

Example 5 with RowsMetadata

use of com.datastax.oss.protocol.internal.response.result.RowsMetadata in project java-driver by datastax.

the class TestResponses method clusterNameResponse.

/**
 * The response to the query run by each connection to check if the cluster name matches.
 */
public static Rows clusterNameResponse(String actualClusterName) {
    ColumnSpec colSpec = new ColumnSpec("system", "local", "cluster_name", 0, RawType.PRIMITIVES.get(ProtocolConstants.DataType.VARCHAR));
    RowsMetadata metadata = new RowsMetadata(ImmutableList.of(colSpec), null, null, null);
    Queue<List<ByteBuffer>> data = Lists.newLinkedList();
    data.add(Lists.newArrayList(ByteBuffer.wrap(actualClusterName.getBytes(Charsets.UTF_8))));
    return new DefaultRows(metadata, data);
}
Also used : RowsMetadata(com.datastax.oss.protocol.internal.response.result.RowsMetadata) ColumnSpec(com.datastax.oss.protocol.internal.response.result.ColumnSpec) DefaultRows(com.datastax.oss.protocol.internal.response.result.DefaultRows) ImmutableList(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList) List(java.util.List)

Aggregations

RowsMetadata (com.datastax.oss.protocol.internal.response.result.RowsMetadata)5 ColumnSpec (com.datastax.oss.protocol.internal.response.result.ColumnSpec)4 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)3 DefaultRows (com.datastax.oss.protocol.internal.response.result.DefaultRows)3 List (java.util.List)3 ArrayDeque (java.util.ArrayDeque)2 BoundStatement (com.datastax.oss.driver.api.core.cql.BoundStatement)1 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)1 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)1 Prepared (com.datastax.oss.protocol.internal.response.result.Prepared)1