use of org.teiid.client.RequestMessage in project teiid by teiid.
the class TestAllResultsImpl method testDateType.
@Test
public void testDateType() throws SQLException {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
ResultsMessage resultsMsg = new ResultsMessage();
resultsMsg.setResults(new List[] { Arrays.asList(new Timestamp(0)) });
// $NON-NLS-1$
resultsMsg.setColumnNames(new String[] { "TS" });
resultsMsg.setDataTypes(new String[] { DataTypeManager.DefaultDataTypes.TIMESTAMP });
resultsMsg.setFirstRow(1);
resultsMsg.setFinalRow(1);
resultsMsg.setLastRow(1);
ResultSetImpl rs = new ResultSetImpl(resultsMsg, statement);
assertTrue(rs.next());
// assumes the mock statement is setup with GMT-5 server and GMT-6 client
// will adjust ahead one hour
assertEquals(new Timestamp(3600000), rs.getObject(1));
// will be the same as the original
// $NON-NLS-1$
assertEquals(new Timestamp(0), rs.getTimestamp(1, Calendar.getInstance(TimeZone.getTimeZone("GMT-05:00"))));
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class TestAllResultsImpl method exampleResultsMsg4.
static ResultsMessage exampleResultsMsg4(int begin, int length, boolean lastBatch) {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
ResultsMessage resultsMsg = new ResultsMessage();
List[] results = exampleResults1(length, begin);
resultsMsg.setResults(results);
// $NON-NLS-1$
resultsMsg.setColumnNames(new String[] { "IntKey" });
resultsMsg.setDataTypes(new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
resultsMsg.setFirstRow(begin);
if (lastBatch) {
resultsMsg.setFinalRow(begin + results.length - 1);
}
resultsMsg.setLastRow(begin + results.length - 1);
return resultsMsg;
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class DQPCore method logMMCommand.
void logMMCommand(RequestWorkItem workItem, Event status, Long rowCount, Long cpuTime) {
if ((status != Event.PLAN && !LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.INFO)) || (status == Event.PLAN && !LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE))) {
return;
}
RequestMessage msg = workItem.requestMsg;
DQPWorkContext workContext = DQPWorkContext.getWorkContext();
RequestID rID = workItem.requestID;
String txnID = null;
TransactionContext tc = workItem.getTransactionContext();
if (tc != null && tc.getTransactionType() != Scope.NONE) {
txnID = tc.getTransactionId();
}
String appName = workContext.getAppName();
// Log to request log
CommandLogMessage message = null;
if (status == Event.NEW) {
message = new CommandLogMessage(System.currentTimeMillis(), rID.toString(), txnID, workContext.getSessionId(), appName, workContext.getUserName(), workContext.getVdbName(), workContext.getVdbVersion(), msg.getCommandString(), cpuTime);
} else {
QueryProcessor qp = workItem.getProcessor();
PlanNode plan = null;
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE) && qp != null) {
plan = qp.getProcessorPlan().getDescriptionProperties();
}
message = new CommandLogMessage(System.currentTimeMillis(), rID.toString(), txnID, workContext.getSessionId(), workContext.getUserName(), workContext.getVdbName(), workContext.getVdbVersion(), rowCount, status, plan);
}
LogManager.log(status == Event.PLAN ? MessageLevel.TRACE : MessageLevel.INFO, LogConstants.CTX_COMMANDLOGGING, message);
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class DQPCore method executeQuery.
/**
* Execute the given query asynchly. Has a hard limit of only returning max rows fetch size rows.
* @param command
* @param vdb
* @param user
* @param app
* @param timeoutInMilli
* @param engine
* @param listener
* @return
* @throws Throwable
*/
public static ResultsFuture<?> executeQuery(final Object command, final VDBMetaData vdb, final String user, final String app, final long timeoutInMilli, final DQPCore engine, final ResultsListener listener) throws Throwable {
final SessionMetadata session = TempTableDataManager.createTemporarySession(user, app, vdb);
final long requestID = 0L;
DQPWorkContext workContext = new DQPWorkContext();
if (engine.localProfile != null) {
workContext.setConnectionProfile(engine.localProfile);
}
workContext.setUseCallingThread(true);
workContext.setSession(session);
workContext.setAdmin(true);
final ResultsFuture<Void> resultFuture = new ResultsFuture<Void>();
resultFuture.addCompletionListener(new ResultsFuture.CompletionListener<Void>() {
@SuppressWarnings("unchecked")
@Override
public void onCompletion(ResultsFuture<Void> future) {
ResultsFuture<?> response;
try {
response = engine.closeRequest(requestID);
response.addCompletionListener(new ResultsFuture.CompletionListener() {
@Override
public void onCompletion(ResultsFuture future) {
engine.terminateSession(session.getSessionId());
}
});
} catch (Exception e) {
engine.terminateSession(session.getSessionId());
}
}
});
workContext.runInContext(new Callable<Void>() {
@Override
public Void call() throws Exception {
RequestMessage request = new RequestMessage();
if (command instanceof String) {
request.setCommands((String) command);
} else {
request.setCommands(command.toString());
request.setCommand(command);
}
request.setExecutionId(requestID);
// this would limit the number of rows that are returned.
request.setRowLimit(engine.getMaxRowsFetchSize());
ResultsFuture<ResultsMessage> message = engine.executeRequest(requestID, request, timeoutInMilli);
message.addCompletionListener(new ResultsFuture.CompletionListener<ResultsMessage>() {
@Override
public void onCompletion(ResultsFuture<ResultsMessage> future) {
try {
ResultsMessage rm = future.get();
if (rm.getException() != null) {
throw rm.getException();
}
if (rm.isUpdateResult()) {
// $NON-NLS-1$
listener.onResults(Arrays.asList("update-count"), rm.getResultsList());
resultFuture.getResultsReceiver().receiveResults(null);
} else {
processResult(rm);
}
} catch (Exception e) {
resultFuture.getResultsReceiver().exceptionOccurred(e);
}
}
private void processResult(ResultsMessage rm) throws Exception {
if (rm.getException() != null) {
throw rm.getException();
}
listener.onResults(Arrays.asList(rm.getColumnNames()), rm.getResultsList());
if (rm.getFinalRow() == -1 || rm.getLastRow() < rm.getFinalRow()) {
ResultsFuture<ResultsMessage> next = engine.processCursorRequest(requestID, rm.getLastRow() + 1, 1024);
next.addCompletionListener(new ResultsFuture.CompletionListener<ResultsMessage>() {
@Override
public void onCompletion(ResultsFuture<ResultsMessage> future) {
try {
processResult(future.get());
} catch (Exception e) {
resultFuture.getResultsReceiver().exceptionOccurred(e);
}
}
});
} else {
resultFuture.getResultsReceiver().receiveResults(null);
}
}
});
return null;
}
});
return resultFuture;
}
use of org.teiid.client.RequestMessage in project teiid by teiid.
the class DQPCore method start.
public void start(DQPConfiguration theConfig) {
this.config = theConfig;
this.authorizationValidator = config.getAuthorizationValidator();
this.chunkSize = config.getLobChunkSizeInKB() * 1024;
this.processWorkerPool = config.getTeiidExecutor();
// we don't want cancellations waiting on normal processing, so they get a small dedicated pool
// TODO: overflow to the worker pool
// $NON-NLS-1$
timeoutExecutor = ExecutorUtils.newFixedThreadPool(3, "Server Side Timeout");
this.cancellationTimer = new EnhancedTimer(timeoutExecutor, timeoutExecutor);
this.maxActivePlans = config.getMaxActivePlans();
if (this.maxActivePlans > config.getMaxThreads()) {
LogManager.logWarning(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30006, this.maxActivePlans, config.getMaxThreads()));
this.maxActivePlans = config.getMaxThreads();
}
// for now options are scoped to the engine - vdb scoping is a todo
options = new Options();
options.setAssumeMatchingCollation(false);
options.setProperties(config.getProperties());
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(options, options.getProperties(), "org.teiid", true);
this.bufferManager.setOptions(options);
// hack to set the max active plans
this.bufferManager.setMaxActivePlans(this.maxActivePlans);
try {
this.bufferManager.initialize();
} catch (TeiidComponentException e) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30496, e);
}
this.userRequestSourceConcurrency = config.getUserRequestSourceConcurrency();
if (this.userRequestSourceConcurrency < 1) {
this.userRequestSourceConcurrency = Math.min(config.getMaxThreads(), 2 * config.getMaxThreads() / this.maxActivePlans);
}
DataTierManagerImpl processorDataManager = new DataTierManagerImpl(this, this.bufferManager, this.config.isDetectingChangeEvents());
processorDataManager.setEventDistributor(eventDistributor);
dataTierMgr = new TempTableDataManager(processorDataManager, this.bufferManager, this.rsCache);
dataTierMgr.setExecutor(new TempTableDataManager.RequestExecutor() {
@Override
public void execute(String command, List<?> parameters) {
final String sessionId = DQPWorkContext.getWorkContext().getSessionId();
RequestMessage request = new RequestMessage(command);
request.setParameterValues(parameters);
request.setStatementType(StatementType.PREPARED);
ResultsFuture<ResultsMessage> result;
try {
result = executeRequest(0, request);
} catch (TeiidProcessingException e) {
throw new TeiidRuntimeException(e);
}
result.addCompletionListener(new ResultsFuture.CompletionListener<ResultsMessage>() {
@Override
public void onCompletion(ResultsFuture<ResultsMessage> future) {
terminateSession(sessionId);
}
});
}
@Override
public boolean isShutdown() {
return shutdown;
}
});
dataTierMgr.setEventDistributor(eventDistributor);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
LogManager.logDetail(LogConstants.CTX_DQP, "DQPCore started maxThreads", this.config.getMaxThreads(), "maxActivePlans", this.maxActivePlans, "source concurrency", this.userRequestSourceConcurrency);
}
Aggregations