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);
}
}
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);
}
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);
}
}
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;
}
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;
}
Aggregations