use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestSimpleDBExecution method testDirectExecution.
@Test
public void testDirectExecution() throws Exception {
SelectResult result = new SelectResult();
result.setItems(mockResult());
String query = "select * from item where attribute > 'name'";
Mockito.stub(connection.performSelect(Mockito.anyString(), Mockito.anyString())).toReturn(result);
Command cmd = utility.parseCommand(query);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
List<Argument> arguments = new ArrayList<Argument>();
Argument arg = new Argument(Direction.IN, String.class, Mockito.mock(ProcedureParameter.class));
arg.setArgumentValue(LanguageFactory.INSTANCE.createLiteral(query, String.class));
arguments.add(arg);
ResultSetExecution exec = translator.createDirectExecution(arguments, cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
exec.execute();
List row = exec.next();
Mockito.verify(connection).performSelect("select * from item where attribute > 'name'", null);
Object[] results = (Object[]) row.get(0);
assertEquals("a1", results[0]);
assertEquals("[a2, a22]", results[1]);
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestHotrodExecution method testServer_Teiid_5165.
// TEIID-5165 - test large cache delete
@Test
public void testServer_Teiid_5165() throws Exception {
EF.setSupportsUpsert(false);
ResultSetExecution exec = null;
Command command = null;
UpdateExecution update = null;
InfinispanConnection connection = getConnection("foo");
// the below also test one-2-one relation.
command = UTILITY.parseCommand("DELETE FROM G2");
update = EF.createUpdateExecution(command, EC, METADATA, connection);
update.execute();
int rows = 12000;
for (int i = 0; i < rows; i++) {
command = UTILITY.parseCommand("INSERT INTO G2 (e1, e2, g3_e1, g3_e2) values (" + i + ", 'row" + i + "', 1, 'one')");
update = EF.createUpdateExecution(command, EC, METADATA, connection);
update.execute();
}
Thread.sleep(5000);
command = UTILITY.parseCommand("SELECT e1, e2 FROM G2");
exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
exec.execute();
int cnt = 0;
while (true) {
List<?> results = exec.next();
if (results == null)
break;
cnt++;
}
assertEquals(new Integer(rows), new Integer(cnt));
command = UTILITY.parseCommand("DELETE FROM G2");
update = EF.createUpdateExecution(command, EC, METADATA, connection);
update.execute();
command = UTILITY.parseCommand("SELECT count(*) as cnt FROM G2");
exec = EF.createResultSetExecution((QueryExpression) command, EC, METADATA, connection);
exec.execute();
assertNull(exec.next());
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataIntegration method testErrorCodes.
@Test
public void testErrorCodes() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {
@Override
public ResultSetExecution createResultSetExecution(final QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
List<? extends List<?>> list = getData(command);
if (list == null) {
throw new RuntimeException(command.toString());
}
final Iterator<? extends List<?>> result = list.iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
throw new TranslatorException(ODataPlugin.Event.TEIID16001, "execution failed");
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (result.hasNext()) {
return result.next();
}
return null;
}
};
}
};
hc.addData("SELECT x.a, x.b FROM x", Arrays.asList(Arrays.asList("a", 1)));
teiid.addTranslator("x1", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (a string, b integer, primary key (a));");
mmd.addSourceMapping("x1", "x1", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("GET").send();
assertEquals(400, response.getStatus());
assertEquals("{\"error\":{\"code\":\"TEIID30504\"," + "\"message\":\"TEIID30504 x1: TEIID16001 execution failed\"}}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/x?$format=xml").method("GET").send();
assertEquals(400, response.getStatus());
assertEquals("<?xml version='1.0' encoding='UTF-8'?>" + "<error xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\">" + "<code>TEIID30504</code>" + "<message>TEIID30504 x1: TEIID16001 execution failed</message>" + "</error>", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestEmbeddedServer method testQueryTimeout.
@Test
public void testQueryTimeout() throws Exception {
es.start(new EmbeddedConfiguration());
es.addTranslator("foo", new ExecutionFactory() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
return super.createResultSetExecution(command, executionContext, metadata, connection);
}
});
es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"foo\" translator-name=\"foo\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table x (y xml);]]> </metadata></model></vdb>".getBytes()));
Connection c = es.getDriver().connect("jdbc:teiid:test", null);
Statement s = c.createStatement();
s.setQueryTimeout(1);
try {
s.execute("select * from x");
fail();
} catch (SQLException e) {
assertEquals(SQLStates.QUERY_CANCELED, e.getSQLState());
}
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestEmbeddedServer method testSourceLobUnderTxn.
@Test
public void testSourceLobUnderTxn() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setMaxResultSetCacheStaleness(0);
MockTransactionManager tm = new MockTransactionManager();
ec.setTransactionManager(tm);
ec.setUseDisk(false);
es.start(ec);
final AtomicBoolean closed = new AtomicBoolean();
es.addTranslator("foo", new ExecutionFactory() {
@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() {
closed.set(true);
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (returned) {
return null;
}
returned = true;
ArrayList<Object> result = new ArrayList<Object>(1);
result.add(new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
// need to make it of a sufficient size to not be inlined
return new ByteArrayInputStream(new byte[DataTypeManager.MAX_LOB_MEMORY_BYTES + 1]);
}
}));
return result;
}
};
}
});
es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"foo\" translator-name=\"foo\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table x (y xml);]]> </metadata></model></vdb>".getBytes()));
Connection c = es.getDriver().connect("jdbc:teiid:test", null);
c.setAutoCommit(false);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from x");
rs.next();
assertFalse(closed.get());
s.close();
assertTrue(closed.get());
}
Aggregations