Search in sources :

Example 86 with ModelMetaData

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;
}
Also used : Reference(org.teiid.query.sql.symbol.Reference) SpecificHint(org.teiid.query.sql.lang.SourceHint.SpecificHint) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryPlannerException(org.teiid.api.exception.query.QueryPlannerException)

Example 87 with ModelMetaData

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());
        }
    }
}
Also used : MetadataRepository(org.teiid.metadata.MetadataRepository) DeploymentBasedDatabaseStore(org.teiid.metadatastore.DeploymentBasedDatabaseStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Database(org.teiid.metadata.Database) StringReader(java.io.StringReader) Datatype(org.teiid.metadata.Datatype) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 88 with ModelMetaData

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);
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 89 with ModelMetaData

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);
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 90 with ModelMetaData

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);
                    }
                }
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Aggregations

ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)191 Test (org.junit.Test)131 Properties (java.util.Properties)50 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)45 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)43 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)36 Connection (java.sql.Connection)23 MetadataFactory (org.teiid.metadata.MetadataFactory)21 Statement (java.sql.Statement)19 ResultSet (java.sql.ResultSet)18 CallableStatement (java.sql.CallableStatement)16 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)15 ArrayList (java.util.ArrayList)13 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)11 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)11 Table (org.teiid.metadata.Table)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 List (java.util.List)9 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)9 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)9