use of org.teiid.metadata.RuntimeMetadata 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[]);
}
use of org.teiid.metadata.RuntimeMetadata 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());
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestConnectorWorkItem method testConversionError.
@Test
public void testConversionError() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
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 {
List<String> list1 = new ArrayList<String>();
list1.add("1");
List<String> list2 = new ArrayList<String>();
list2.add("a");
final Iterator<List<String>> iter = Arrays.asList(list1, list2).iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (iter.hasNext()) {
return iter.next();
}
return null;
}
};
}
};
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 intkey FROM bqt1.smalla", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] results = message.getResults();
assertEquals(1, results.length);
List<?> tuple = results[0];
assertEquals(1, tuple.get(0));
assertEquals(-1, message.getFinalRow());
try {
cwi.more();
fail();
} catch (TranslatorException e) {
// should throw the conversion error
}
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestConnectorWorkItem method testUnmodifibleList.
@Test
public void testUnmodifibleList() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
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 {
List<String> list1 = Collections.singletonList("1");
final Iterator<List<String>> iter = Arrays.asList(list1).iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (iter.hasNext()) {
return iter.next();
}
return null;
}
};
}
};
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();
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] results = message.getResults();
assertEquals(1, results.length);
List<?> tuple = results[0];
assertEquals(1, tuple.get(0));
assertEquals(1, message.getFinalRow());
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestODataIntegration method testCheckGeneratedColumns.
@Test
public void testCheckGeneratedColumns() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {
@Override
public UpdateExecution createUpdateExecution(org.teiid.language.Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
GeneratedKeys keys = executionContext.getCommandContext().returnGeneratedKeys(new String[] { "a" }, new Class[] { String.class });
keys.addKey(Arrays.asList("ax"));
return super.createUpdateExecution(command, executionContext, metadata, connection);
}
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
};
hc.addUpdate("INSERT INTO x (b, c) VALUES ('b', 5)", new int[] { 1 });
// this gets called right after insert.
hc.addData("SELECT x.a, x.b, x.c FROM x WHERE x.a = 'ax'", Arrays.asList(Arrays.asList("a", "b", 2)));
teiid.addTranslator("x", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (a string, b string, c integer, " + "primary key (a)) options (updatable true);");
mmd.addSourceMapping("x", "x", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider("{\"b\":\"b\", \"c\":5}"), "application/json").send();
assertEquals(201, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
Aggregations