Search in sources :

Example 1 with Row

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

the class CassandraAggregationRepository method scan.

/**
     * Get exchange IDs to be recovered
     *
     * @return Exchange IDs
     */
@Override
public Set<String> scan(CamelContext camelContext) {
    List<Row> rows = selectKeyIds();
    Set<String> exchangeIds = new HashSet<String>(rows.size());
    for (Row row : rows) {
        exchangeIds.add(row.getString(exchangeIdColumn));
    }
    return exchangeIds;
}
Also used : Row(com.datastax.driver.core.Row) HashSet(java.util.HashSet)

Example 2 with Row

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

the class CassandraAggregationRepository method confirm.

/**
     * Remove exchange by Id from aggregation table.
     */
@Override
public void confirm(CamelContext camelContext, String exchangeId) {
    String keyColumn = getKeyColumn();
    LOGGER.debug("Selecting Ids");
    List<Row> rows = selectKeyIds();
    for (Row row : rows) {
        if (row.getString(exchangeIdColumn).equals(exchangeId)) {
            String key = row.getString(keyColumn);
            Object[] cqlParams = append(getPKValues(key), exchangeId);
            LOGGER.debug("Deleting If Id {} ", cqlParams);
            getSession().execute(deleteIfIdStatement.bind(cqlParams));
        }
    }
}
Also used : Row(com.datastax.driver.core.Row)

Example 3 with Row

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

the class CassandraAggregationRepository method get.

/**
     * Get exchange from aggregation table by aggregation key.
     */
@Override
public Exchange get(CamelContext camelContext, String key) {
    Object[] pkValues = getPKValues(key);
    LOGGER.debug("Selecting key {} ", pkValues);
    Row row = getSession().execute(selectStatement.bind(pkValues)).one();
    Exchange exchange = null;
    if (row != null) {
        try {
            exchange = exchangeCodec.unmarshallExchange(camelContext, row.getBytes(exchangeColumn));
        } catch (IOException iOException) {
            throw new CassandraAggregationException("Failed to read exchange", exchange, iOException);
        } catch (ClassNotFoundException classNotFoundException) {
            throw new CassandraAggregationException("Failed to read exchange", exchange, classNotFoundException);
        }
    }
    return exchange;
}
Also used : Exchange(org.apache.camel.Exchange) Row(com.datastax.driver.core.Row) IOException(java.io.IOException)

Example 4 with Row

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

the class CassandraAggregationRepository method recover.

/**
     * Get exchange by exchange ID.
     * This is far from optimal.
     */
@Override
public Exchange recover(CamelContext camelContext, String exchangeId) {
    List<Row> rows = selectKeyIds();
    String keyColumnName = getKeyColumn();
    String lKey = null;
    for (Row row : rows) {
        String lExchangeId = row.getString(exchangeIdColumn);
        if (lExchangeId.equals(exchangeId)) {
            lKey = row.getString(keyColumnName);
            break;
        }
    }
    return lKey == null ? null : get(camelContext, lKey);
}
Also used : Row(com.datastax.driver.core.Row)

Example 5 with Row

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

the class CassandraComponentConsumerTest method testConsumeOne.

@Test
public void testConsumeOne() throws Exception {
    if (!canTest()) {
        return;
    }
    MockEndpoint mock = getMockEndpoint("mock:resultOne");
    mock.expectedMinimumMessageCount(1);
    mock.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Object body = exchange.getIn().getBody();
            assertTrue(body instanceof Row);
        }
    });
    mock.await(1, TimeUnit.SECONDS);
    assertMockEndpointsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Aggregations

Row (com.datastax.driver.core.Row)59 ResultSet (com.datastax.driver.core.ResultSet)35 Test (org.junit.Test)23 Session (com.datastax.driver.core.Session)10 ArrayList (java.util.ArrayList)10 BoundStatement (com.datastax.driver.core.BoundStatement)9 Cluster (com.datastax.driver.core.Cluster)9 Statement (com.datastax.driver.core.Statement)7 List (java.util.List)6 ImmutableList (com.google.common.collect.ImmutableList)5 HashSet (java.util.HashSet)5 PreparedStatement (com.datastax.driver.core.PreparedStatement)4 Select (com.datastax.driver.core.querybuilder.Select)4 ByteBuffer (java.nio.ByteBuffer)4 BatchStatement (com.datastax.driver.core.BatchStatement)3 Update (com.datastax.driver.core.querybuilder.Update)3 HashMap (java.util.HashMap)3 ProtocolVersion (org.apache.cassandra.transport.ProtocolVersion)3 TypeHint (org.apache.flink.api.common.typeinfo.TypeHint)3 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)2