use of org.teiid.language.QueryExpression in project teiid by teiid.
the class LoopbackExecution method determineOutputTypes.
private void determineOutputTypes() {
// Get select columns and lookup the types in metadata
if (command instanceof QueryExpression) {
QueryExpression query = (QueryExpression) command;
types = Arrays.asList(query.getColumnTypes());
return;
}
if (command instanceof Call) {
types = Arrays.asList(((Call) command).getResultSetColumnTypes());
return;
}
types = new ArrayList<Class<?>>(1);
types.add(Integer.class);
}
use of org.teiid.language.QueryExpression 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.language.QueryExpression in project teiid by teiid.
the class TestBaseDelegatingExecutionFactory method testExecution.
@Test
public void testExecution() throws TranslatorException {
BaseDelegatingExecutionFactory<Void, Void> ef = new BaseDelegatingExecutionFactory<Void, Void>() {
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
return null;
}
};
ef.setDelegate(new ExecutionFactory<Void, Void>() {
@Override
public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
throw new AssertionError();
}
});
ef.createExecution(new Select(null, false, null, null, null, null, null), null, null, null);
}
use of org.teiid.language.QueryExpression 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.language.QueryExpression 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");
}
}
Aggregations