コード例 #1
0
  @Test
  public void executePreparedCounterTest() throws Exception {
    PreparedStatement p = session.prepare("UPDATE " + COUNTER_TABLE + " SET c = c + ? WHERE k = ?");

    session.execute(p.bind(1L, "row"));
    session.execute(p.bind(1L, "row"));

    ResultSet rs = session.execute("SELECT * FROM " + COUNTER_TABLE);
    List<Row> rows = rs.all();
    assertEquals(1, rows.size());
    assertEquals(2L, rows.get(0).getLong("c"));
  }
コード例 #2
0
  @Test
  public void executePreparedTest() throws Exception {
    // Simple calls to all versions of the execute/executeAsync methods for prepared statements
    // Note: the goal is only to exercice the Session methods, PreparedStatementTest have better
    // prepared statement tests.
    String key = "execute_prepared_test";
    ResultSet rs = session.execute(String.format(INSERT_FORMAT, TABLE, key, "foo", 42, 24.03f));
    assertTrue(rs.isExhausted());

    PreparedStatement p = session.prepare(String.format(SELECT_ALL_FORMAT + " WHERE k = ?", TABLE));
    BoundStatement bs = p.bind(key);

    // executePrepared
    checkExecuteResultSet(session.execute(bs), key);
    checkExecuteResultSet(session.execute(bs.setConsistencyLevel(ConsistencyLevel.ONE)), key);

    // executePreparedAsync
    checkExecuteResultSet(session.executeAsync(bs).getUninterruptibly(), key);
    checkExecuteResultSet(
        session.executeAsync(bs.setConsistencyLevel(ConsistencyLevel.ONE)).getUninterruptibly(),
        key);
  }