use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class TestAsyncTupleSource method testTupleSource.
@Test
public void testTupleSource() throws TeiidComponentException, TeiidProcessingException {
AsyncTupleSource ats = new AsyncTupleSource(new Callable<TupleSource>() {
@Override
public TupleSource call() throws Exception {
return new CollectionTupleSource(Arrays.asList(Arrays.asList(1), Arrays.asList(2)).iterator());
}
}, new CommandContext());
for (int i = 0; i < 20; i++) {
try {
assertEquals(Arrays.asList(1), ats.nextTuple());
break;
} catch (BlockedException e) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
}
}
}
assertEquals(Arrays.asList(2), ats.nextTuple());
assertNull(ats.nextTuple());
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class BaseQueryTest method doProcess.
protected void doProcess(QueryMetadataInterface metadata, String sql, CapabilitiesFinder capFinder, ProcessorDataManager dataManager, List[] expectedResults, boolean debug) throws Exception {
CommandContext context = createCommandContext();
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
bm.setProcessorBatchSize(context.getProcessorBatchSize());
context.setBufferManager(bm);
doProcess(metadata, sql, capFinder, dataManager, expectedResults, debug, context);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class Request method createCommandContext.
protected void createCommandContext() {
if (this.context != null) {
return;
}
// Create command context, used in rewriting, planning, and processing
// Identifies a "group" of requests on a per-connection basis to allow later
// cleanup of all resources in the group on connection shutdown
String groupName = workContext.getSessionId();
this.context = new CommandContext(groupName, workContext.getUserName(), requestMsg.getExecutionPayload(), workContext.getVdbName(), workContext.getVdbVersion(), this.requestMsg.getShowPlan() != ShowPlan.OFF || LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE));
this.context.setProcessorBatchSize(bufferManager.getProcessorBatchSize());
this.context.setGlobalTableStore(this.globalTables);
boolean autoCleanLobs = true;
if (this.workContext.getSession().isEmbedded()) {
Object value = this.workContext.getSession().getSessionVariables().get(CLEAN_LOBS_ONCLOSE);
if (value != null) {
value = DataTypeManager.convertToRuntimeType(value, false);
try {
value = DataTypeManager.transformValue(value, value.getClass(), DataTypeManager.DefaultDataClasses.BOOLEAN);
if (!(Boolean) value) {
autoCleanLobs = false;
}
} catch (TransformationException e) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_DQP, e, "Improper value for", CLEAN_LOBS_ONCLOSE);
}
}
}
if (!autoCleanLobs) {
context.disableAutoCleanLobs();
}
context.setExecutor(this.executor);
context.setAuthoriziationValidator(authorizationValidator);
context.setTempTableStore(tempTableStore);
context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(this.bufferManager, this.processorDataManager, this.capabilitiesFinder, idGenerator, metadata));
context.setMetadata(this.metadata);
context.setBufferManager(this.bufferManager);
context.setPreparedPlanCache(planCache);
context.setResultSetCacheEnabled(this.resultSetCacheEnabled);
context.setUserRequestSourceConcurrency(this.userRequestConcurrency);
context.setSubject(workContext.getSubject());
this.context.setOptions(options);
this.context.setSession(workContext.getSession());
this.context.setRequestId(this.requestId);
this.context.setDQPWorkContext(this.workContext);
this.context.setTransactionService(this.transactionService);
this.context.setVDBClassLoader(workContext.getVDB().getAttachment(ClassLoader.class));
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class QueryProcessorFactoryImpl method createQueryProcessor.
@Override
public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext, Object... params) throws TeiidProcessingException, TeiidComponentException {
CommandContext copy = commandContext.clone();
copy.resetDeterminismLevel(true);
copy.setDataObjects(null);
QueryMetadataInterface metadata = commandContext.getMetadata();
if (metadata == null) {
metadata = defaultMetadata;
}
PreparedPlan pp = getPreparedPlan(query, recursionGroup, copy, metadata);
copy.pushVariableContext(new VariableContext());
PreparedStatementRequest.resolveParameterValues(pp.getReferences(), Arrays.asList(params), copy, metadata);
return new QueryProcessor(pp.getPlan().clone(), copy, bufferMgr, dataMgr);
}
use of org.teiid.query.util.CommandContext in project teiid by teiid.
the class BufferManagerImpl method releaseBuffers.
private void releaseBuffers(long count, boolean updateContext) {
if (count < 1) {
return;
}
if (updateContext) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.TRACE)) {
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Releasing buffer space", count);
}
CommandContext context = CommandContext.getThreadLocalContext();
if (context != null) {
context.addAndGetReservedBuffers((int) -count);
}
} else {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.INFO)) {
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_BUFFER_MGR, "Releasing orphaned buffer space", count);
}
}
lock.lock();
try {
this.reserveBatchBytes.addAndGet(count);
batchesFreed.signalAll();
} finally {
lock.unlock();
}
}
Aggregations