use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class StatementImpl method createResultSet.
ResultSetImpl createResultSet(List records, ResultSetMetaData rsmd) throws SQLException {
if (rsmd.getColumnCount() > 0) {
// force the load of the metadata
rsmd.getScale(1);
}
ResultsMessage resultsMsg = createDummyResultsMessage(null, null, records);
resultSet = new ResultSetImpl(resultsMsg, this, rsmd, 0);
resultSet.setMaxFieldSize(this.maxFieldSize);
return resultSet;
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class StatementImpl method execute.
private ResultsFuture<ResultsMessage> execute(final RequestMessage reqMsg, boolean synch) throws SQLException, TeiidSQLException {
this.getConnection().beginLocalTxnIfNeeded();
this.currentRequestID = this.driverConnection.nextRequestID();
// Create a request message
if (this.payload != null) {
reqMsg.setExecutionPayload(this.payload);
} else {
reqMsg.setExecutionPayload(this.getMMConnection().getPayload());
}
reqMsg.setDelaySerialization(true);
reqMsg.setCursorType(this.resultSetType);
reqMsg.setFetchSize(this.fetchSize);
reqMsg.setRowLimit(this.maxRows);
reqMsg.setTransactionIsolation(this.driverConnection.getTransactionIsolation());
reqMsg.setSync(synch && useCallingThread());
// Get connection properties and set them onto request message
copyPropertiesToRequest(reqMsg);
reqMsg.setExecutionId(this.currentRequestID);
ResultsFuture.CompletionListener<ResultsMessage> compeletionListener = null;
if (queryTimeoutMS > 0 && (!synch || this.driverConnection.getServerConnection().isLocal())) {
final Task c = cancellationTimer.add(cancelTask, queryTimeoutMS);
compeletionListener = new ResultsFuture.CompletionListener<ResultsMessage>() {
@Override
public void onCompletion(ResultsFuture<ResultsMessage> future) {
c.cancel();
}
};
}
ResultsFuture<ResultsMessage> pendingResult = null;
try {
pendingResult = this.getDQP().executeRequest(this.currentRequestID, reqMsg);
} catch (TeiidException e) {
throw TeiidSQLException.create(e);
}
if (compeletionListener != null) {
pendingResult.addCompletionListener(compeletionListener);
}
return pendingResult;
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class ResultSetImpl method requestBatch.
public Batch requestBatch(int beginRow) throws SQLException {
checkClosed();
try {
if (prefetch != null) {
// TODO: this is not efficient if the user is skipping around the results
// but the server logic at this point basically requires us
// to read what we have requested before requesting more (no queuing)
ResultsMessage result = getResults(prefetch);
prefetch = null;
Batch nextBatch = processBatch(result);
return nextBatch;
}
ResultsFuture<ResultsMessage> results = submitRequestBatch(beginRow);
if (asynch && !results.isDone()) {
synchronized (this) {
asynchResults = results;
}
throw new AsynchPositioningException();
}
ResultsMessage currentResultMsg = getResults(results);
return processBatch(currentResultMsg);
} catch (InterruptedException e) {
throw TeiidSQLException.create(e);
} catch (ExecutionException e) {
throw TeiidSQLException.create(e);
} catch (TimeoutException e) {
throw TeiidSQLException.create(e);
}
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class ResultSetImpl method getResults.
private ResultsMessage getResults(ResultsFuture<ResultsMessage> results) throws SQLException, InterruptedException, ExecutionException, TimeoutException {
int timeoutSeconds = statement.getQueryTimeout();
if (timeoutSeconds == 0) {
timeoutSeconds = Integer.MAX_VALUE;
}
ResultsMessage currentResultMsg = results.get(timeoutSeconds, TimeUnit.SECONDS);
return currentResultMsg;
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestResultSet method testXML.
@Test
public void testXML() throws Exception {
StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY);
ResultsFuture<LobChunk> future = new ResultsFuture<LobChunk>();
future.getResultsReceiver().receiveResults(new LobChunk("<a/>".getBytes(Charset.forName("UTF-8")), true));
XMLType result = new XMLType();
Mockito.stub(statement.getDQP().requestNextLobChunk(0, 0, result.getReferenceStreamId())).toReturn(future);
ResultsMessage resultsMsg = new ResultsMessage();
result.setEncoding("UTF-8");
resultsMsg.setResults(new List<?>[] { Arrays.asList(result) });
resultsMsg.setLastRow(1);
resultsMsg.setFirstRow(1);
resultsMsg.setFinalRow(1);
// $NON-NLS-1$
resultsMsg.setColumnNames(new String[] { "x" });
// $NON-NLS-1$
resultsMsg.setDataTypes(new String[] { "xml" });
ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement);
cs.next();
assertEquals("<a/>", cs.getString(1));
}
Aggregations