Search in sources :

Example 66 with ResultSet

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

the class CassandraComponentProducerTest method testRequestUriCql.

@Test
public void testRequestUriCql() throws Exception {
    if (!canTest()) {
        return;
    }
    Object response = producerTemplate.requestBody(Arrays.asList("w_jiang", "Willem", "Jiang"));
    Cluster cluster = CassandraUnitUtils.cassandraCluster();
    Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
    ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "w_jiang");
    Row row = resultSet.one();
    assertNotNull(row);
    assertEquals("Willem", row.getString("first_name"));
    assertEquals("Jiang", row.getString("last_name"));
    session.close();
    cluster.close();
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 67 with ResultSet

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

the class CassandraComponentProducerTest method testEndpointNoCqlParameter.

/**
     * Simulate different CQL statements in the incoming message containing a header with RegularStatement, justifying the cassandracql endpoint not containing a "cql" Uri parameter
     */
@Test
public void testEndpointNoCqlParameter() throws Exception {
    if (!canTest()) {
        return;
    }
    Update.Where updateFirstName = update("camel_user").with(set("first_name", bindMarker())).where(eq("login", bindMarker()));
    @SuppressWarnings("unused") Object response1 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[] { "Claus 2", "c_ibsen" }, CassandraConstants.CQL_QUERY, updateFirstName);
    Cluster cluster = CassandraUnitUtils.cassandraCluster();
    Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
    ResultSet resultSet1 = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
    Row row1 = resultSet1.one();
    assertNotNull(row1);
    assertEquals("Claus 2", row1.getString("first_name"));
    assertEquals("Ibsen", row1.getString("last_name"));
    Update.Where updateLastName = update("camel_user").with(set("last_name", bindMarker())).where(eq("login", bindMarker()));
    @SuppressWarnings("unused") Object response2 = producerTemplateNoEndpointCql.requestBodyAndHeader(new Object[] { "Ibsen 2", "c_ibsen" }, CassandraConstants.CQL_QUERY, updateLastName);
    ResultSet resultSet2 = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
    Row row2 = resultSet2.one();
    assertNotNull(row2);
    assertEquals("Claus 2", row2.getString("first_name"));
    assertEquals("Ibsen 2", row2.getString("last_name"));
    session.close();
    cluster.close();
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) Row(com.datastax.driver.core.Row) Update(com.datastax.driver.core.querybuilder.Update) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 68 with ResultSet

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

the class CassandraConsumer method poll.

@Override
protected int poll() throws Exception {
    // Execute CQL Query
    Session session = getEndpoint().getSessionHolder().getSession();
    ResultSet resultSet;
    if (isPrepareStatements()) {
        resultSet = session.execute(preparedStatement.bind());
    } else {
        resultSet = session.execute(getEndpoint().getCql());
    }
    // Create message from ResultSet
    Exchange exchange = getEndpoint().createExchange();
    Message message = exchange.getIn();
    getEndpoint().fillMessage(resultSet, message);
    try {
        // send message to next processor in the route
        getProcessor().process(exchange);
        // number of messages polled
        return 1;
    } finally {
        // log exception if an exception occurred and was not handled
        if (exchange.getException() != null) {
            getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) ResultSet(com.datastax.driver.core.ResultSet) Session(com.datastax.driver.core.Session)

Example 69 with ResultSet

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

the class CassandraComponentProducerUnpreparedTest method testRequestUriCql.

@Test
public void testRequestUriCql() throws Exception {
    Object response = producerTemplate.requestBody(Arrays.asList("w_jiang", "Willem", "Jiang"));
    Cluster cluster = CassandraUnitUtils.cassandraCluster();
    Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
    ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "w_jiang");
    Row row = resultSet.one();
    assertNotNull(row);
    assertEquals("Willem", row.getString("first_name"));
    assertEquals("Jiang", row.getString("last_name"));
    session.close();
    cluster.close();
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 70 with ResultSet

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

the class CassandraComponentProducerUnpreparedTest method testRequestMessageCql.

@Test
public void testRequestMessageCql() throws Exception {
    Object response = producerTemplate.requestBodyAndHeader(new Object[] { "Claus 2", "Ibsen 2", "c_ibsen" }, CassandraConstants.CQL_QUERY, "update camel_user set first_name=?, last_name=? where login=?");
    Cluster cluster = CassandraUnitUtils.cassandraCluster();
    Session session = cluster.connect(CassandraUnitUtils.KEYSPACE);
    ResultSet resultSet = session.execute("select login, first_name, last_name from camel_user where login = ?", "c_ibsen");
    Row row = resultSet.one();
    assertNotNull(row);
    assertEquals("Claus 2", row.getString("first_name"));
    assertEquals("Ibsen 2", row.getString("last_name"));
    session.close();
    cluster.close();
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Aggregations

ResultSet (com.datastax.driver.core.ResultSet)95 Row (com.datastax.driver.core.Row)61 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)17 BoundStatement (com.datastax.driver.core.BoundStatement)13 Session (com.datastax.driver.core.Session)12 Cluster (com.datastax.driver.core.Cluster)10 Statement (com.datastax.driver.core.Statement)8 List (java.util.List)8 PreparedStatement (com.datastax.driver.core.PreparedStatement)7 ByteBuffer (java.nio.ByteBuffer)5 StaticBuffer (org.janusgraph.diskstorage.StaticBuffer)5 BatchStatement (com.datastax.driver.core.BatchStatement)4 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 Select (com.datastax.driver.core.querybuilder.Select)4 Tuple (io.vavr.Tuple)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)4 Entry (org.janusgraph.diskstorage.Entry)4