use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestVisitors method helpTest.
private void helpTest(String sql, String expected) throws Exception {
Command command = translationUtility.parseCommand(sql);
SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
ArgumentCaptor<String> queryArgument = ArgumentCaptor.forClass(String.class);
QueryResult qr = Mockito.mock(QueryResult.class);
Mockito.stub(connection.query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean())).toReturn(qr);
Execution execution = factory.createExecution(command, ec, rm, connection);
execution.execute();
Mockito.verify(connection, Mockito.times(1)).query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean());
assertEquals(expected, queryArgument.getValue().trim());
}
use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestConnectorManager method testGetCapabilities.
@Test
public void testGetCapabilities() throws Exception {
final Object cf = new Object();
ExecutionFactory ef = new ExecutionFactory() {
public boolean isSourceRequiredForCapabilities() {
return true;
}
};
final Object[] cfHolder = new Object[1];
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
ef) {
public Object getConnectionFactory() {
return cfHolder[0];
}
};
cm.start();
try {
cm.getCapabilities();
fail();
} catch (TranslatorException e) {
}
ef = new ExecutionFactory() {
public boolean isSourceRequiredForCapabilities() {
return true;
}
@Override
public Object getConnection(Object factory, ExecutionContext executionContext) throws TranslatorException {
assertEquals(cf, factory);
return factory;
}
@Override
public void closeConnection(Object connection, Object factory) {
}
};
cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
ef) {
public Object getConnectionFactory() {
return cfHolder[0];
}
};
cfHolder[0] = cf;
cm.getCapabilities();
}
use of org.teiid.translator.ExecutionContext in project teiid by teiid.
the class TestConnectorWorkItem method testLobs.
@Test
public void testLobs() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final List<Object> result = Arrays.asList(AutoGenDataService.CLOB_VAL);
final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
return new ResultSetExecution() {
private boolean returned;
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (returned) {
return null;
}
returned = true;
return result;
}
};
}
};
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector") {
public ExecutionFactory getExecutionFactory() {
return ef;
}
public Object getConnectionFactory() {
return null;
}
};
cm.start();
ef.setCopyLobs(true);
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] resutls = message.getResults();
List<?> tuple = resutls[0];
ClobType clob = (ClobType) tuple.get(0);
assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob));
assertTrue(message.supportsImplicitClose());
result.set(0, AutoGenDataService.CLOB_VAL);
ef.setCopyLobs(false);
cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
message = cwi.more();
resutls = message.getResults();
tuple = resutls[0];
clob = (ClobType) tuple.get(0);
assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob));
assertFalse(message.supportsImplicitClose());
result.set(0, new ClobImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(new byte[0]);
}
@Override
public StorageMode getStorageMode() {
// TODO: introduce an explicit streaming
return StorageMode.FREE;
}
}, -1));
requestMsg.setCopyStreamingLobs(true);
cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
message = cwi.more();
resutls = message.getResults();
tuple = resutls[0];
clob = (ClobType) tuple.get(0);
// switched from FREE to PERSISTENT
assertEquals(StorageMode.PERSISTENT, InputStreamFactory.getStorageMode(clob));
assertFalse(message.supportsImplicitClose());
}
use of org.teiid.translator.ExecutionContext 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.translator.ExecutionContext 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'"));
}
Aggregations