use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.
the class TestCompositeVDB method testImportErrors.
@Test(expected = VirtualDatabaseException.class)
public void testImportErrors() throws Exception {
VDBRepository repo = new VDBRepository();
repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
repo.setSystemFunctionManager(RealMetadataFactory.SFM);
MetadataStore metadataStore = RealMetadataFactory.exampleBQTCached().getMetadataStore();
VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
vdb = createVDBMetadata(metadataStore, "bqt1");
VDBImportMetadata vdbImport = new VDBImportMetadata();
vdbImport.setName("foo");
vdb.getVDBImports().add(vdbImport);
try {
// foo does not exist
repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
fail();
} catch (VirtualDatabaseException e) {
}
vdb = createVDBMetadata(metadataStore, "bqt1");
vdbImport.setName("bqt");
vdb.getVDBImports().add(vdbImport);
// model conflict
repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
}
use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository 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;
}
use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.
the class TestConnectorCapabilitiesFinder method testFind.
@Test
public void testFind() throws Exception {
// $NON-NLS-1$
String modelName = "model";
// $NON-NLS-1$
String functionName = "fakeFunction";
BasicSourceCapabilities caps = new BasicSourceCapabilities();
// $NON-NLS-1$
caps.setFunctionSupport("fakeFunction", true);
ArrayList<String> bindings = new ArrayList<String>();
bindings.add(modelName);
VDBMetaData vdb = Mockito.mock(VDBMetaData.class);
ModelMetaData model = Mockito.mock(ModelMetaData.class);
Mockito.stub(vdb.getModel(modelName)).toReturn(model);
Mockito.stub(model.getSourceNames()).toReturn(bindings);
BasicSourceCapabilities basicSourceCapabilities = new BasicSourceCapabilities();
basicSourceCapabilities.setFunctionSupport(functionName, true);
ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
ConnectorManager cm = Mockito.mock(ConnectorManager.class);
Mockito.stub(cm.getCapabilities()).toReturn(basicSourceCapabilities);
Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(cm);
CachedFinder finder = new CachedFinder(repo, vdb);
// Test
SourceCapabilities actual = finder.findCapabilities(modelName);
// $NON-NLS-1$
assertEquals("Did not get expected capabilities", true, actual.supportsFunction(functionName));
assertTrue(finder.isValid(modelName));
}
use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.
the class TestDQPCore method setUp.
@Before
public void setUp() throws Exception {
agds = new AutoGenDataService();
DQPWorkContext context = RealMetadataFactory.buildWorkContext(RealMetadataFactory.createTransformationMetadata(RealMetadataFactory.exampleBQTCached().getMetadataStore(), "bqt"));
// $NON-NLS-1$
context.getVDB().getModel("BQT3").setVisible(false);
// $NON-NLS-1$
context.getVDB().getModel("VQT").setVisible(false);
HashMap<String, DataPolicy> policies = new HashMap<String, DataPolicy>();
policies.put("foo", new DataPolicyMetadata());
context.setPolicies(policies);
ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
context.getVDB().addAttchment(ConnectorManagerRepository.class, repo);
Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(agds);
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
bm.setInlineLobs(false);
FakeBufferService bs = new FakeBufferService(bm, bm);
core = new DQPCore();
core.setBufferManager(bs.getBufferManager());
core.setResultsetCache(new SessionAwareCache<CachedResults>("resultset", new DefaultCacheFactory(new CacheConfiguration()), SessionAwareCache.Type.RESULTSET, 0));
core.setPreparedPlanCache(new SessionAwareCache<PreparedPlan>("preparedplan", new DefaultCacheFactory(new CacheConfiguration()), SessionAwareCache.Type.PREPAREDPLAN, 0));
core.setTransactionService(new FakeTransactionService());
config = new DQPConfiguration();
config.setMaxActivePlans(1);
config.setUserRequestSourceConcurrency(2);
DefaultAuthorizationValidator daa = new DefaultAuthorizationValidator();
daa.setPolicyDecider(new DataRolePolicyDecider());
config.setAuthorizationValidator(daa);
core.start(config);
core.getPrepPlanCache().setModTime(1);
core.getRsCache().setTupleBufferCache(bs.getBufferManager());
}
use of org.teiid.dqp.internal.datamgr.ConnectorManagerRepository in project teiid by teiid.
the class TestPreparedStatement method helpGetProcessorPlan.
static PreparedStatementRequest helpGetProcessorPlan(String preparedSql, List<?> values, CapabilitiesFinder capFinder, QueryMetadataInterface metadata, SessionAwareCache<PreparedPlan> prepPlanCache, int conn, boolean callableStatement, boolean limitResults, VDBMetaData vdb) throws TeiidComponentException, TeiidProcessingException {
// Create Request
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);
}
if (limitResults) {
request.setRowLimit(1);
}
DQPWorkContext workContext = RealMetadataFactory.buildWorkContext(metadata, vdb);
workContext.getSession().setSessionId(String.valueOf(conn));
PreparedStatementRequest serverRequest = new PreparedStatementRequest(prepPlanCache);
ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(new AutoGenDataService());
serverRequest.initialize(request, BufferManagerFactory.getStandaloneBufferManager(), null, new FakeTransactionService(), null, workContext, prepPlanCache);
serverRequest.setMetadata(capFinder, metadata);
DefaultAuthorizationValidator drav = new DefaultAuthorizationValidator();
serverRequest.setAuthorizationValidator(drav);
serverRequest.processRequest();
assertNotNull(serverRequest.processPlan);
return serverRequest;
}
Aggregations