use of org.teiid.query.tempdata.TempTableStore in project teiid by teiid.
the class RelationalPlan method initialize.
/**
* @see ProcessorPlan#connectDataManager(ProcessorDataManager)
*/
public void initialize(CommandContext context, ProcessorDataManager dataMgr, BufferManager bufferMgr) {
if (this.with != null) {
context = context.clone();
tempTableStore = new TempTableStore(context.getConnectionId(), TransactionMode.NONE);
tempTableStore.setParentTempTableStore(context.getTempTableStore());
context.setTempTableStore(tempTableStore);
}
setContext(context);
connectExternal(this.root, context, dataMgr, bufferMgr);
}
use of org.teiid.query.tempdata.TempTableStore in project teiid by teiid.
the class ProcedurePlan method push.
public void push(Program program) throws XATransactionException {
this.evaluator.close();
program.reset(this.getContext().getConnectionId());
program.setTrappingExceptions(program.getExceptionGroup() != null || (!this.programs.isEmpty() && this.programs.peek().isTrappingExceptions()));
TempTableStore tts = getTempTableStore();
getContext().setTempTableStore(program.getTempTableStore());
program.getTempTableStore().setParentTempTableStore(tts);
this.programs.push(program);
VariableContext context = new VariableContext(true);
context.setParentContext(this.currentVarContext);
this.currentVarContext = context;
VariableContext cc = new VariableContext(true);
cc.setParentContext(this.cursorStates);
this.cursorStates = cc;
if (program.isAtomic() && this.blockContext == null) {
TransactionContext tc = this.getContext().getTransactionContext();
if (tc != null && tc.getTransactionType() == Scope.NONE && Boolean.TRUE.equals(program.instructionsRequireTransaction(false))) {
// start a transaction
this.getContext().getTransactionServer().begin(tc);
this.blockContext = tc;
program.setStartedTxn(true);
}
}
}
use of org.teiid.query.tempdata.TempTableStore in project teiid by teiid.
the class TestProcessor method doProcess.
public static long doProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults, CommandContext context) throws Exception {
BufferManager bufferMgr = context.getBufferManager();
if (bufferMgr == null) {
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
bm.setProcessorBatchSize(context.getProcessorBatchSize());
context.setBufferManager(bm);
bufferMgr = bm;
}
context.getNextRand(0);
if (context.getTempTableStore() == null) {
context.setTempTableStore(new TempTableStore(context.getConnectionId(), TransactionMode.ISOLATE_WRITES));
}
if (context.getGlobalTableStore() == null) {
GlobalTableStoreImpl gts = new GlobalTableStoreImpl(bufferMgr, null, context.getMetadata());
context.setGlobalTableStore(gts);
}
if (!(dataManager instanceof TempTableDataManager)) {
SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
cache.setTupleBufferCache(bufferMgr);
dataManager = new TempTableDataManager(dataManager, bufferMgr, cache);
}
if (context.getQueryProcessorFactory() == null) {
context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(bufferMgr, dataManager, new DefaultCapabilitiesFinder(), null, context.getMetadata()));
}
TupleBuffer id = null;
long rowCount = 0;
try {
QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
// processor.setNonBlocking(true);
BatchCollector collector = processor.createBatchCollector();
for (int i = 0; i < 100; i++) {
try {
id = collector.collectTuples();
break;
} catch (BlockedException e) {
}
}
if (id == null) {
fail("did not complete processing");
}
rowCount = id.getRowCount();
if (DEBUG) {
// $NON-NLS-1$
System.out.println("\nResults:\n" + id.getSchema());
TupleSource ts2 = id.createIndexedTupleSource();
for (int j = 0; j < rowCount; j++) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("" + j + ": " + ts2.nextTuple());
}
}
if (expectedResults != null) {
examineResults(expectedResults, bufferMgr, id);
}
} finally {
if (id != null) {
id.remove();
}
}
return rowCount;
}
use of org.teiid.query.tempdata.TempTableStore in project teiid by teiid.
the class MetaDataProcessor method processMessage.
/**
* Process a metadata request message - this is typically either a request
* for metadata for a prepared statement or a request for full metadata from
* an already processed command.
* @param metadataMsg The message from the client
* @return The message for the client
* @throws TeiidComponentException
* @throws TeiidProcessingException
*/
MetadataResult processMessage(RequestID requestId, DQPWorkContext workContext, String preparedSql, boolean allowDoubleQuotedVariable) throws TeiidComponentException, TeiidProcessingException {
this.requestID = requestId;
this.metadata = workContext.getVDB().getAttachment(QueryMetadataInterface.class);
RequestWorkItem workItem = null;
try {
workItem = requestManager.getRequestWorkItem(requestID);
} catch (TeiidProcessingException e) {
if (preparedSql == null) {
throw e;
}
}
TempTableStore tempTableStore = null;
if (requestManager != null) {
ClientState state = requestManager.getClientState(workContext.getSessionId(), false);
if (state != null) {
tempTableStore = state.sessionTables;
}
}
if (tempTableStore != null) {
metadata = new TempMetadataAdapter(this.metadata, tempTableStore.getMetadataStore());
}
if (workItem != null) {
return getMetadataForCommand(workItem.getOriginalCommand());
}
return obtainMetadataForPreparedSql(preparedSql, workContext, allowDoubleQuotedVariable);
}
use of org.teiid.query.tempdata.TempTableStore in project teiid by teiid.
the class ProcedurePlan method pop.
/**
* @param success
* @throws TeiidComponentException
* @throws XATransactionException
*/
public void pop(boolean success) throws TeiidComponentException {
this.evaluator.close();
Program program = this.programs.pop();
VariableContext vc = this.currentVarContext;
VariableContext cs = this.cursorStates;
try {
this.currentVarContext = this.currentVarContext.getParentContext();
this.cursorStates = this.cursorStates.getParentContext();
TempTableStore tempTableStore = program.getTempTableStore();
this.getContext().setTempTableStore(tempTableStore.getParentTempTableStore());
tempTableStore.removeTempTables();
if (program.startedTxn()) {
TransactionService ts = this.getContext().getTransactionServer();
TransactionContext tc = this.blockContext;
this.blockContext = null;
try {
ts.resume(tc);
for (WeakReference<DataTierTupleSource> ref : txnTupleSources) {
DataTierTupleSource dtts = ref.get();
if (dtts != null) {
dtts.fullyCloseSource();
}
}
this.txnTupleSources.clear();
if (success) {
ts.commit(tc);
} else {
ts.rollback(tc);
}
} catch (XATransactionException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30165, e);
}
}
} finally {
removeAllCursors(cs);
}
}
Aggregations