Search in sources :

Example 11 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class EmbeddedServer method addTranslator.

/**
 * Add a named {@link ExecutionFactory}. NOTE: Only this single instance will be shared for all usage.
 * @param name
 * @param ef the already started ExecutionFactory
 * @see {@link #addTranslator(String, String, Map)} or {@link #addTranslator(Class)}
 */
public void addTranslator(String name, ExecutionFactory<?, ?> ef) {
    translators.put(name, ef);
    VDBTranslatorMetaData vdbTranslatorMetaData = TranslatorUtil.buildTranslatorMetadata(ef, null);
    if (vdbTranslatorMetaData != null) {
        this.translatorRepository.addTranslatorMetadata(name, vdbTranslatorMetaData);
    }
}
Also used : VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 12 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class EmbeddedServer method addTranslator.

/**
 * Add an override translator
 * @param name
 * @param type the name of an existing translator to override
 * @param properties
 */
public void addTranslator(String name, String type, Map<String, String> properties) throws TranslatorException {
    VDBTranslatorMetaData vdbTranslatorMetaData = new VDBTranslatorMetaData();
    vdbTranslatorMetaData.setName(name);
    VDBTranslatorMetaData parent = translatorRepository.getTranslatorMetaData(type);
    if (parent == null) {
        throw new TranslatorException(RuntimePlugin.Event.TEIID40136, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40136, type));
    }
    vdbTranslatorMetaData.setParent(parent);
    if (properties != null) {
        Properties p = new Properties();
        p.putAll(properties);
        vdbTranslatorMetaData.setProperties(p);
    }
    this.translatorRepository.addTranslatorMetadata(name, vdbTranslatorMetaData);
}
Also used : TranslatorException(org.teiid.translator.TranslatorException) Properties(java.util.Properties) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 13 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class EmbeddedServer method addTranslator.

/**
 * Adds a definition of the {@link ExecutionFactory} using the default name either from the {@link Translator} annotation or the class name.
 * Only {@link ExecutionFactory} classes with a {@link Translator} annotation can be referenced by {@link #addTranslator(String, String, Map)}
 * @param ef
 * @throws TranslatorException
 */
public void addTranslator(Class<? extends ExecutionFactory> clazz) throws TranslatorException {
    try {
        VDBTranslatorMetaData vdbTranslatorMetaData = TranslatorUtil.buildTranslatorMetadata(clazz.newInstance(), null);
        if (vdbTranslatorMetaData != null) {
            translatorRepository.addTranslatorMetadata(vdbTranslatorMetaData.getName(), vdbTranslatorMetaData);
        } else {
            // not a well defined translator
            ExecutionFactory<?, ?> instance = clazz.newInstance();
            instance.start();
            addTranslator(clazz.getName(), instance);
        }
    } catch (InstantiationException | IllegalAccessException e) {
        throw new TranslatorException(e);
    }
}
Also used : TranslatorException(org.teiid.translator.TranslatorException) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 14 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class TranslatorUtil method getExecutionFactory.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static ExecutionFactory<Object, Object> getExecutionFactory(String name, TranslatorRepository vdbRepo, TranslatorRepository repo, VDBMetaData deployment, IdentityHashMap<Translator, ExecutionFactory<Object, Object>> map, HashSet<String> building) throws ConnectorManagerException {
    if (!building.add(name)) {
        throw new ConnectorManagerException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40138, building));
    }
    VDBTranslatorMetaData translator = vdbRepo.getTranslatorMetaData(name);
    if (translator == null) {
        translator = repo.getTranslatorMetaData(name);
    }
    if (translator == null) {
        return null;
    }
    ExecutionFactory<Object, Object> ef = map.get(translator);
    if (ef == null) {
        try {
            ef = TranslatorUtil.buildExecutionFactory(translator);
        } catch (TeiidException e) {
            throw new ConnectorManagerException(e);
        }
        if (ef instanceof DelegatingExecutionFactory) {
            DelegatingExecutionFactory delegator = (DelegatingExecutionFactory) ef;
            String delegateName = delegator.getDelegateName();
            if (delegateName != null) {
                ExecutionFactory<Object, Object> delegate = getExecutionFactory(delegateName, vdbRepo, repo, deployment, map, building);
                if (delegate == null) {
                    if (deployment != null) {
                        throw new ConnectorManagerException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31146, deployment.getName(), deployment.getVersion(), delegateName));
                    }
                    throw new ConnectorManagerException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40136, delegateName));
                }
                ((DelegatingExecutionFactory<Object, Object>) ef).setDelegate(delegate);
            }
        }
        map.put(translator, ef);
    }
    return ef;
}
Also used : ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) DelegatingExecutionFactory(org.teiid.translator.DelegatingExecutionFactory) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) TeiidException(org.teiid.core.TeiidException)

