use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestFunctionPushdown method testParseFormatNameCase.
@Test
public void testParseFormatNameCase() throws Exception {
BasicSourceCapabilities caps = getTypicalCapabilities();
caps.setCapabilitySupport(Capability.ONLY_FORMAT_LITERALS, true);
caps.setFunctionSupport(SourceSystemFunctions.FORMATTIMESTAMP, true);
caps.setTranslator(new ExecutionFactory<Object, Object>() {
@Override
public boolean supportsFormatLiteral(String literal, org.teiid.translator.ExecutionFactory.Format format) {
return literal.equals("yyyy");
}
});
ProcessorPlan plan = // $NON-NLS-1$
TestOptimizer.helpPlan(// $NON-NLS-1$
"SELECT stringkey from bqt1.smalla where formatTimestamp(timestampvalue, 'yyyy') = '1921' and parsebigdecimal(stringkey, 'yyyy') = 1 and formatTimestamp(timestampvalue, stringkey) = '19'", RealMetadataFactory.exampleBQTCached(), null, new DefaultCapabilitiesFinder(caps), new String[] { "SELECT g_0.TimestampValue, g_0.StringKey FROM BQT1.SmallA AS g_0 WHERE formatTimestamp(g_0.TimestampValue, 'yyyy') = '1921'" }, // $NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
checkNodeTypes(plan, new int[] { // Access
1, // DependentAccess
0, // DependentSelect
0, // DependentProject
0, // DupRemove
0, // Grouping
0, // NestedLoopJoinStrategy
0, // MergeJoinStrategy
0, // Null
0, // PlanExecution
0, // Project
1, // Select
1, // Sort
0, // UnionAll
0 });
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TeiidAdd method buildConnectorManagerRepository.
private ConnectorManagerRepository buildConnectorManagerRepository(final TranslatorRepository translatorRepo) {
ConnectorManagerRepository cmr = new ConnectorManagerRepository();
ConnectorManagerRepository.ExecutionFactoryProvider provider = new ConnectorManagerRepository.ExecutionFactoryProvider() {
HashMap<String, ExecutionFactory<Object, Object>> map = new HashMap<String, ExecutionFactory<Object, Object>>();
@Override
public ExecutionFactory<Object, Object> getExecutionFactory(String name) throws ConnectorManagerException {
VDBTranslatorMetaData translator = translatorRepo.getTranslatorMetaData(name);
if (translator == null) {
throw new ConnectorManagerException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50110, name));
}
ExecutionFactory<Object, Object> ef = map.get(name);
if (ef == null) {
ef = TranslatorUtil.buildDelegateAwareExecutionFactory(translator, this);
map.put(name, ef);
}
return ef;
}
};
cmr.setProvider(provider);
return cmr;
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TranslatorAdd method performRuntime.
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {
final ModelNode address = operation.require(OP_ADDR);
final PathAddress pathAddress = PathAddress.pathAddress(address);
final String translatorName = pathAddress.getLastElement().getValue();
String moduleName = null;
if (isDefined(TRANSLATOR_MODULE_ATTRIBUTE, operation, context)) {
moduleName = asString(TRANSLATOR_MODULE_ATTRIBUTE, operation, context);
}
String slot = null;
if (isDefined(TRANSLATOR_SLOT_ATTRIBUTE, operation, context)) {
slot = asString(TRANSLATOR_SLOT_ATTRIBUTE, operation, context);
}
final ServiceTarget target = context.getServiceTarget();
final Module module;
ClassLoader translatorLoader = this.getClass().getClassLoader();
ModuleLoader ml = Module.getCallerModuleLoader();
if (moduleName != null && ml != null) {
try {
ModuleIdentifier id = ModuleIdentifier.create(moduleName);
if (slot != null) {
id = ModuleIdentifier.create(moduleName, slot);
}
module = ml.loadModule(id);
translatorLoader = module.getClassLoader();
} catch (ModuleLoadException e) {
throw new OperationFailedException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50007, moduleName, translatorName), e);
}
}
boolean added = false;
final ServiceLoader<ExecutionFactory> serviceLoader = ServiceLoader.load(ExecutionFactory.class, translatorLoader);
if (serviceLoader != null) {
for (ExecutionFactory ef : serviceLoader) {
VDBTranslatorMetaData metadata = TranslatorUtil.buildTranslatorMetadata(ef, moduleName);
if (metadata == null) {
throw new OperationFailedException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50008, translatorName));
}
metadata.addAttchment(ClassLoader.class, translatorLoader);
if (translatorName.equalsIgnoreCase(metadata.getName())) {
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50006, metadata.getName()));
TranslatorDeployer.buildService(target, metadata);
added = true;
break;
}
}
}
if (!added) {
throw new OperationFailedException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50009, translatorName, moduleName));
}
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TranslatorDeployer method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ServiceTarget target = phaseContext.getServiceTarget();
if (!TeiidAttachments.isTranslator(deploymentUnit)) {
return;
}
String moduleName = deploymentUnit.getName();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
ClassLoader translatorLoader = module.getClassLoader();
final ServiceLoader<ExecutionFactory> serviceLoader = ServiceLoader.load(ExecutionFactory.class, translatorLoader);
if (serviceLoader != null) {
for (ExecutionFactory ef : serviceLoader) {
VDBTranslatorMetaData metadata = TranslatorUtil.buildTranslatorMetadata(ef, moduleName);
if (metadata == null) {
throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50070, moduleName));
}
deploymentUnit.putAttachment(TeiidAttachments.TRANSLATOR_METADATA, metadata);
metadata.addProperty(TranslatorUtil.DEPLOYMENT_NAME, moduleName);
metadata.addAttchment(ClassLoader.class, translatorLoader);
LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50006, metadata.getName()));
buildService(target, metadata);
}
}
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestConnectorManager method testGetCapabilities.
@Test
public void testGetCapabilities() throws Exception {
final Object cf = new Object();
ExecutionFactory ef = new ExecutionFactory() {
public boolean isSourceRequiredForCapabilities() {
return true;
}
};
final Object[] cfHolder = new Object[1];
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
ef) {
public Object getConnectionFactory() {
return cfHolder[0];
}
};
cm.start();
try {
cm.getCapabilities();
fail();
} catch (TranslatorException e) {
}
ef = new ExecutionFactory() {
public boolean isSourceRequiredForCapabilities() {
return true;
}
@Override
public Object getConnection(Object factory, ExecutionContext executionContext) throws TranslatorException {
assertEquals(cf, factory);
return factory;
}
@Override
public void closeConnection(Object connection, Object factory) {
}
};
cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
ef) {
public Object getConnectionFactory() {
return cfHolder[0];
}
};
cfHolder[0] = cf;
cm.getCapabilities();
}
Aggregations