Search in sources :

Example 16 with Session

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();
}
Also used : Cluster(com.datastax.driver.core.Cluster) Session(com.datastax.driver.core.Session)

Example 17 with Session

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=?");
}
Also used : Session(com.datastax.driver.core.Session) Before(org.junit.Before)

Example 18 with Session

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();
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Example 19 with Session

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();
}
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 20 with Session

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();
}
Also used : Session(com.datastax.driver.core.Session)

Aggregations

Session (com.datastax.driver.core.Session)30 Cluster (com.datastax.driver.core.Cluster)16 Test (org.junit.Test)16 ResultSet (com.datastax.driver.core.ResultSet)11 Row (com.datastax.driver.core.Row)10 BoundStatement (com.datastax.driver.core.BoundStatement)3 PreparedStatement (com.datastax.driver.core.PreparedStatement)3 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)3 Update (com.datastax.driver.core.querybuilder.Update)3 ReconnectionPolicy (com.datastax.driver.core.policies.ReconnectionPolicy)2 IOException (java.io.IOException)2 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)2 ColumnMetadata (com.datastax.driver.core.ColumnMetadata)1 DataType (com.datastax.driver.core.DataType)1 Host (com.datastax.driver.core.Host)1 IndexMetadata (com.datastax.driver.core.IndexMetadata)1 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)1 Metadata (com.datastax.driver.core.Metadata)1 QueryTrace (com.datastax.driver.core.QueryTrace)1 SimpleStatement (com.datastax.driver.core.SimpleStatement)1