use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.
the class AutoGenDataService method registerRequest.
@Override
public ConnectorWork registerRequest(AtomicRequestMessage message) throws TeiidComponentException {
List projectedSymbols = (message.getCommand()).getProjectedSymbols();
List[] results = createResults(projectedSymbols, rows, useIntCounter);
if (RelationalNodeUtil.isUpdate(message.getCommand())) {
results = new List[] { Arrays.asList(1) };
}
final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results);
msg.setFinalRow(rows);
return new ConnectorWork() {
boolean returnedInitial;
@Override
public boolean isDataAvailable() {
return dataAvailable;
}
@Override
public AtomicResultsMessage more() throws TranslatorException {
if (dataNotAvailable != null) {
int delay = dataNotAvailable;
dataNotAvailable = null;
DataNotAvailableException dnae = new DataNotAvailableException(delay);
dnae.setStrict(strict);
throw dnae;
}
if (addWarning) {
msg.setWarnings(Arrays.asList(new Exception()));
}
if (!returnedInitial) {
returnedInitial = true;
return msg;
}
// $NON-NLS-1$
throw new RuntimeException("Should not be called");
}
@Override
public void execute() throws TranslatorException {
executeCount.incrementAndGet();
if (sleep > 0) {
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
if (latch != null) {
try {
latch.countDown();
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
if (throwExceptionOnExecute) {
// $NON-NLS-1$
throw new TranslatorException("Connector Exception");
}
}
@Override
public void close() {
closeCount.incrementAndGet();
}
@Override
public void cancel(boolean abnormal) {
}
@Override
public CacheDirective getCacheDirective() {
return cacheDirective;
}
@Override
public boolean isForkable() {
return true;
}
@Override
public boolean isThreadBound() {
return threadBound;
}
@Override
public AtomicRequestID getId() {
return null;
}
};
}
use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.
the class TestConnectorWorkItem method testUpdateExecution.
@Test
public void testUpdateExecution() throws Throwable {
AtomicResultsMessage results = helpExecuteUpdate(false, true);
assertEquals(Integer.valueOf(1), results.getResults()[0].get(0));
}
use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.
the class TestConnectorWorkItem method testBatchUpdateExecution.
@Test
public void testBatchUpdateExecution() throws Throwable {
AtomicResultsMessage results = helpExecuteUpdate(true, false);
assertEquals(2, results.getResults().length);
assertEquals(Integer.valueOf(1), results.getResults()[0].get(0));
assertEquals(1, results.getResults()[1].get(0));
}
use of org.teiid.dqp.message.AtomicResultsMessage 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.dqp.message.AtomicResultsMessage 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());
}
Aggregations