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