Search in sources :

Example 1 with Database

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

the class TestDDLStringVisitor method testDatabaseWithDomains.

@Test
public void testDatabaseWithDomains() throws Exception {
    String expected = "\n" + "/*\n" + "###########################################\n" + "# START DATABASE foo\n" + "###########################################\n" + "*/\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';\n" + "\n" + "--############ Domains ############\n" + "CREATE DOMAIN x AS string(1000) NOT NULL;\n\n" + "CREATE DOMAIN y AS integer NOT NULL;\n\n" + "CREATE DOMAIN z AS bigdecimal(10,2) NOT NULL;\n\n" + "\n--############ Schemas ############\n" + "CREATE VIRTUAL SCHEMA SchemaA;\n\n" + "\n--############ Schema:SchemaA ############\n" + "SET SCHEMA SchemaA;\n" + "\n" + "CREATE VIEW G1 (\n" + "\te1 x,\n" + "\te2 y\n" + ")\nAS\nSELECT 'a', 1;\n" + "/*\n" + "###########################################\n" + "# END DATABASE foo\n" + "###########################################\n" + "*/\n" + "\n";
    Database db = TestDDLParser.helpParse(expected);
    String metadataDDL = DDLStringVisitor.getDDLString(db);
    assertEquals(expected, metadataDDL);
}
Also used : Database(org.teiid.metadata.Database) Test(org.junit.Test)

Example 2 with Database

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

the class TestDDLStringVisitor method testGrants.

@Test
public void testGrants() throws Exception {
    Database db = new Database("foo", "2");
    Role role = new Role("admin");
    role.setAnyAuthenticated(true);
    Role role1 = new Role("uber");
    Grant.Permission permission = new Grant.Permission();
    permission.setAllowAlter(true);
    permission.setAllowSelect(true);
    permission.setResourceName("schema.tableName");
    permission.setResourceType(ResourceType.TABLE);
    Grant.Permission permission2 = new Grant.Permission();
    permission2.setAllowDelete(true);
    permission2.setResourceName("schema.tableName");
    permission2.setResourceType(ResourceType.TABLE);
    Grant.Permission permission3 = new Grant.Permission();
    permission3.setAllowAllPrivileges(true);
    permission3.setAllowTemporyTables(true);
    Grant.Permission permission4 = new Grant.Permission();
    permission4.setAllowTemporyTables(true);
    Grant g = new Grant();
    g.setRole(role.getName());
    g.addPermission(permission);
    g.addPermission(permission4);
    Grant g2 = new Grant();
    g2.setRole(role.getName());
    g2.addPermission(permission2);
    Grant g3 = new Grant();
    g3.setRole("uber");
    g3.addPermission(permission3);
    db.addRole(role);
    db.addRole(role1);
    db.addGrant(g);
    db.addGrant(g2);
    db.addGrant(g3);
    String expected = "\n" + "/*\n" + "###########################################\n" + "# START DATABASE foo\n" + "###########################################\n" + "*/\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';\n" + "\n" + "--############ Roles ############\n" + "CREATE ROLE admin WITH ANY AUTHENTICATED;\n\n" + "CREATE ROLE uber;\n\n\n" + "--############ Grants ############\n" + "GRANT SELECT,DELETE,ALTER ON TABLE \"schema.tableName\" TO admin;\n" + "GRANT TEMPORARY TABLE TO admin;\n\n" + "GRANT ALL PRIVILEGES TO uber;\n" + "GRANT TEMPORARY TABLE TO uber;\n" + "\n" + "\n" + "/*\n" + "###########################################\n" + "# END DATABASE foo\n" + "###########################################\n" + "*/\n" + "\n";
    String metadataDDL = DDLStringVisitor.getDDLString(db);
    assertEquals(expected, metadataDDL);
}
Also used : Role(org.teiid.metadata.Role) Grant(org.teiid.metadata.Grant) Database(org.teiid.metadata.Database) Test(org.junit.Test)

Example 3 with Database

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

the class TestDDLStringVisitor method testSchema.

