use of org.teiid.dqp.internal.datamgr.ConnectorWork in project teiid by teiid.
the class AutoGenDataService method registerRequest.
@Override
public ConnectorWork registerRequest(AtomicRequestMessage message) throws TeiidComponentException {
List projectedSymbols = (message.getCommand()).getProjectedSymbols();
List[] results = createResults(projectedSymbols, rows, useIntCounter);
if (RelationalNodeUtil.isUpdate(message.getCommand())) {
results = new List[] { Arrays.asList(1) };
}
final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results);
msg.setFinalRow(rows);
return new ConnectorWork() {
boolean returnedInitial;
@Override
public boolean isDataAvailable() {
return dataAvailable;
}
@Override
public AtomicResultsMessage more() throws TranslatorException {
if (dataNotAvailable != null) {
int delay = dataNotAvailable;
dataNotAvailable = null;
DataNotAvailableException dnae = new DataNotAvailableException(delay);
dnae.setStrict(strict);
throw dnae;
}
if (addWarning) {
msg.setWarnings(Arrays.asList(new Exception()));
}
if (!returnedInitial) {
returnedInitial = true;
return msg;
}
// $NON-NLS-1$
throw new RuntimeException("Should not be called");
}
@Override
public void execute() throws TranslatorException {
executeCount.incrementAndGet();
if (sleep > 0) {
try {
Thread.sleep(sleep);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
if (latch != null) {
try {
latch.countDown();
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
if (throwExceptionOnExecute) {
// $NON-NLS-1$
throw new TranslatorException("Connector Exception");
}
}
@Override
public void close() {
closeCount.incrementAndGet();
}
@Override
public void cancel(boolean abnormal) {
}
@Override
public CacheDirective getCacheDirective() {
return cacheDirective;
}
@Override
public boolean isForkable() {
return true;
}
@Override
public boolean isThreadBound() {
return threadBound;
}
@Override
public AtomicRequestID getId() {
return null;
}
};
}
use of org.teiid.dqp.internal.datamgr.ConnectorWork in project teiid by teiid.
the class DataTierManagerImpl method registerRequest.
public TupleSource registerRequest(CommandContext context, Command command, String modelName, final RegisterRequestParameter parameterObject) throws TeiidComponentException, TeiidProcessingException {
RequestWorkItem workItem = context.getWorkItem();
Assertion.isNotNull(workItem);
if (CoreConstants.SYSTEM_MODEL.equals(modelName) || CoreConstants.SYSTEM_ADMIN_MODEL.equals(modelName)) {
return processSystemQuery(context, command, workItem.getDqpWorkContext());
}
AtomicRequestMessage aqr = createRequest(workItem, command, modelName, parameterObject.connectorBindingId, parameterObject.nodeID);
aqr.setCommandContext(context);
if (parameterObject.fetchSize > 0) {
aqr.setFetchSize(2 * parameterObject.fetchSize);
}
if (parameterObject.limit > 0) {
aqr.setFetchSize(Math.min(parameterObject.limit, aqr.getFetchSize()));
}
aqr.setCopyStreamingLobs(parameterObject.copyStreamingLobs);
Collection<GroupSymbol> accessedGroups = null;
if (context.getDataObjects() != null) {
QueryMetadataInterface metadata = context.getMetadata();
accessedGroups = GroupCollectorVisitor.getGroupsIgnoreInlineViews(command, false);
boolean usedModel = false;
for (GroupSymbol gs : accessedGroups) {
context.accessedDataObject(gs.getMetadataID());
// check the source/tables/procs for determinism level
Object mid = gs.getMetadataID();
if (mid instanceof TempMetadataID) {
TempMetadataID tid = (TempMetadataID) mid;
if (tid.getOriginalMetadataID() != null) {
mid = tid.getOriginalMetadataID();
}
}
String specificProp = metadata.getExtensionProperty(mid, AbstractMetadataRecord.RELATIONAL_URI + DDLConstants.DETERMINISM, false);
if (specificProp == null) {
if (!usedModel) {
Object modelId = metadata.getModelID(mid);
String prop = metadata.getExtensionProperty(modelId, AbstractMetadataRecord.RELATIONAL_URI + DDLConstants.DETERMINISM, false);
if (prop != null) {
usedModel = true;
// set model property
context.setDeterminismLevel(Determinism.valueOf(prop.toUpperCase()));
}
}
continue;
}
context.setDeterminismLevel(Determinism.valueOf(specificProp.toUpperCase()));
}
}
ConnectorManagerRepository cmr = workItem.getDqpWorkContext().getVDB().getAttachment(ConnectorManagerRepository.class);
ConnectorManager connectorManager = cmr.getConnectorManager(aqr.getConnectorName());
if (connectorManager == null) {
// can happen if sources are removed
if (RelationalNodeUtil.hasOutputParams(command)) {
// $NON-NLS-1$
throw new AssertionError("A source is required to execute a procedure returning parameters");
}
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logDetail(LogConstants.CTX_DQP, "source", aqr.getConnectorName(), "no longer exists, returning dummy results");
return CollectionTupleSource.createNullTupleSource();
}
ConnectorWork work = connectorManager.registerRequest(aqr);
if (!work.isForkable()) {
aqr.setSerial(true);
}
CacheID cid = null;
CacheDirective cd = null;
if (workItem.getRsCache() != null && command.areResultsCachable()) {
CachableVisitor cv = new CachableVisitor();
PreOrPostOrderNavigator.doVisit(command, cv, PreOrPostOrderNavigator.PRE_ORDER, true);
if (cv.cacheable) {
try {
cd = work.getCacheDirective();
} catch (TranslatorException e) {
// $NON-NLS-1$
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30504, e, aqr.getConnectorName() + ": " + e.getMessage());
}
if (cd != null) {
if (cd.getScope() == Scope.NONE) {
parameterObject.doNotCache = true;
} else {
String cmdString = command.toString();
if (cmdString.length() < 100000) {
// TODO: this check won't be needed if keys aren't exclusively held in memory
cid = new CacheID(workItem.getDqpWorkContext(), ParseInfo.DEFAULT_INSTANCE, cmdString);
cid.setParameters(cv.parameters);
if (cd.getInvalidation() == null || cd.getInvalidation() == Invalidation.NONE) {
CachedResults cr = workItem.getRsCache().get(cid);
if (cr != null && (cr.getRowLimit() == 0 || (parameterObject.limit > 0 && cr.getRowLimit() >= parameterObject.limit))) {
parameterObject.doNotCache = true;
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_DQP, "Using cache entry for", cid);
work.close();
return cr.getResults().createIndexedTupleSource();
}
} else if (cd.getInvalidation() == Invalidation.IMMEDIATE) {
workItem.getRsCache().remove(cid, CachingTupleSource.getDeterminismLevel(cd.getScope()));
}
}
}
} else {
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_DQP, aqr.getAtomicRequestID(), "no cache directive");
}
} else {
// $NON-NLS-1$
LogManager.logTrace(LogConstants.CTX_DQP, aqr.getAtomicRequestID(), "command not cachable");
}
}
DataTierTupleSource dtts = new DataTierTupleSource(aqr, workItem, work, this, parameterObject.limit);
TupleSource result = dtts;
TupleBuffer tb = null;
if (cid != null) {
tb = getBufferManager().createTupleBuffer(aqr.getCommand().getProjectedSymbols(), aqr.getCommandContext().getConnectionId(), TupleSourceType.PROCESSOR);
result = new CachingTupleSource(this, tb, (DataTierTupleSource) result, cid, parameterObject, cd, accessedGroups, workItem);
}
if (work.isThreadBound()) {
result = handleThreadBound(workItem, aqr, work, cid, result, dtts, tb);
} else if (!aqr.isSerial()) {
dtts.addWork();
}
return result;
}
Aggregations