Example 15 with VDBTranslatorMetaData

use of org.teiid.adminapi.impl.VDBTranslatorMetaData in project teiid by teiid.

the class DatabaseUtil method convert.

public static VDBMetaData convert(Database database) {
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName(database.getName());
    vdb.setVersion(database.getVersion());
    vdb.setDescription(database.getAnnotation());
    if (database.getProperty("connection-type", false) != null) {
        vdb.setConnectionType(VDB.ConnectionType.valueOf(database.getProperty("connection-type", false)));
    }
    vdb.getPropertiesMap().putAll(database.getProperties());
    String domainDDLString = DDLStringVisitor.getDomainDDLString(database);
    if (!domainDDLString.isEmpty()) {
        vdb.addProperty(VDBMetaData.TEIID_DOMAINS, domainDDLString);
    }
    // translators
    for (DataWrapper dw : database.getDataWrappers()) {
        if (dw.getType() == null) {
            // we only care about the override types in the VDB
            continue;
        }
        VDBTranslatorMetaData translator = new VDBTranslatorMetaData();
        translator.setName(dw.getName());
        translator.setType(dw.getType());
        translator.setDescription(dw.getAnnotation());
        translator.getPropertiesMap().putAll(dw.getProperties());
        vdb.addOverideTranslator(translator);
    }
    for (Schema schema : database.getSchemas()) {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName(schema.getName());
        mmd.setDescription(schema.getAnnotation());
        mmd.setVisible(Boolean.valueOf(schema.isVisible()));
        mmd.getPropertiesMap().putAll(schema.getProperties());
        if (schema.isPhysical()) {
            mmd.setModelType(Model.Type.PHYSICAL);
            for (Server server : schema.getServers()) {
                // if there are more properties to create DS they will be lost in this translation
                String connectionName = server.getJndiName();
                if (connectionName == null) {
                    connectionName = server.getName();
                }
                mmd.addSourceMapping(server.getName(), server.getDataWrapper(), connectionName);
            }
        } else {
            mmd.setModelType(Model.Type.VIRTUAL);
        }
        vdb.addModel(mmd);
    }
    copyDatabaseGrantsAndRoles(database, vdb);
    return vdb;
}
Also used : VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Aggregations

VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)27 Test (org.junit.Test)13 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)6 ExecutionFactory (org.teiid.translator.ExecutionFactory)6 ModelNode (org.jboss.dmr.ModelNode)4 Translator (org.teiid.adminapi.Translator)4 ArrayList (java.util.ArrayList)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)3 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)3 TranslatorException (org.teiid.translator.TranslatorException)3 Properties (java.util.Properties)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 Module (org.jboss.modules.Module)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 TeiidException (org.teiid.core.TeiidException)2 UDFMetaData (org.teiid.deployers.UDFMetaData)2 TeiidConstants.asString (org.teiid.jboss.TeiidConstants.asString)2 IndexMetadataRepository (org.teiid.metadata.index.IndexMetadataRepository)2