use of com.datastax.driver.core.Session in project camel by apache.
the class CassandraEndpoint method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
if (cluster == null && beanRef != null) {
Object bean = CamelContextHelper.mandatoryLookup(getCamelContext(), beanRef);
if (bean instanceof Session) {
session = (Session) bean;
cluster = session.getCluster();
keyspace = session.getLoggedKeyspace();
} else if (bean instanceof Cluster) {
cluster = (Cluster) bean;
session = null;
} else {
throw new IllegalArgumentException("CQL Bean type should be of type Session or Cluster but was " + bean);
}
}
if (cluster == null && hosts != null) {
// use the cluster builder to create the cluster
cluster = createClusterBuilder().build();
}
if (cluster != null) {
sessionHolder = new CassandraSessionHolder(cluster, keyspace);
} else {
sessionHolder = new CassandraSessionHolder(session);
}
sessionHolder.start();
}
use of com.datastax.driver.core.Session in project camel by apache.
the class CassandraComponentProducerTest method testRequestMessageStatement.
/**
* Test with incoming message containing a header with RegularStatement.
*/
@Test
public void testRequestMessageStatement() throws Exception {
if (!canTest()) {
return;
}
Update.Where update = update("camel_user").with(set("first_name", bindMarker())).and(set("last_name", bindMarker())).where(eq("login", bindMarker()));
Object response = producerTemplate.requestBodyAndHeader(new Object[] { "Claus 2", "Ibsen 2", "c_ibsen" }, CassandraConstants.CQL_QUERY, update);
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();
}
use of com.datastax.driver.core.Session in project camel by apache.
the class CassandraComponentProducerTest method testLoadBalancing.
@Test
public void testLoadBalancing() throws Exception {
if (!canTest()) {
return;
}
Object response = loadBalancingPolicyTemplate.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();
}
use of com.datastax.driver.core.Session in project camel by apache.
the class CassandraComponentProducerTest method testRequestMessageCql.
@Test
public void testRequestMessageCql() throws Exception {
if (!canTest()) {
return;
}
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();
}
use of com.datastax.driver.core.Session in project camel by apache.
the class CassandraComponentProducerUnpreparedTest method testRequestMessageStatement.
/**
* Test with incoming message containing a header with RegularStatement.
*/
@Test
public void testRequestMessageStatement() throws Exception {
Update.Where update = update("camel_user").with(set("first_name", "Claus 2")).and(set("last_name", "Ibsen 2")).where(eq("login", "c_ibsen"));
Object response = producerTemplate.requestBodyAndHeader(null, CassandraConstants.CQL_QUERY, update);
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();
}
Aggregations