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;
}
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;
}
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;
}
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();
}
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);
}
Aggregations