Search in sources :

Example 21 with MetadataStore

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

the class TestValidator method exampleMetadata3.

public static TransformationMetadata exampleMetadata3() {
    MetadataStore metadataStore = new MetadataStore();
    // Create metadata objects
    // $NON-NLS-1$
    Schema modelObj = RealMetadataFactory.createPhysicalModel("test", metadataStore);
    // $NON-NLS-1$
    Table groupObj = RealMetadataFactory.createPhysicalGroup("group", modelObj);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e0", groupObj, DataTypeManager.DefaultDataTypes.INTEGER);
    // $NON-NLS-1$
    Column elemObj1 = RealMetadataFactory.createElement("e1", groupObj, DataTypeManager.DefaultDataTypes.STRING);
    elemObj1.setNullType(NullType.No_Nulls);
    elemObj1.setDefaultValue(Boolean.FALSE.toString());
    elemObj1.setAutoIncremented(true);
    // $NON-NLS-1$
    elemObj1.setNameInSource("e1:SEQUENCE=MYSEQUENCE.nextVal");
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "example3");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) Schema(org.teiid.metadata.Schema)

Example 22 with MetadataStore

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

the class VDBService method start.

@Override
public void start(final StartContext context) throws StartException {
    ConnectorManagerRepository cmr = new ConnectorManagerRepository();
    TranslatorRepository repo = new TranslatorRepository();
    this.vdb.addAttchment(TranslatorRepository.class, repo);
    // check if this is a VDB with index files, if there are then build the TransformationMetadata
    UDFMetaData udf = this.vdb.getAttachment(UDFMetaData.class);
    // add required connector managers; if they are not already there
    for (Translator t : this.vdb.getOverrideTranslators()) {
        VDBTranslatorMetaData data = (VDBTranslatorMetaData) t;
        String type = data.getType();
        VDBTranslatorMetaData parent = getTranslatorRepository().getTranslatorMetaData(type);
        data.setModuleName(parent.getModuleName());
        data.addAttchment(ClassLoader.class, parent.getAttachment(ClassLoader.class));
        data.setParent(parent);
        repo.addTranslatorMetadata(data.getName(), data);
    }
    createConnectorManagers(cmr, repo, this.vdb);
    final ServiceBuilder<Void> vdbService = addVDBFinishedService(context);
    this.vdbListener = new VDBLifeCycleListener() {

        @Override
        public void added(String name, CompositeVDB cvdb) {
        }

        @Override
        public void beforeRemove(String name, CompositeVDB cvdb) {
        }

        @Override
        public void removed(String name, CompositeVDB cvdb) {
        }

        @Override
        public void finishedDeployment(String name, CompositeVDB cvdb) {
            if (!VDBService.this.vdbKey.equals(cvdb.getVDBKey())) {
                return;
            }
            // clear out the indexmetadatarepository as it holds state that is no longer necessary
            // $NON-NLS-1$
            repositories.put("index", new IndexMetadataRepository());
            VDBMetaData vdbInstance = cvdb.getVDB();
            if (vdbInstance.getStatus().equals(Status.ACTIVE)) {
                vdbService.install();
            }
        }
    };
    getVDBRepository().addListener(this.vdbListener);
    MetadataStore store = new MetadataStore();
    try {
        // check to see if there is an index file.  if there is then we assume
        // that index is the default metadata repo
        MetadataRepository<?, ?> defaultRepo = null;
        for (String s : this.vdbResources.getEntriesPlusVisibilities().keySet()) {
            if (s.endsWith(VDBResources.INDEX_EXT)) {
                // $NON-NLS-1$
                defaultRepo = super.getMetadataRepository("index");
                break;
            }
        }
        this.assignMetadataRepositories(vdb, defaultRepo);
        // add transformation metadata to the repository.
        getVDBRepository().addVDB(this.vdb, store, vdbResources.getEntriesPlusVisibilities(), udf, cmr);
    } catch (VirtualDatabaseException e) {
        cleanup(context);
        throw new StartException(e);
    }
    this.vdb.removeAttachment(UDFMetaData.class);
    try {
        loadMetadata(this.vdb, cmr, store, this.vdbResources);
    } catch (TranslatorException e) {
        cleanup(context);
        throw new StartException(e);
    }
    this.runtimeVDB = buildRuntimeVDB(this.vdb, context.getController().getServiceContainer());
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) CompositeVDB(org.teiid.deployers.CompositeVDB) UDFMetaData(org.teiid.deployers.UDFMetaData) TranslatorRepository(org.teiid.dqp.internal.datamgr.TranslatorRepository) IndexMetadataRepository(org.teiid.metadata.index.IndexMetadataRepository) MetadataStore(org.teiid.metadata.MetadataStore) Translator(org.teiid.adminapi.Translator) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBLifeCycleListener(org.teiid.deployers.VDBLifeCycleListener) StartException(org.jboss.msc.service.StartException) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 23 with MetadataStore

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

the class TestMatViewAliasing method setUp.

@Before
public void setUp() throws Exception {
    server = new FakeServer(true);
    VDBRepository vdbRepository = new VDBRepository();
    MetadataFactory mf = new MetadataFactory(null, 1, "foo", vdbRepository.getRuntimeTypeMap(), new Properties(), null);
    mf.getSchema().setPhysical(false);
    Table mat = mf.addTable("mat");
    mat.setVirtual(true);
    mat.setMaterialized(true);
    mat.setSelectTransformation("/*+ cache(ttl:0) */ select 1 as x, 'y' as Name");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.INTEGER, mat);
    mf.addColumn("Name", DataTypeManager.DefaultDataTypes.STRING, mat);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB(MATVIEWS, ms);
    conn = server.createConnection("jdbc:teiid:" + MATVIEWS);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) FakeServer(org.teiid.jdbc.FakeServer) VDBRepository(org.teiid.deployers.VDBRepository) Properties(java.util.Properties) Before(org.junit.Before)

