Search in sources :

Example 51 with ResultSet

use of com.datastax.driver.core.ResultSet in project camel by apache.

the class CassandraProducer method execute.

/**
     * Execute CQL query using incoming message body has statement parameters.
     */
private ResultSet execute(Message message) {
    Object messageCql = message.getHeader(CassandraConstants.CQL_QUERY);
    // Convert Empty string to null
    if (messageCql instanceof String && ((String) messageCql).isEmpty()) {
        messageCql = null;
    }
    Object[] cqlParams = getCqlParams(message);
    ResultSet resultSet;
    Session session = getEndpoint().getSessionHolder().getSession();
    if (isPrepareStatements()) {
        resultSet = executePreparedStatement(session, messageCql, cqlParams);
    } else {
        resultSet = executeStatement(session, messageCql, cqlParams);
    }
    return resultSet;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Session(com.datastax.driver.core.Session)

Example 52 with ResultSet

use of com.datastax.driver.core.ResultSet in project camel by apache.

the class CassandraProducer method executePreparedStatement.

/**
     * Execute CQL as PreparedStatement
     */
private ResultSet executePreparedStatement(Session session, Object messageCql, Object[] cqlParams) {
    ResultSet resultSet;
    PreparedStatement lPreparedStatement;
    if (messageCql == null) {
        // URI CQL
        lPreparedStatement = this.preparedStatement;
    } else if (messageCql instanceof String) {
        // Message CQL
        lPreparedStatement = getEndpoint().prepareStatement((String) messageCql);
    } else if (messageCql instanceof RegularStatement) {
        // Message Statement
        lPreparedStatement = getEndpoint().getSession().prepare((RegularStatement) messageCql);
    } else {
        throw new IllegalArgumentException("Invalid " + CassandraConstants.CQL_QUERY + " header");
    }
    if (isEmpty(cqlParams)) {
        resultSet = session.execute(lPreparedStatement.bind());
    } else {
        resultSet = session.execute(lPreparedStatement.bind(cqlParams));
    }
    return resultSet;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) RegularStatement(com.datastax.driver.core.RegularStatement)

Example 53 with ResultSet

use of com.datastax.driver.core.ResultSet in project camel by apache.

the class CassandraProducer method executeStatement.

/**
     * Execute CQL as is
     */
private ResultSet executeStatement(Session session, Object messageCql, Object[] cqlParams) {
    ResultSet resultSet;
    String cql = null;
    RegularStatement statement = null;
    if (messageCql == null) {
        // URI CQL
        cql = getEndpoint().getCql();
    } else if (messageCql instanceof String) {
        // Message CQL
        cql = (String) messageCql;
    } else if (messageCql instanceof RegularStatement) {
        // Message Statement
        statement = (RegularStatement) messageCql;
    } else {
        throw new IllegalArgumentException("Invalid " + CassandraConstants.CQL_QUERY + " header");
    }
    if (statement != null) {
        resultSet = session.execute(statement);
    } else if (isEmpty(cqlParams)) {
        resultSet = session.execute(cql);
    } else {
        resultSet = session.execute(cql, cqlParams);
    }
    return resultSet;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) RegularStatement(com.datastax.driver.core.RegularStatement)

Example 54 with ResultSet

use of com.datastax.driver.core.ResultSet in project presto by prestodb.

the class CassandraTokenSplitManager method getSizeEstimates.

private List<SizeEstimate> getSizeEstimates(String keyspaceName, String tableName) {
    checkSizeEstimatesTableExist();
    Statement statement = select("range_start", "range_end", "mean_partition_size", "partitions_count").from(SYSTEM, SIZE_ESTIMATES).where(eq("keyspace_name", keyspaceName)).and(eq("table_name", tableName));
    ResultSet result = session.executeWithSession(session -> session.execute(statement));
    ImmutableList.Builder<SizeEstimate> estimates = ImmutableList.builder();
    for (Row row : result.all()) {
        SizeEstimate estimate = new SizeEstimate(row.getString("range_start"), row.getString("range_end"), row.getLong("mean_partition_size"), row.getLong("partitions_count"));
        estimates.add(estimate);
    }
    return estimates.build();
}
Also used : Statement(com.datastax.driver.core.Statement) ImmutableList(com.google.common.collect.ImmutableList) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row)

Example 55 with ResultSet

use of com.datastax.driver.core.ResultSet in project presto by prestodb.

the class EmbeddedCassandra method checkConnectivity.

private static void checkConnectivity(CassandraSession session) {
    ResultSet result = session.execute("SELECT release_version FROM system.local");
    List<Row> rows = result.all();
    assertEquals(rows.size(), 1);
    String version = rows.get(0).getString(0);
    log.info("Cassandra version: %s", version);
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row)

Aggregations

ResultSet (com.datastax.driver.core.ResultSet)64 Row (com.datastax.driver.core.Row)35 Test (org.junit.Test)25 BoundStatement (com.datastax.driver.core.BoundStatement)11 Session (com.datastax.driver.core.Session)10 ArrayList (java.util.ArrayList)9 Cluster (com.datastax.driver.core.Cluster)8 Statement (com.datastax.driver.core.Statement)7 PreparedStatement (com.datastax.driver.core.PreparedStatement)5 List (java.util.List)5 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 Select (com.datastax.driver.core.querybuilder.Select)4 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)4 BatchStatement (com.datastax.driver.core.BatchStatement)3 RegularStatement (com.datastax.driver.core.RegularStatement)3 Update (com.datastax.driver.core.querybuilder.Update)3 ImmutableList (com.google.common.collect.ImmutableList)3 IgniteException (org.apache.ignite.IgniteException)3 RandomSleeper (org.apache.ignite.cache.store.cassandra.common.RandomSleeper)3 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)2