Search in sources :

Example 11 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project teiid by teiid.

the class TestNativeCassandra method testDirect.

@Test
public void testDirect() throws TranslatorException {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    cef.setSupportsDirectQueryProcedure(true);
    String input = "call native('select $1', 'a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    CassandraConnection connection = Mockito.mock(CassandraConnection.class);
    ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
    Mockito.stub(rsf.isDone()).toReturn(true);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.stub(rsf.getUninterruptibly()).toReturn(rs);
    Row row = Mockito.mock(Row.class);
    ColumnDefinitions cd = Mockito.mock(ColumnDefinitions.class);
    Mockito.stub(row.getColumnDefinitions()).toReturn(cd);
    Mockito.stub(rs.one()).toReturn(row).toReturn(null);
    Mockito.stub(connection.executeQuery("select 'a'")).toReturn(rsf);
    ResultSetExecution execution = (ResultSetExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    List<?> vals = execution.next();
    assertTrue(vals.get(0) instanceof Object[]);
}
Also used : ColumnDefinitions(com.datastax.driver.core.ColumnDefinitions) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Example 12 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project teiid by teiid.

the class TestUpdates method testBulkUpdate.

@Test
public void testBulkUpdate() throws Exception {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    String input = "insert into pm1.g1 (e1) values ('a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    Insert insert = (Insert) command;
    Parameter p = new Parameter();
    p.setType(String.class);
    p.setValueIndex(0);
    ((ExpressionValueSource) insert.getValueSource()).getValues().set(0, p);
    insert.setParameterValues(Arrays.asList(Arrays.asList("a"), Arrays.asList("b")).iterator());
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    CassandraConnection connection = Mockito.mock(CassandraConnection.class);
    ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
    Mockito.stub(rsf.isDone()).toReturn(true);
    Mockito.stub(connection.executeBatch(Mockito.eq("INSERT INTO g1 (e1) VALUES (?)"), (List<Object[]>) Mockito.anyObject())).toReturn(rsf);
    UpdateExecution execution = (UpdateExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    assertArrayEquals(new int[] { 2 }, execution.getUpdateCounts());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Parameter(org.teiid.language.Parameter) UpdateExecution(org.teiid.translator.UpdateExecution) Insert(org.teiid.language.Insert) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 13 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project jnosql-diana-driver by eclipse.

the class DefaultCassandraColumnFamilyManagerAsync method delete.

@Override
public void delete(ColumnDeleteQuery query, ConsistencyLevel level, Consumer<Void> consumer) {
    requireNonNull(query, "query is required");
    requireNonNull(level, "level is required");
    requireNonNull(consumer, "consumer is required");
    BuiltStatement delete = QueryUtils.delete(query, keyspace);
    delete.setConsistencyLevel(requireNonNull(level, "ConsistencyLevel is required"));
    ResultSetFuture resultSetFuture = session.executeAsync(delete);
    resultSetFuture.addListener(() -> consumer.accept(null), executor);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) BuiltStatement(com.datastax.driver.core.querybuilder.BuiltStatement)

Example 14 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project jnosql-diana-driver by eclipse.

the class DefaultCassandraColumnFamilyManagerAsync method select.

@Override
public void select(ColumnQuery query, ConsistencyLevel level, Consumer<List<ColumnEntity>> consumer) throws ExecuteAsyncQueryException, NullPointerException {
    requireNonNull(query, "query is required");
    requireNonNull(level, "level is required");
    requireNonNull(consumer, "consumer is required");
    BuiltStatement select = QueryUtils.select(query, keyspace);
    select.setConsistencyLevel(requireNonNull(level, "ConsistencyLevel is required"));
    ResultSetFuture resultSet = session.executeAsync(select);
    CassandraReturnQueryAsync executeAsync = new CassandraReturnQueryAsync(resultSet, consumer);
    resultSet.addListener(executeAsync, executor);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) BuiltStatement(com.datastax.driver.core.querybuilder.BuiltStatement)

Example 15 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project jnosql-diana-driver by eclipse.

the class DefaultCassandraColumnFamilyManagerAsync method cql.

@Override
public void cql(String query, Map<String, Object> values, Consumer<List<ColumnEntity>> consumer) throws ExecuteAsyncQueryException, NullPointerException {
    requireNonNull(query, "query is required");
    requireNonNull(values, "values is required");
    requireNonNull(consumer, "consumer is required");
    ResultSetFuture resultSet = session.executeAsync(query, values);
    CassandraReturnQueryAsync executeAsync = new CassandraReturnQueryAsync(resultSet, consumer);
    resultSet.addListener(executeAsync, executor);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture)

Aggregations

ResultSetFuture (com.datastax.driver.core.ResultSetFuture)78 Test (org.junit.Test)35 UUID (java.util.UUID)26 ResultSet (com.datastax.driver.core.ResultSet)20 EntityWithCollections (com.datastax.driver.mapping.entity.EntityWithCollections)13 BoundStatement (com.datastax.driver.core.BoundStatement)12 PreparedStatement (com.datastax.driver.core.PreparedStatement)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 Row (com.datastax.driver.core.Row)7 Statement (com.datastax.driver.core.Statement)7 List (java.util.List)6 Session (com.datastax.driver.core.Session)5 Simple (com.datastax.driver.mapping.entity.Simple)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)5 BigDecimal (java.math.BigDecimal)5 HashSet (java.util.HashSet)5 Result (com.datastax.driver.mapping.Result)4 WriteOptions (com.datastax.driver.mapping.option.WriteOptions)4 Nullable (javax.annotation.Nullable)4