Search in sources :

Example 6 with Update

use of com.datastax.driver.core.querybuilder.Update 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 7 with Update

use of com.datastax.driver.core.querybuilder.Update in project eventapis by kloiasoft.

the class CassandraEventRecorder method markFail.

@Override
public List<EntityEvent> markFail(String key) {
    Select select = QueryBuilder.select().from(tableNameByOps);
    select.where(QueryBuilder.eq(OP_ID, key));
    List<Row> entityEventDatas = cassandraSession.execute(select, PagingIterable::all);
    return entityEventDatas.stream().map(CassandraViewQuery::convertToEntityEvent).filter(entityEvent -> {
        try {
            Update update = QueryBuilder.update(tableName);
            update.where(QueryBuilder.eq(ENTITY_ID, entityEvent.getEventKey().getEntityId())).and(QueryBuilder.eq(VERSION, entityEvent.getEventKey().getVersion())).ifExists();
            update.with(QueryBuilder.set(STATUS, "FAILED"));
            ResultSet execute = cassandraSession.execute(update);
            log.debug("Failure Mark Result:" + execute.toString() + " Update: " + update.toString());
            return true;
        } catch (Exception e) {
            log.warn(e.getMessage(), e);
            return false;
        }
    }).collect(Collectors.toList());
}
Also used : QueryBuilder(com.datastax.driver.core.querybuilder.QueryBuilder) IdCreationStrategy(com.kloia.eventapis.api.IdCreationStrategy) OperationContext(com.kloia.eventapis.common.OperationContext) Row(com.datastax.driver.core.Row) Date(java.util.Date) EventKey(com.kloia.eventapis.common.EventKey) EventRecorder(com.kloia.eventapis.common.EventRecorder) Function(java.util.function.Function) PagingIterable(com.datastax.driver.core.PagingIterable) RecordedEvent(com.kloia.eventapis.common.RecordedEvent) ResultSet(com.datastax.driver.core.ResultSet) UUIDCreationStrategy(com.kloia.eventapis.api.impl.UUIDCreationStrategy) EventStoreException(com.kloia.eventapis.exception.EventStoreException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Update(com.datastax.driver.core.querybuilder.Update) Insert(com.datastax.driver.core.querybuilder.Insert) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EventState(com.kloia.eventapis.pojos.EventState) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) IUserContext(com.kloia.eventapis.api.IUserContext) Views(com.kloia.eventapis.api.Views) Optional(java.util.Optional) Select(com.datastax.driver.core.querybuilder.Select) PagingIterable(com.datastax.driver.core.PagingIterable) Select(com.datastax.driver.core.querybuilder.Select) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) Update(com.datastax.driver.core.querybuilder.Update) EventStoreException(com.kloia.eventapis.exception.EventStoreException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Update (com.datastax.driver.core.querybuilder.Update)7 ResultSet (com.datastax.driver.core.ResultSet)4 Row (com.datastax.driver.core.Row)4 Cluster (com.datastax.driver.core.Cluster)3 Session (com.datastax.driver.core.Session)3 Test (org.junit.Test)3 CassandraQuery (org.apache.gora.cassandra.query.CassandraQuery)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 ColumnDefinitions (com.datastax.driver.core.ColumnDefinitions)1 PagingIterable (com.datastax.driver.core.PagingIterable)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 Insert (com.datastax.driver.core.querybuilder.Insert)1 QueryBuilder (com.datastax.driver.core.querybuilder.QueryBuilder)1 Select (com.datastax.driver.core.querybuilder.Select)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IUserContext (com.kloia.eventapis.api.IUserContext)1 IdCreationStrategy (com.kloia.eventapis.api.IdCreationStrategy)1 Views (com.kloia.eventapis.api.Views)1 UUIDCreationStrategy (com.kloia.eventapis.api.impl.UUIDCreationStrategy)1