Search in sources :

Example 41 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project cassandra by apache.

the class AlterNTSTest method testDropColumnAsPreparedStatement.

@Test
public void testDropColumnAsPreparedStatement() throws Throwable {
    String table = createTable("CREATE TABLE %s (key int PRIMARY KEY, value int);");
    PreparedStatement prepared = sessionNet().prepare("ALTER TABLE " + KEYSPACE + "." + table + " DROP value;");
    executeNet("INSERT INTO %s (key, value) VALUES (1, 1)");
    assertRowsNet(executeNet("SELECT * FROM %s"), row(1, 1));
    sessionNet().execute(prepared.bind());
    executeNet("ALTER TABLE %s ADD value int");
    assertRows(execute("SELECT * FROM %s"), row(1, null));
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) Test(org.junit.Test)

Example 42 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project storm by apache.

the class BoundCQLStatementTupleMapper method map.

/**
 * {@inheritDoc}
 */
@Override
public List<Statement> map(Map<String, Object> config, Session session, ITuple tuple) {
    final List<Column> columns = mapper.map(tuple);
    final String query = contextQuery.resolves(config, tuple);
    PreparedStatement statement = getPreparedStatement(session, query);
    if (hasRoutingKeys()) {
        List<ByteBuffer> keys = rkGenerator.getRoutingKeys(tuple);
        if (keys.size() == 1) {
            statement.setRoutingKey(keys.get(0));
        } else {
            statement.setRoutingKey(keys.toArray(new ByteBuffer[keys.size()]));
        }
    }
    return Arrays.asList((Statement) this.binder.apply(statement, columns));
}
Also used : Column(org.apache.storm.cassandra.query.Column) PreparedStatement(com.datastax.driver.core.PreparedStatement) ByteBuffer(java.nio.ByteBuffer)

Example 43 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project cassandra by apache.

the class CQLMetricsTest method testPreparedStatementsRatio.

@Test
public void testPreparedStatementsRatio() {
    clearMetrics();
    PreparedStatement metricsStatement = session.prepare("INSERT INTO junit.metricstest (id, val) VALUES (?, ?)");
    assertEquals(Double.NaN, QueryProcessor.metrics.preparedStatementsRatio.getValue(), 0.0);
    for (int i = 0; i < 10; i++) session.execute(metricsStatement.bind(i, "val" + i));
    assertEquals(1.0, QueryProcessor.metrics.preparedStatementsRatio.getValue(), 0.0);
    for (int i = 0; i < 10; i++) session.execute(String.format("INSERT INTO junit.metricstest (id, val) VALUES (%d, '%s')", i, "val" + i));
    assertEquals(0.5, QueryProcessor.metrics.preparedStatementsRatio.getValue(), 0.0);
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) Test(org.junit.Test)

Example 44 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project cassandra by apache.

the class CQLMetricsTest method testRegularStatementsExecuted.

@Test
public void testRegularStatementsExecuted() {
    clearMetrics();
    PreparedStatement metricsStatement = session.prepare("INSERT INTO junit.metricstest (id, val) VALUES (?, ?)");
    assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
    assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.getCount());
    for (int i = 0; i < 10; i++) session.execute(String.format("INSERT INTO junit.metricstest (id, val) VALUES (%d, '%s')", i, "val" + i));
    assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
    assertEquals(10, QueryProcessor.metrics.regularStatementsExecuted.getCount());
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) Test(org.junit.Test)

Example 45 with PreparedStatement

use of com.datastax.driver.core.PreparedStatement in project cassandra by apache.

the class CQLMetricsTest method testPreparedStatementsExecuted.

@Test
public void testPreparedStatementsExecuted() {
    clearMetrics();
    PreparedStatement metricsStatement = session.prepare("INSERT INTO junit.metricstest (id, val) VALUES (?, ?)");
    assertEquals(0, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
    assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.getCount());
    for (int i = 0; i < 10; i++) session.execute(metricsStatement.bind(i, "val" + i));
    assertEquals(10, QueryProcessor.metrics.preparedStatementsExecuted.getCount());
    assertEquals(0, QueryProcessor.metrics.regularStatementsExecuted.getCount());
}
Also used : PreparedStatement(com.datastax.driver.core.PreparedStatement) Test(org.junit.Test)

Aggregations

PreparedStatement (com.datastax.driver.core.PreparedStatement)113 ResultSet (com.datastax.driver.core.ResultSet)60 BoundStatement (com.datastax.driver.core.BoundStatement)59 Session (com.datastax.driver.core.Session)39 Test (org.junit.Test)30 Row (com.datastax.driver.core.Row)27 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)27 XMLStreamException (javolution.xml.stream.XMLStreamException)25 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)15 Cluster (com.datastax.driver.core.Cluster)9 Date (java.util.Date)9 IInvokableInstance (org.apache.cassandra.distributed.api.IInvokableInstance)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 QueryProcessor (org.apache.cassandra.cql3.QueryProcessor)7 GOSSIP (org.apache.cassandra.distributed.api.Feature.GOSSIP)7 NATIVE_PROTOCOL (org.apache.cassandra.distributed.api.Feature.NATIVE_PROTOCOL)7 NETWORK (org.apache.cassandra.distributed.api.Feature.NETWORK)7 ICluster (org.apache.cassandra.distributed.api.ICluster)7