use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestLocalConnections method oneTimeSetup.
@SuppressWarnings("serial")
@BeforeClass
public static void oneTimeSetup() throws Exception {
server.setUseCallingThread(true);
server.setConnectorManagerRepository(new ConnectorManagerRepository() {
@Override
public ConnectorManager getConnectorManager(String connectorName) {
return new ConnectorManager(connectorName, connectorName) {
@Override
public ExecutionFactory<Object, Object> getExecutionFactory() {
return new ExecutionFactory<Object, Object>() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
return new ResultSetExecution() {
boolean returnedRow = false;
@Override
public void execute() throws TranslatorException {
lock.lock();
try {
sourceCounter.release();
if (!wait.await(5, TimeUnit.SECONDS)) {
throw new RuntimeException();
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
lock.unlock();
}
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (returnedRow) {
return null;
}
returnedRow = true;
return new ArrayList<Object>(Collections.singleton(null));
}
};
}
};
}
@Override
public Object getConnectionFactory() throws TranslatorException {
return null;
}
};
}
});
FunctionMethod function = new FunctionMethod("foo", null, FunctionCategoryConstants.MISCELLANEOUS, PushDown.CANNOT_PUSHDOWN, TestLocalConnections.class.getName(), "blocking", null, new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER), false, FunctionMethod.Determinism.NONDETERMINISTIC);
HashMap<String, Collection<FunctionMethod>> udfs = new HashMap<String, Collection<FunctionMethod>>();
udfs.put("test", Arrays.asList(function));
server.deployVDB("PartsSupplier", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb", new DeployVDBParameter(udfs, null));
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestExecutionReuse method oneTimeSetUp.
@BeforeClass
public static void oneTimeSetUp() throws Exception {
EmbeddedConfiguration config = new EmbeddedConfiguration();
config.setUserRequestSourceConcurrency(1);
server = new FakeServer(false);
server.setConnectorManagerRepository(new ConnectorManagerRepository() {
private ConnectorManager cm = new ConnectorManager("x", "y") {
private ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
ec = executionContext;
return execution;
}
public boolean isSourceRequired() {
return false;
}
};
@Override
public ExecutionFactory<Object, Object> getExecutionFactory() {
return ef;
}
@Override
public Object getConnectionFactory() throws TranslatorException {
return null;
}
};
@Override
public ConnectorManager getConnectorManager(String connectorName) {
return cm;
}
});
server.start(config, false);
server.deployVDB("PartsSupplier", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestResultsCache method testScope.
@Test
public void testScope() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.addProperty("teiid_rel:determinism", "USER_DETERMINISTIC");
mmd.addSourceMapping("x", "x", null);
mmd.addSourceMetadata("ddl", "create foreign table t (c string); create foreign procedure p () returns table (c string);");
final AtomicBoolean setScope = new AtomicBoolean();
server.addTranslator("x", new ExecutionFactory() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, final ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
return createProcedureExecution(null, executionContext, metadata, connection);
}
@Override
public ProcedureExecution createProcedureExecution(Call command, final ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
return new ProcedureExecution() {
boolean returned = false;
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (setScope.get()) {
// prevent caching altogether
executionContext.setScope(Scope.SESSION);
}
if (returned) {
return null;
}
returned = true;
return Arrays.asList(executionContext.getSession().getSessionId());
}
@Override
public List<?> getOutputParameterValues() throws TranslatorException {
return null;
}
};
}
});
server.deployVDB("x", mmd);
Connection c = server.getDriver().connect("jdbc:teiid:x;user=alice", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("/* cache */ select * from t");
assertTrue(rs.next());
String sessionid = rs.getString(1);
// should be the same with same user/session
rs = s.executeQuery("/* cache */ select * from t");
assertTrue(rs.next());
assertEquals(sessionid, rs.getString(1));
c.close();
c = server.getDriver().connect("jdbc:teiid:x;user=alice", null);
s = c.createStatement();
rs = s.executeQuery("/* cache */ select * from t");
assertTrue(rs.next());
assertEquals(sessionid, rs.getString(1));
c.close();
// for the final test
setScope.set(true);
// should be different with another user
c = server.getDriver().connect("jdbc:teiid:x;user=bill", null);
s = c.createStatement();
rs = s.executeQuery("/* cache */ select * from t");
assertTrue(rs.next());
String sessionid1 = rs.getString(1);
c.close();
assertNotEquals(sessionid, sessionid1);
c = server.getDriver().connect("jdbc:teiid:x;user=bill", null);
s = c.createStatement();
rs = s.executeQuery("/* cache */ select * from t");
assertTrue(rs.next());
// scope session should prevent reuse
assertNotEquals(sessionid1, rs.getString(1));
setScope.set(false);
rs = s.executeQuery("/* cache */ call p()");
assertTrue(rs.next());
sessionid = rs.getString(1);
c.close();
c = server.getDriver().connect("jdbc:teiid:x;user=alice", null);
s = c.createStatement();
rs = s.executeQuery("/* cache */ call p()");
assertTrue(rs.next());
assertNotEquals(sessionid, rs.getString(1));
c.close();
}
use of org.teiid.translator.ExecutionFactory in project wildfly-swarm by wildfly-swarm.
the class TranslatorCustomizer method loadTranslators.
@SuppressWarnings("rawtypes")
private void loadTranslators(String moduleName) {
ClassLoader translatorLoader = this.getClass().getClassLoader();
try {
final Module module = Module.getBootModuleLoader().loadModule(moduleName);
if (module != null) {
translatorLoader = module.getClassLoader();
final ServiceLoader<ExecutionFactory> serviceLoader = ServiceLoader.load(ExecutionFactory.class, translatorLoader);
if (serviceLoader != null) {
for (ExecutionFactory ef : serviceLoader) {
Translator t = ef.getClass().getAnnotation(Translator.class);
fraction.translator(t.name(), x -> x.module(moduleName));
}
}
}
} catch (ModuleLoadException e) {
// no-op
}
}
Aggregations