use of com.datastax.driver.core.Session in project camel by apache.
the class CqlPopulateBean method populate.
public void populate() {
Cluster cluster = Cluster.builder().addContactPoint("cassandra").build();
Session session = cluster.connect();
session.execute("create keyspace if not exists test with replication = {'class':'SimpleStrategy', 'replication_factor':1};");
session.execute("create table if not exists test.users ( id int primary key, name text );");
session.execute("insert into test.users (id,name) values (1, 'oscerd') if not exists;");
session.close();
cluster.close();
}
use of com.datastax.driver.core.Session in project cassandra by apache.
the class DeleteTest method prepare.
@Before
public void prepare() throws Exception {
// Schema.instance.clear();
Session session = sessionNet();
session.getCluster().getConfiguration().getQueryOptions().setConsistencyLevel(ConsistencyLevel.ONE);
session.execute("drop keyspace if exists junit;");
session.execute("create keyspace junit WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 2 };");
session.execute("CREATE TABLE junit.tpc_base (\n" + " id int ,\n" + " cid int ,\n" + " val text ,\n" + " PRIMARY KEY ( ( id ), cid )\n" + ");");
session.execute("CREATE TABLE junit.tpc_inherit_a (\n" + " id int ,\n" + " cid int ,\n" + " inh_a text ,\n" + " val text ,\n" + " PRIMARY KEY ( ( id ), cid )\n" + ");");
session.execute("CREATE TABLE junit.tpc_inherit_b (\n" + " id int ,\n" + " cid int ,\n" + " inh_b text ,\n" + " val text ,\n" + " PRIMARY KEY ( ( id ), cid )\n" + ");");
session.execute("CREATE TABLE junit.tpc_inherit_b2 (\n" + " id int ,\n" + " cid int ,\n" + " inh_b text ,\n" + " inh_b2 text ,\n" + " val text ,\n" + " PRIMARY KEY ( ( id ), cid )\n" + ");");
session.execute("CREATE TABLE junit.tpc_inherit_c (\n" + " id int ,\n" + " cid int ,\n" + " inh_c text ,\n" + " val text ,\n" + " PRIMARY KEY ( ( id ), cid )\n" + ");");
pstmtI = session.prepare("insert into junit.tpc_inherit_b ( id, cid, inh_b, val) values (?, ?, ?, ?)");
pstmtU = session.prepare("update junit.tpc_inherit_b set inh_b=?, val=? where id=? and cid=?");
pstmtD = session.prepare("delete from junit.tpc_inherit_b where id=? and cid=?");
pstmt1 = session.prepare("select id, cid, val from junit.tpc_base where id=? and cid=?");
pstmt2 = session.prepare("select id, cid, inh_a, val from junit.tpc_inherit_a where id=? and cid=?");
pstmt3 = session.prepare("select id, cid, inh_b, val from junit.tpc_inherit_b where id=? and cid=?");
pstmt4 = session.prepare("select id, cid, inh_b, inh_b2, val from junit.tpc_inherit_b2 where id=? and cid=?");
pstmt5 = session.prepare("select id, cid, inh_c, val from junit.tpc_inherit_c where id=? and cid=?");
}
use of com.datastax.driver.core.Session 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();
}
use of com.datastax.driver.core.Session 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.Session in project camel by apache.
the class CassandraIdempotentTest method doPreSetup.
@Override
protected void doPreSetup() throws Exception {
if (canTest()) {
cluster = CassandraUnitUtils.cassandraCluster();
Session rootSession = cluster.connect();
CassandraUnitUtils.loadCQLDataSet(rootSession, "NamedIdempotentDataSet.cql");
rootSession.close();
idempotentRepository = new NamedCassandraIdempotentRepository(cluster, CassandraUnitUtils.KEYSPACE, "ID");
idempotentRepository.setTable("NAMED_CAMEL_IDEMPOTENT");
idempotentRepository.start();
}
super.doPreSetup();
}
Aggregations