Search in sources :

Example 1 with VDBResource

use of org.teiid.metadata.VDBResource in project teiid by teiid.

the class DDLFileMetadataRepository method loadMetadata.

@Override
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory, String text) throws TranslatorException {
    String ddlFile = factory.getModelProperties().getProperty("ddl-file");
    if (ddlFile != null) {
        text = ddlFile;
    }
    if (text != null) {
        VDBResource resource = factory.getVDBResources().get(text);
        if (resource == null) {
            throw new MetadataException(Event.TEIID31137, QueryPlugin.Util.gs(Event.TEIID31137, text));
        }
        InputStream is;
        try {
            is = resource.openStream();
        } catch (IOException e1) {
            throw new MetadataException(e1);
        }
        try {
            // TODO: could allow for a property driven encoding
            // $NON-NLS-1$
            factory.parse(new InputStreamReader(is, Charset.forName("UTF-8")));
        } finally {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : VDBResource(org.teiid.metadata.VDBResource) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) IOException(java.io.IOException) MetadataException(org.teiid.metadata.MetadataException)

Example 2 with VDBResource

use of org.teiid.metadata.VDBResource in project teiid by teiid.

the class FakeServer method deployVDB.

public void deployVDB(String vdbName, MetadataStore metadata, DeployVDBParameter parameterObject) {
    VDBMetaData vdbMetaData = null;
    try {
        if (parameterObject.vdbResources != null && parameterObject.useVdbXml) {
            VDBResource resource = parameterObject.vdbResources.get("/META-INF/vdb.xml");
            if (resource != null) {
                vdbMetaData = VDBMetadataParser.unmarshell(resource.openStream());
            }
        }
        if (vdbMetaData == null) {
            vdbMetaData = new VDBMetaData();
            vdbMetaData.setName(vdbName);
            for (Schema schema : metadata.getSchemas().values()) {
                ModelMetaData model = addModel(vdbMetaData, schema);
                if (parameterObject.metadataRepo != null) {
                    model.addAttchment(MetadataRepository.class, parameterObject.metadataRepo);
                    // fakeserver does not load through the repository framework, so call load after the fact here.
                    MetadataFactory mf = createMetadataFactory(vdbMetaData, metadata, model, parameterObject.vdbResources);
                    mf.setSchema(schema);
                    try {
                        parameterObject.metadataRepo.loadMetadata(mf, null, null);
                    } catch (TranslatorException e) {
                        throw new TeiidRuntimeException(e);
                    }
                }
            }
        } else {
            if (!parameterObject.useDataRoles) {
                vdbMetaData.setDataPolicies(Collections.EMPTY_LIST);
            }
            cmr.createConnectorManagers(vdbMetaData, this);
        }
        UDFMetaData udfMetaData = null;
        if (parameterObject.udfs != null) {
            udfMetaData = new UDFMetaData();
            for (Map.Entry<String, Collection<FunctionMethod>> entry : parameterObject.udfs.entrySet()) {
                udfMetaData.addFunctions(entry.getKey(), entry.getValue());
            }
        }
        if (parameterObject.vdbImports != null) {
            for (VDBImportMetadata vdbImport : parameterObject.vdbImports) {
                vdbMetaData.getVDBImports().add(vdbImport);
            }
        }
        vdbMetaData.setStatus(VDB.Status.ACTIVE);
        this.repo.addVDB(vdbMetaData, metadata, parameterObject.vdbResources, udfMetaData, cmr);
        this.repo.finishDeployment(vdbMetaData.getName(), vdbMetaData.getVersion());
        this.repo.getLiveVDB(vdbMetaData.getName(), vdbMetaData.getVersion()).setStatus(VDB.Status.ACTIVE);
    } catch (VirtualDatabaseException e) {
        throw new RuntimeException(e);
    } catch (ConnectorManagerException e) {
        throw new RuntimeException(e);
    } catch (XMLStreamException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) VDBResource(org.teiid.metadata.VDBResource) Schema(org.teiid.metadata.Schema) UDFMetaData(org.teiid.deployers.UDFMetaData) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) IOException(java.io.IOException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) ConnectorManagerException(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) MetadataFactory(org.teiid.metadata.MetadataFactory) VDBMetadataFactory(org.teiid.metadata.index.VDBMetadataFactory) XMLStreamException(javax.xml.stream.XMLStreamException) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Collection(java.util.Collection) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)2 VDBResource (org.teiid.metadata.VDBResource)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)1 VDBImportMetadata (org.teiid.adminapi.impl.VDBImportMetadata)1 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)1 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)1 UDFMetaData (org.teiid.deployers.UDFMetaData)1 VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)1 ConnectorManagerException (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository.ConnectorManagerException)1 MetadataException (org.teiid.metadata.MetadataException)1 MetadataFactory (org.teiid.metadata.MetadataFactory)1 Schema (org.teiid.metadata.Schema)1 VDBMetadataFactory (org.teiid.metadata.index.VDBMetadataFactory)1 TranslatorException (org.teiid.translator.TranslatorException)1