Example 24 with MetadataStore

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

the class EmbeddedServer method deployVDB.

protected void deployVDB(VDBMetaData vdb, VDBResources resources) throws ConnectorManagerException, VirtualDatabaseException, TranslatorException {
    checkStarted();
    if (!vdb.getOverrideTranslators().isEmpty() && !allowOverrideTranslators()) {
        throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40106, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40106, vdb.getName()));
    }
    vdb.addAttchment(ClassLoader.class, Thread.currentThread().getContextClassLoader());
    try {
        createPreParser(vdb);
    } catch (TeiidException e1) {
        throw new VirtualDatabaseException(e1);
    }
    cmr.createConnectorManagers(vdb, this);
    MetadataStore metadataStore = new MetadataStore();
    UDFMetaData udfMetaData = new UDFMetaData();
    udfMetaData.setFunctionClassLoader(Thread.currentThread().getContextClassLoader());
    MetadataRepository<?, ?> defaultRepo = null;
    LinkedHashMap<String, VDBResources.Resource> visibilityMap = null;
    if (resources != null) {
        // that index is the default metadata repo
        for (String s : resources.getEntriesPlusVisibilities().keySet()) {
            if (s.endsWith(VDBResources.INDEX_EXT)) {
                defaultRepo = new IndexMetadataRepository();
                break;
            }
        }
        visibilityMap = resources.getEntriesPlusVisibilities();
    } else {
        visibilityMap = new LinkedHashMap<String, VDBResources.Resource>();
    }
    this.assignMetadataRepositories(vdb, defaultRepo);
    repo.addVDB(vdb, metadataStore, visibilityMap, udfMetaData, cmr);
    try {
        this.loadMetadata(vdb, cmr, metadataStore, resources);
    } catch (VDBValidationError e) {
        throw new VirtualDatabaseException(RuntimePlugin.Event.valueOf(e.getCode()), e.getMessage());
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) IndexMetadataRepository(org.teiid.metadata.index.IndexMetadataRepository) UDFMetaData(org.teiid.deployers.UDFMetaData) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) TeiidException(org.teiid.core.TeiidException)

Example 25 with MetadataStore

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

the class VDBRepository method addVDB.

public void addVDB(VDBMetaData vdb, MetadataStore metadataStore, LinkedHashMap<String, VDBResources.Resource> visibilityMap, UDFMetaData udf, ConnectorManagerRepository cmr) throws VirtualDatabaseException {
    // get the system VDB metadata store
    if (this.systemStore == null) {
        throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40022, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40022));
    }
    if (dataRolesRequired && vdb.getDataPolicyMap().isEmpty()) {
        throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40143, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40143, vdb));
    }
    boolean pgMetadataEnabled = ADD_PG_METADATA;
    String includePgMetadata = vdb.getPropertyValue("include-pg-metadata");
    if (includePgMetadata != null) {
        pgMetadataEnabled = Boolean.parseBoolean(includePgMetadata);
    }
    if (pgMetadataEnabled && odbcException != null) {
        throw odbcException;
    }
    MetadataStore[] stores = null;
    if (pgMetadataEnabled) {
        stores = new MetadataStore[] { this.systemStore, odbcStore };
    } else {
        stores = new MetadataStore[] { this.systemStore };
    }
    CompositeVDB cvdb = new CompositeVDB(vdb, metadataStore, visibilityMap, udf, this.systemFunctionManager.getSystemFunctions(), cmr, this, stores);
    lock.lock();
    try {
        VDBKey vdbKey = cvdb.getVDBKey();
        if (vdbKey.isAtMost()) {
            throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40145, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40145, vdbKey));
        }
        if (vdbRepo.containsKey(vdbKey)) {
            throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40035, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40035, vdb.getName(), vdb.getVersion()));
        }
        // canonicalize the version
        vdb.setVersion(vdbKey.getVersion());
        // save the key for comparisons
        vdb.addAttchment(VDBKey.class, vdbKey);
        vdb.setStatus(Status.LOADING);
        this.vdbRepo.put(vdbKey, cvdb);
        this.pendingDeployments.remove(vdbKey);
        vdbAdded.signalAll();
    } finally {
        lock.unlock();
    }
    notifyAdd(vdb.getName(), vdb.getVersion(), cvdb);
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBKey(org.teiid.vdb.runtime.VDBKey)

Aggregations

MetadataStore (org.teiid.metadata.MetadataStore)73 Schema (org.teiid.metadata.Schema)47 Test (org.junit.Test)38 Table (org.teiid.metadata.Table)37 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)22 QueryNode (org.teiid.query.mapping.relational.QueryNode)19 Column (org.teiid.metadata.Column)17 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)15 Properties (java.util.Properties)12 MetadataFactory (org.teiid.metadata.MetadataFactory)12 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)12 Procedure (org.teiid.metadata.Procedure)11 List (java.util.List)9 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 Connection (java.sql.Connection)8 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)8 ArrayList (java.util.ArrayList)7 ProcedureParameter (org.teiid.metadata.ProcedureParameter)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6