use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class PlanToProcessConverter method aliasCommand.
private Command aliasCommand(AccessNode aNode, Command command, Object modelID) throws TeiidComponentException, QueryPlannerException {
try {
command = (Command) command.clone();
boolean aliasGroups = modelID != null && (CapabilitiesUtil.supportsGroupAliases(modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
boolean aliasColumns = modelID != null && (CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
AliasGenerator visitor = new AliasGenerator(aliasGroups, !aliasColumns);
SourceHint sh = command.getSourceHint();
if (sh != null && aliasGroups) {
VDBMetaData vdb = context.getDQPWorkContext().getVDB();
ModelMetaData model = vdb.getModel(aNode.getModelName());
List<String> sourceNames = model.getSourceNames();
SpecificHint sp = null;
if (sourceNames.size() == 1) {
sp = sh.getSpecificHint(sourceNames.get(0));
}
if (sh.isUseAliases() || (sp != null && sp.isUseAliases())) {
visitor.setAliasMapping(context.getAliasMapping());
}
}
List<Reference> references = ReferenceCollectorVisitor.getReferences(command);
if (!references.isEmpty()) {
Set<String> correleatedGroups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
for (Reference ref : references) {
if (ref.isCorrelated() && ref.getExpression().getGroupSymbol() != null) {
correleatedGroups.add(ref.getExpression().getGroupSymbol().getName());
}
}
visitor.setCorrelationGroups(correleatedGroups);
}
command.acceptVisitor(visitor);
} catch (QueryMetadataException err) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30249, err);
} catch (TeiidRuntimeException e) {
if (e.getCause() instanceof QueryPlannerException) {
throw (QueryPlannerException) e.getCause();
}
throw e;
}
return command;
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class AbstractVDBDeployer method loadMetadata.
protected void loadMetadata(VDBMetaData vdb, ConnectorManagerRepository cmr, MetadataStore store, VDBResources vdbResources) throws TranslatorException {
// add the system types
store.addDataTypes(SystemMetadata.getInstance().getRuntimeTypeMap());
// add domains if defined
String value = vdb.getPropertyValue(VDBMetaData.TEIID_DOMAINS);
if (value != null) {
// use a temporary store/db to retrieve the domains
DatabaseStore dbStore = new DatabaseStore() {
@Override
public Map<String, Datatype> getRuntimeTypes() {
return getVDBRepository().getRuntimeTypeMap();
}
};
dbStore.startEditing(true);
// $NON-NLS-1$ //$NON-NLS-2$
dbStore.databaseCreated(new Database("x", "1"));
// $NON-NLS-1$ //$NON-NLS-2$
dbStore.databaseSwitched("x", "1");
dbStore.setMode(Mode.DOMAIN);
QueryParser.getQueryParser().parseDDL(dbStore, new StringReader(value));
dbStore.stopEditing();
// $NON-NLS-1$ //$NON-NLS-2$
store.addDataTypes(dbStore.getDatabase("x", "1").getMetadataStore().getDatatypes());
}
// load metadata from the models
AtomicInteger loadCount = new AtomicInteger();
for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
if (model.getModelType() == Model.Type.PHYSICAL || model.getModelType() == Model.Type.VIRTUAL) {
loadCount.incrementAndGet();
}
}
if (loadCount.get() == 0) {
processVDBDDL(vdb, store, cmr, vdbResources);
getVDBRepository().finishDeployment(vdb.getName(), vdb.getVersion());
return;
}
for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
MetadataRepository metadataRepository = model.getAttachment(MetadataRepository.class);
if (model.getModelType() == Model.Type.PHYSICAL || model.getModelType() == Model.Type.VIRTUAL) {
loadMetadata(vdb, model, cmr, metadataRepository, store, loadCount, vdbResources);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "Model ", model.getName(), "in VDB ", vdb.getName(), " was being loaded from its repository");
} else {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "Model ", model.getName(), "in VDB ", vdb.getName(), " skipped being loaded because of its type ", model.getModelType());
}
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class EmbeddedAdminImpl method updateSource.
@Override
public void updateSource(String vdbName, String vdbVersion, String sourceName, String translatorName, String dsName) throws AdminException {
VDBMetaData vdb = checkVDB(vdbName, vdbVersion);
synchronized (vdb) {
for (ModelMetaData m : vdb.getModelMetaDatas().values()) {
SourceMappingMetadata mapping = m.getSourceMapping(sourceName);
if (mapping != null) {
mapping.setTranslatorName(translatorName);
mapping.setConnectionJndiName(dsName);
}
}
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class RuntimeVDB method removeSource.
public ReplaceResult removeSource(String modelName, String sourceName) throws AdminProcessingException {
synchronized (this.vdb) {
ModelMetaData model = this.vdb.getModel(modelName);
if (model == null) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40090, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40090, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
if (!model.isSupportsMultiSourceBindings()) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40108, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40108, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
if (model.getSources().size() == 1) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40109, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40109, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
SourceMappingMetadata source = model.getSources().remove(sourceName);
if (source == null) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40091, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40091, sourceName, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
if (model.getSources().size() == 1) {
// we default to multi-source with multiple sources, so now we need to explicitly set to true
model.setSupportsMultiSourceBindings(true);
}
String previousDsName = source.getConnectionJndiName();
boolean success = false;
try {
this.listener.dataSourceChanged(modelName, sourceName, null, null);
ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
// detect if the ConnectorManager is still used
boolean exists = false;
for (ModelMetaData m : this.vdb.getModelMetaDatas().values()) {
if (m == model) {
continue;
}
if (m.getSourceMapping(sourceName) != null) {
exists = true;
break;
}
}
if (!exists) {
cmr.removeConnectorManager(sourceName);
}
ReplaceResult rr = new ReplaceResult();
if (!dsExists(previousDsName, cmr)) {
rr.removedDs = previousDsName;
}
success = true;
return rr;
} finally {
if (!success) {
// TODO: this means that the order has changed
model.addSourceMapping(source);
}
}
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class VDBRepository method validateDataSources.
void validateDataSources(VDBMetaData vdb) {
ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
if (model.isSource()) {
Collection<SourceMappingMetadata> mappings = model.getSourceMappings();
for (SourceMappingMetadata mapping : mappings) {
ConnectorManager cm = cmr.getConnectorManager(mapping.getName());
if (cm != null) {
String msg = cm.getStausMessage();
if (msg != null && msg.length() > 0) {
model.addRuntimeError(msg);
model.setMetadataStatus(Model.MetadataStatus.FAILED);
LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
}
}
}
}
}
}
Aggregations