@Test
public void testSchema() throws Exception {
    Database db = new Database("foo", "2");
    DataWrapper dw = new DataWrapper("orcle");
    db.addDataWrapper(dw);
    Server s = new Server("testing");
    s.setDataWrapper(dw.getName());
    s.setJndiName("java://test-server");
    s.setType("orcl");
    db.addServer(s);
    String table = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar)";
    Table t = TestDDLParser.helpParse(table, "SchemaA").getSchema().getTable("G1");
    Schema schema = new Schema();
    schema.setName("SchemaA");
    schema.addTable(t);
    schema.addServer(s);
    db.addSchema(schema);
    String metadataDDL = DDLStringVisitor.getDDLString(db);
    String expected = "\n" + "/*\n" + "###########################################\n" + "# START DATABASE foo\n" + "###########################################\n" + "*/\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';" + "\n" + "\n--############ Translators ############\n" + "CREATE FOREIGN DATA WRAPPER orcle;\n" + "\n" + "\n--############ Servers ############\n" + "CREATE SERVER testing TYPE 'orcl' FOREIGN DATA WRAPPER orcle OPTIONS (\"jndi-name\" 'java://test-server');\n" + "\n" + "\n--############ Schemas ############\n" + "CREATE SCHEMA SchemaA SERVER testing;\n\n" + "\n--############ Schema:SchemaA ############\n" + "SET SCHEMA SchemaA;\n" + "\n" + "CREATE FOREIGN TABLE G1 (\n" + "\te1 integer,\n" + "\te2 string\n" + ");\n" + "/*\n" + "###########################################\n" + "# END DATABASE foo\n" + "###########################################\n" + "*/\n" + "\n";
    assertEquals(expected, metadataDDL);
}
Also used : DataWrapper(org.teiid.metadata.DataWrapper) Table(org.teiid.metadata.Table) Server(org.teiid.metadata.Server) Schema(org.teiid.metadata.Schema) Database(org.teiid.metadata.Database) Test(org.junit.Test)

Example 4 with Database

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

the class QueryParser method parseDDL.

public void parseDDL(final MetadataFactory factory, Reader ddl) {
    SingleSchemaDatabaseStore store = new SingleSchemaDatabaseStore(factory);
    store.startEditing(true);
    Database db = new Database(factory.getVdbName(), factory.getVdbVersion());
    store.databaseCreated(db);
    store.databaseSwitched(factory.getVdbName(), factory.getVdbVersion());
    store.dataWrapperCreated(new DataWrapper(NONE));
    Server server = new Server(NONE);
    server.setDataWrapper(NONE);
    store.serverCreated(server);
    if (factory.getSchema().isPhysical()) {
        Server s = new Server(factory.getSchema().getName());
        s.setDataWrapper(NONE);
        store.serverCreated(s);
    }
    List<String> servers = Collections.emptyList();
    store.schemaCreated(factory.getSchema(), servers);
    // with the schema created, create the TransformationMetadata
    CompositeMetadataStore cms = new CompositeMetadataStore(db.getMetadataStore());
    TransformationMetadata qmi = new TransformationMetadata(DatabaseUtil.convert(db), cms, null, null, null);
    store.setTransformationMetadata(qmi);
    store.schemaSwitched(factory.getSchema().getName());
    store.setMode(Mode.SCHEMA);
    store.setStrict(true);
    try {
        parseDDL(store, ddl);
        Map<String, String> colNs = store.getNameSpaces();
        for (String key : colNs.keySet()) {
            factory.addNamespace(key, colNs.get(key));
        }
    } finally {
        store.stopEditing();
    }
}
Also used : DataWrapper(org.teiid.metadata.DataWrapper) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) Server(org.teiid.metadata.Server) Database(org.teiid.metadata.Database)

Example 5 with Database

use of org.teiid.metadata.Database 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)

Aggregations

Database (org.teiid.metadata.Database)9 Test (org.junit.Test)4 StringReader (java.io.StringReader)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)2 DataWrapper (org.teiid.metadata.DataWrapper)2 MetadataRepository (org.teiid.metadata.MetadataRepository)2 Schema (org.teiid.metadata.Schema)2 Server (org.teiid.metadata.Server)2 DeploymentBasedDatabaseStore (org.teiid.metadatastore.DeploymentBasedDatabaseStore)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 BufferedReader (java.io.BufferedReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 VDBImportMetadata (org.teiid.adminapi.impl.VDBImportMetadata)1 VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)1 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)1