Search in sources :

Example 6 with ExecutionFactory

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 });
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ExecutionFactory(org.teiid.translator.ExecutionFactory) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) Test(org.junit.Test)

Example 7 with ExecutionFactory

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;
}
Also used : ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) HashMap(java.util.HashMap) ExecutionFactory(org.teiid.translator.ExecutionFactory) TeiidConstants.asString(org.teiid.jboss.TeiidConstants.asString) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 8 with ExecutionFactory

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));
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ModuleLoader(org.jboss.modules.ModuleLoader) ServiceTarget(org.jboss.msc.service.ServiceTarget) OperationFailedException(org.jboss.as.controller.OperationFailedException) ExecutionFactory(org.teiid.translator.ExecutionFactory) TeiidConstants.asString(org.teiid.jboss.TeiidConstants.asString) PathAddress(org.jboss.as.controller.PathAddress) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) ModelNode(org.jboss.dmr.ModelNode) Module(org.jboss.modules.Module) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 9 with ExecutionFactory

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);
        }
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ServiceTarget(org.jboss.msc.service.ServiceTarget) ExecutionFactory(org.teiid.translator.ExecutionFactory) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 10 with ExecutionFactory

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();
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ExecutionFactory(org.teiid.translator.ExecutionFactory) TranslatorException(org.teiid.translator.TranslatorException) Test(org.junit.Test)

Aggregations

ExecutionFactory (org.teiid.translator.ExecutionFactory)29 Test (org.junit.Test)18 TranslatorException (org.teiid.translator.TranslatorException)11 ExecutionContext (org.teiid.translator.ExecutionContext)9 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)8 ResultSetExecution (org.teiid.translator.ResultSetExecution)8 List (java.util.List)7 QueryExpression (org.teiid.language.QueryExpression)7 ArrayList (java.util.ArrayList)6 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)6 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)6 MetadataFactory (org.teiid.metadata.MetadataFactory)6 Connection (java.sql.Connection)5 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)5 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)5 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 OracleExecutionFactory (org.teiid.translator.jdbc.oracle.OracleExecutionFactory)4 TeiidExecutionFactory (org.teiid.translator.jdbc.teiid.TeiidExecutionFactory)4 FileInputStream (java.io.FileInputStream)3