use of com.datastax.driver.core.ResultSet in project camel by apache.
the class ResultSetConversionStrategiesTest method testAll.
@Test
public void testAll() {
ResultSetConversionStrategy strategy = ResultSetConversionStrategies.fromName("ALL");
ResultSet resultSet = mock(ResultSet.class);
List<Row> rows = Collections.nCopies(20, mock(Row.class));
when(resultSet.all()).thenReturn(rows);
Object body = strategy.getBody(resultSet);
assertTrue(body instanceof List);
assertSame(rows, body);
}
use of com.datastax.driver.core.ResultSet in project camel by apache.
the class ResultSetConversionStrategiesTest method testLimit.
@Test
public void testLimit() {
ResultSetConversionStrategy strategy = ResultSetConversionStrategies.fromName("LIMIT_10");
ResultSet resultSet = mock(ResultSet.class);
List<Row> rows = Collections.nCopies(20, mock(Row.class));
when(resultSet.iterator()).thenReturn(rows.iterator());
Object body = strategy.getBody(resultSet);
assertTrue(body instanceof List);
assertEquals(10, ((List) body).size());
}
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;
}
Aggregations