use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestNativeCassandra method testNativeQuery.
@Test
public void testNativeQuery() throws Exception {
CassandraExecutionFactory cef = new CassandraExecutionFactory();
cef.setSupportsDirectQueryProcedure(true);
String input = "call proc('a', 1)";
TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign procedure proc (in x string, in y integer) options (\"teiid_rel:native-query\" 'delete from $1 where $2')", "x", "y");
TranslationUtility util = new TranslationUtility(metadata);
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(connection.executeQuery("delete from 'a' where 1")).toReturn(rsf);
Execution execution = cef.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection).executeQuery("delete from 'a' where 1");
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestUpdates method testBatchedUpdate.
@Test
public void testBatchedUpdate() throws TranslatorException {
CassandraExecutionFactory cef = new CassandraExecutionFactory();
String input = "insert into pm1.g1 (e1) values ('a')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
Command command1 = util.parseCommand("update pm1.g1 set e1 = 'b'");
command = new BatchedUpdates(Arrays.asList(command, command1));
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(Arrays.asList("INSERT INTO g1 (e1) VALUES ('a')", "UPDATE g1 SET e1 = 'b'"))).toReturn(rsf);
UpdateExecution execution = (UpdateExecution) cef.createExecution(command, ec, rm, connection);
execution.execute();
assertArrayEquals(new int[] { 2 }, execution.getUpdateCounts());
Mockito.verify(connection).executeBatch(Arrays.asList("INSERT INTO g1 (e1) VALUES ('a')", "UPDATE g1 SET e1 = 'b'"));
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestSQLtoSpreadsheetQuery method testInsertExecution.
@Test
public void testInsertExecution() throws Exception {
String sql = "insert into PeopleList(A,B,C) values ('String,String', 'val', 15.5)";
Insert insert = (Insert) getCommand(sql);
GoogleSpreadsheetConnection gsc = Mockito.mock(GoogleSpreadsheetConnection.class);
Mockito.stub(gsc.getSpreadsheetInfo()).toReturn(people);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
SpreadsheetUpdateExecution sue = new SpreadsheetUpdateExecution(insert, gsc, ec, rm);
sue.execute();
LinkedHashMap<String, Object> vals = new LinkedHashMap<String, Object>();
vals.put("A", "String,String");
vals.put("B", "val");
vals.put("C", 15.5);
Mockito.verify(gsc).executeRowInsert("PeopleList", vals);
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestTeiidTableMarsheller method helpExecute.
private IckleConversionVisitor helpExecute(String query) throws Exception {
MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto");
// System.out.println(DDLStringVisitor.getDDLString(mf.getSchema(), null, null));
InfinispanExecutionFactory ef = new InfinispanExecutionFactory();
TransformationMetadata metadata = TestProtobufMetadataProcessor.getTransformationMetadata(mf, ef);
TranslationUtility utility = new TranslationUtility(metadata);
Select cmd = (Select) utility.parseCommand(query);
RuntimeMetadata runtimeMetadata = new RuntimeMetadataImpl(metadata);
IckleConversionVisitor visitor = new IckleConversionVisitor(runtimeMetadata, false);
visitor.visitNode(cmd);
visitor.getQuery();
return visitor;
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class ConnectorHost method executeBatchedUpdates.
public int[] executeBatchedUpdates(String[] updates) throws TranslatorException {
RuntimeMetadata runtimeMetadata = getRuntimeMetadata();
Command[] commands = new Command[updates.length];
for (int i = 0; i < updates.length; i++) {
commands[i] = getCommand(updates[i]);
}
return executeBatchedUpdates(commands, runtimeMetadata);
}
Aggregations