public static RequestMessage example() { RequestMessage message = new RequestMessage(); message.setStatementType(StatementType.CALLABLE); message.setFetchSize(100); List<Integer> params = new ArrayList<Integer>(); params.add(new Integer(100)); params.add(new Integer(200)); params.add(new Integer(300)); params.add(new Integer(400)); message.setParameterValues(params); message.setPartialResults(true); message.setStyleSheet("myStyleSheet"); //$NON-NLS-1$ message.setExecutionPayload("myExecutionPayload"); //$NON-NLS-1$ try { message.setTxnAutoWrapMode(RequestMessage.TXN_WRAP_ON); } catch (TeiidProcessingException e) { throw new RuntimeException(e); } message.setShowPlan(ShowPlan.ON); message.setRowLimit(1313); message.setReturnAutoGeneratedKeys(true); message.setDelaySerialization(true); message.setSpanContext("foo"); return message; }
public void processRequest() throws TeiidComponentException, TeiidProcessingException { LogManager.logDetail(LogConstants.CTX_DQP, this.requestId, "executing", this.requestMsg.isPreparedStatement()?"prepared":"", this.requestMsg.getCommandString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ initMetadata(); generatePlan(false); createProcessor(); }
public AtomicRequestMessage(RequestMessage requestMessage, DQPWorkContext parent, int nodeId){ this.workContext = parent; this.requestID = new RequestID(parent.getSessionId(), requestMessage.getExecutionId()); this.atomicRequestId = new AtomicRequestID(this.requestID, nodeId, EXECUTION_COUNT.getAndIncrement()); }
protected RequestMessage createRequestMessage(String[] commands, boolean isBatchedCommand, ResultsMode resultsMode) { RequestMessage reqMessage = new RequestMessage(); reqMessage.setCommands(commands); reqMessage.setBatchedUpdate(isBatchedCommand); reqMessage.setResultsMode(resultsMode); return reqMessage; }
@Override protected RequestMessage createRequestMessage(String[] commands, boolean isBatchedCommand, ResultsMode resultsMode) { RequestMessage message = super.createRequestMessage(commands, false, resultsMode); message.setStatementType(StatementType.PREPARED); message.setParameterValues(isBatchedCommand?getParameterValuesList(): getParameterValues()); message.setBatchedUpdate(isBatchedCommand); message.setCommand(this.command); return message; }
private CacheHint getCacheHint() { if (requestMsg.getCommand() != null) { return ((Command)requestMsg.getCommand()).getCacheHint(); } return QueryParser.getQueryParser().parseCacheHint(requestMsg.getCommandString()); }
@Test public void testSerialize() throws Exception { RequestMessage copy = UnitTestUtil.helpSerialize(example()); assertTrue(copy.isCallableStatement()); assertEquals(100, copy.getFetchSize()); assertNotNull(copy.getParameterValues()); assertEquals(4, copy.getParameterValues().size()); assertEquals(new Integer(100), copy.getParameterValues().get(0)); assertEquals(new Integer(200), copy.getParameterValues().get(1)); assertEquals(new Integer(300), copy.getParameterValues().get(2)); assertEquals(new Integer(400), copy.getParameterValues().get(3)); assertFalse(copy.isPreparedStatement()); assertEquals("myStyleSheet", copy.getStyleSheet()); //$NON-NLS-1$ assertEquals("myExecutionPayload", copy.getExecutionPayload()); //$NON-NLS-1$ assertEquals(RequestMessage.TXN_WRAP_ON, copy.getTxnAutoWrapMode()); assertEquals(ShowPlan.ON, copy.getShowPlan()); assertEquals(1313, copy.getRowLimit()); assertTrue(copy.isReturnAutoGeneratedKeys()); assertTrue(copy.isDelaySerialization()); assertEquals("foo", copy.getSpanContext()); }
checkActive(workContext); RequestID requestID = workContext.getRequestID(reqID); requestMsg.setFetchSize(Math.min(requestMsg.getFetchSize(), this.config.getMaxRowsFetchSize())); Request request = null; if ( requestMsg.isPreparedStatement() || requestMsg.isCallableStatement() || requestMsg.getRequestOptions().isContinuous()) { request = new PreparedStatementRequest(prepPlanCache); } else { boolean runInThread = requestMsg.isSync(); synchronized (waitingPlans) { if (runInThread || currentlyActivePlans <= maxActivePlans) {
if (requestMsg.getRequestOptions().isContinuous()) { canUseCache = false; LogManager.logDetail(LogConstants.CTX_DQP, requestID, "Command is continuous, result set caching will not be used"); //$NON-NLS-1$ } else if (!requestMsg.useResultSetCache() && getCacheHint() == null) { canUseCache = false; LogManager.logDetail(LogConstants.CTX_DQP, requestID, "Command has no cache hint and result set cache mode is not on."); //$NON-NLS-1$ cacheId = new CacheID(this.dqpWorkContext, pi, requestMsg.getCommandString()); cachable = cacheId.setParameters(requestMsg.getParameterValues()); if (cachable) { if (cr != null && (cr.getRowLimit() == 0 || (requestMsg.getRowLimit() != 0 && requestMsg.getRowLimit() <= cr.getRowLimit()))) { request.initMetadata(); this.originalCommand = cr.getCommand(requestMsg.getCommandString(), request.metadata, pi); if (!request.validateAccess(requestMsg.getCommands(), this.originalCommand, CommandType.CACHED)) { LogManager.logDetail(LogConstants.CTX_DQP, requestID, "Using result set cached results", cacheId); //$NON-NLS-1$ this.resultsBuffer = cr.getResults(); if (cachable && (requestMsg.useResultSetCache() || originalCommand.getCacheHint() != null) && rsCache != null && originalCommand.areResultsCachable()) { this.cid = cacheId; if (!request.addedLimit && this.requestMsg.getRowLimit() > 0 && this.requestMsg.getRowLimit() < Integer.MAX_VALUE) { this.collector.setRowLimit(this.requestMsg.getRowLimit()); this.collector.setSaveLastRow(request.isReturingParams()); } else if (this.requestMsg.getRequestOptions().isContinuous()) { if (requestMsg.isNoExec()) {
@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); } }); }
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()); reqMsg.setExecutionId(this.currentRequestID);
public RequestMessage exampleRequestMessage(String sql) { RequestMessage msg = new RequestMessage(sql); msg.setCursorType(ResultSet.TYPE_SCROLL_INSENSITIVE); msg.setFetchSize(10); msg.setPartialResults(false); msg.setExecutionId(100); msg.setExecutionId(id++); return msg; }
RequestMessage request = new RequestMessage(preparedSql); if (callableStatement) { request.setStatementType(StatementType.CALLABLE); } else { request.setStatementType(StatementType.PREPARED); request.setParameterValues(values); if (values != null && values.size() > 0 && values.get(0) instanceof List) { request.setBatchedUpdate(true); request.setRowLimit(1);
assertEquals("Command does not match", sqlCommand, statement.requestMessage.getCommandString()); //$NON-NLS-1$ assertEquals("Parameter values do not match", expectedParameterValues, statement.requestMessage.getParameterValues()); //$NON-NLS-1$ assertTrue("RequestMessage.isBatchedUpdate should be true", statement.requestMessage.isBatchedUpdate()); //$NON-NLS-1$ assertFalse("RequestMessage.isCallableStatement should be false", statement.requestMessage.isCallableStatement()); //$NON-NLS-1$ assertTrue("RequestMessage.isPreparedStatement should be true", statement.requestMessage.isPreparedStatement()); //$NON-NLS-1$
private ResultsMessage exampleMessage(List<Object>[] results, String[] columnNames, String[] datatypes) { RequestMessage request = new RequestMessage(); request.setExecutionId(REQUEST_ID); ResultsMessage resultsMsg = new ResultsMessage(); resultsMsg.setResults(results); resultsMsg.setColumnNames(columnNames); resultsMsg.setDataTypes(datatypes); resultsMsg.setFinalRow(results.length); resultsMsg.setLastRow(results.length); resultsMsg.setFirstRow(1); return resultsMsg; }
private RequestID addRequest(DQPCore rm, String sessionId, int executionId) { RequestMessage r0 = new RequestMessage("test command"); //$NON-NLS-1$ RequestID id = new RequestID(sessionId, executionId); addRequest(rm, r0, id, null, null); return id; }
private AtomicRequestMessage helpSetupRequest(String sql, int nodeId, QueryMetadataInterface metadata) throws Exception { DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata, vdb); Command command = helpGetCommand(sql, metadata); RequestMessage original = new RequestMessage(); original.setExecutionId(id++); original.setPartialResults(true); RequestID requestID = workContext.getRequestID(original.getExecutionId()); context = new CommandContext(); context.setSession(workContext.getSession()); context.setVdbName("test"); //$NON-NLS-1$ context.setVdbVersion(1); context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(dtm.getBufferManager(), dtm, new DefaultCapabilitiesFinder(), null, metadata)); workItem = TestDQPCoreRequestHandling.addRequest(rm, original, requestID, null, workContext); context.setWorkItem(workItem); AtomicRequestMessage request = new AtomicRequestMessage(original, workContext, nodeId); request.setCommand(command); request.setConnectorName("FakeConnectorID"); //$NON-NLS-1$ request.setCommandContext(context); return request; }
protected void generatePlan(boolean addLimit) throws TeiidComponentException, TeiidProcessingException { createCommandContext(); String sqlQuery = requestMsg.getCommands()[0]; if (this.preParser != null) { sqlQuery = this.preParser.preParse(sqlQuery, this.context); ProcessorPlan cachedPlan = prepPlan.getPlan(); this.userCommand = prepPlan.getCommand(); if (validateAccess(requestMsg.getCommands(), userCommand, CommandType.PREPARED)) { LogManager.logDetail(LogConstants.CTX_DQP, requestId, "AuthorizationValidator indicates that the prepared plan for command will not be used"); //$NON-NLS-1$ prepPlan = null; if (requestMsg.isBatchedUpdate()) { handlePreparedBatchUpdate(); } else { List<Reference> params = prepPlan.getReferences(); List<?> values = requestMsg.getParameterValues();
validateAccess(requestMsg.getCommands(), command, CommandType.USER); if (!prepared && requestMsg.getRowLimit() > 0 && command instanceof QueryCommand) { QueryCommand query = (QueryCommand)command; if (query.getLimit() == null) { query.setLimit(new Limit(null, new Constant(new Integer(requestMsg.getRowLimit()), DataTypeManager.DefaultDataClasses.INTEGER))); this.addedLimit = true; String debugLog = analysisRecord.getDebugLog(); if(debugLog != null && debugLog.length() > 0) { LogManager.log(requestMsg.getShowPlan()==ShowPlan.DEBUG?MessageLevel.INFO:MessageLevel.TRACE, LogConstants.CTX_QUERY_PLANNER, debugLog);
reqMsg.setCursorType(ResultSet.TYPE_FORWARD_ONLY); DQPWorkContext.getWorkContext().getSession().setSessionId(sessionid); DQPWorkContext.getWorkContext().getSession().setUserName(userName); ((BufferManagerImpl)core.getBufferManager()).setProcessorBatchSize(1); Future<ResultsMessage> message = core.executeRequest(reqMsg.getExecutionId(), reqMsg); ResultsMessage rm = message.get(500000, TimeUnit.MILLISECONDS); assertNull(rm.getException()); RequestWorkItem item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId())); message = core.processCursorRequest(reqMsg.getExecutionId(), 9, rowsPerBatch); rm = message.get(500000, TimeUnit.MILLISECONDS); assertNull(rm.getException()); item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId())); message = core.processCursorRequest(reqMsg.getExecutionId(), start, rowsPerBatch); rm = message.get(5000, TimeUnit.MILLISECONDS); assertNull(rm.getException()); reqMsg.setCursorType(ResultSet.TYPE_SCROLL_INSENSITIVE); reqMsg.setExecutionId(id++); message = core.executeRequest(reqMsg.getExecutionId(), reqMsg); rm = message.get(500000, TimeUnit.MILLISECONDS); assertNull(rm.getException()); item = core.getRequestWorkItem(DQPWorkContext.getWorkContext().getRequestID(reqMsg.getExecutionId()));