properties.setProperty(TeiidURL.JDBC.VDB_VERSION, String.valueOf(version));
String user = "JOPR ADMIN"; //$NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.getString("admin_executing", user, command)); //$NON-NLS-1$
SessionMetadata session = null;
try {
session = this.sessionService.createSession(user, null, "JOPR", properties, false, false); //$NON-NLS-1$
} catch (SessionServiceException e1) {
throw new AdminProcessingException(e1);
} catch (LoginException e1) {
throw new AdminProcessingException(e1);
}
final long requestID = 0L;
DQPWorkContext context = new DQPWorkContext();
context.setSession(session);
try {
return context.runInContext(new Callable<List<List>>() {
@Override
public List<List> call() throws Exception {
ArrayList<List> results = new ArrayList<List>();
long start = System.currentTimeMillis();
RequestMessage request = new RequestMessage(command);
request.setExecutionId(0L);
request.setRowLimit(getMaxRowsFetchSize()); // this would limit the number of rows that are returned.
Future<ResultsMessage> message = dqpCore.executeRequest(requestID, request);
ResultsMessage rm = message.get(timoutInMilli, TimeUnit.MILLISECONDS);
if (rm.getException() != null) {
throw new AdminProcessingException(rm.getException());
}
if (rm.isUpdateResult()) {
results.addAll(new ArrayList(Arrays.asList("update count"))); //$NON-NLS-1$
results.addAll(Arrays.asList(rm.getResults()));
}
else {
results.addAll(new ArrayList(Arrays.asList(rm.getColumnNames())));
results.addAll(Arrays.asList(fixResults(rm.getResults())));
while (rm.getFinalRow() == -1 || rm.getLastRow() < rm.getFinalRow()) {
long elapsed = System.currentTimeMillis() - start;
message = dqpCore.processCursorRequest(requestID, rm.getLastRow()+1, 1024);
rm = message.get(timoutInMilli-elapsed, TimeUnit.MILLISECONDS);
results.addAll(Arrays.asList(fixResults(rm.getResults())));
}
}
long elapsed = System.currentTimeMillis() - start;
ResultsFuture<?> response = dqpCore.closeRequest(requestID);
response.get(timoutInMilli-elapsed, TimeUnit.MILLISECONDS);
return results;
}
});
} catch (Throwable t) {
throw new AdminProcessingException(t);
} finally {
try {
sessionService.closeSession(session.getSessionId());
} catch (InvalidSessionException e) { //ignore
}
}
}