Search in sources :

Example 1 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class DatabaseUtil method convert.

public static Database convert(VDBMetaData vdb, MetadataStore metadataStore) {
    Database db = new Database(vdb.getName(), vdb.getVersion());
    db.setProperties(vdb.getPropertiesMap());
    if (vdb.getDescription() != null) {
        db.setAnnotation(vdb.getDescription());
    }
    db.setProperty("connection-type", vdb.getConnectionType().name());
    db.getMetadataStore().addDataTypes(metadataStore.getDatatypes());
    // override translators
    List<Translator> translators = vdb.getOverrideTranslators();
    for (Translator t : translators) {
        // add the base
        if (db.getDataWrapper(t.getType()) == null) {
            DataWrapper dw = new DataWrapper(t.getType());
            db.addDataWrapper(dw);
        }
        // add override with properties
        if (db.getDataWrapper(t.getName()) == null) {
            DataWrapper dw = new DataWrapper(t.getName());
            dw.setType(t.getType());
            for (final String key : t.getProperties().stringPropertyNames()) {
                dw.setProperty(key, t.getPropertyValue(key));
            }
            if (t.getDescription() != null) {
                dw.setAnnotation(t.getDescription());
            }
            db.addDataWrapper(dw);
        }
    }
    Collection<ModelMetaData> models = vdb.getModelMetaDatas().values();
    for (ModelMetaData m : models) {
        Schema schema = metadataStore.getSchema(m.getName());
        // add servers
        if (m.isSource()) {
            Collection<SourceMappingMetadata> sources = m.getSourceMappings();
            for (SourceMappingMetadata s : sources) {
                // add translators, that are not override
                if (db.getDataWrapper(s.getTranslatorName()) == null) {
                    DataWrapper dw = new DataWrapper(s.getTranslatorName());
                    db.addDataWrapper(dw);
                }
                // add servers
                Server server = new Server(s.getName());
                server.setJndiName(s.getConnectionJndiName());
                server.setDataWrapper(s.getTranslatorName());
                // no need to add duplicate definitions.
                if (db.getServer(s.getName()) == null) {
                    db.addServer(server);
                    schema.addServer(server);
                }
            }
        }
        db.addSchema(schema);
    }
    for (String key : vdb.getDataPolicyMap().keySet()) {
        DataPolicyMetadata dpm = vdb.getDataPolicyMap().get(key);
        Role role = new Role(dpm.getName());
        if (dpm.getMappedRoleNames() != null && !dpm.getMappedRoleNames().isEmpty()) {
            role.setJaasRoles(dpm.getMappedRoleNames());
        }
        if (dpm.isAnyAuthenticated()) {
            role.setAnyAuthenticated(true);
        }
        Grant grant = null;
        if (dpm.isGrantAll()) {
            if (grant == null) {
                grant = new Grant();
                grant.setRole(role.getName());
            }
            Permission permission = new Permission();
            permission.setAllowAllPrivileges(true);
            permission.setResourceType(ResourceType.DATABASE);
            grant.addPermission(permission);
        }
        if (dpm.isAllowCreateTemporaryTables() != null && dpm.isAllowCreateTemporaryTables()) {
            if (grant == null) {
                grant = new Grant();
                grant.setRole(role.getName());
            }
            Permission permission = new Permission();
            permission.setAllowTemporyTables(true);
            permission.setResourceType(ResourceType.DATABASE);
            grant.addPermission(permission);
        }
        for (DataPolicy.DataPermission dp : dpm.getPermissions()) {
            if (grant == null) {
                grant = new Grant();
                grant.setRole(role.getName());
            }
            Permission permission = convert(dp);
            grant.addPermission(permission);
        }
        db.addRole(role);
        db.addGrant(grant);
    }
    return db;
}
Also used : ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) Translator(org.teiid.adminapi.Translator) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) DataPermission(org.teiid.adminapi.DataPolicy.DataPermission) DataPermission(org.teiid.adminapi.DataPolicy.DataPermission) Permission(org.teiid.metadata.Grant.Permission) DataPolicy(org.teiid.adminapi.DataPolicy)

Example 2 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestMetaDataProcessor method examplePrivatePhysicalModelVDB.

public static VDBMetaData examplePrivatePhysicalModelVDB() {
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("example1");
    vdb.setVersion(1);
    ModelMetaData m = RealMetadataFactory.createModel("pm1", true);
    m.setVisible(false);
    vdb.addModel(m);
    vdb.addModel(RealMetadataFactory.createModel("vm1", false));
    return vdb;
}
Also used : VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 3 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestMultiSourcePlanToProcessConverter method testGroupByCountPushdownMultiSource.

@Test
public void testGroupByCountPushdownMultiSource() throws Exception {
    String userSql = "SELECT s.e1, m.e1, COUNT(*) FROM pm1.g1 AS s INNER JOIN pm2.g2 AS m ON s.e2 = m.e2 GROUP BY s.e1, m.e1";
    HardcodedDataManager hdm = new HardcodedDataManager();
    hdm.addData("SELECT g_0.e2, COUNT(*) FROM pm1.g1 AS g_0 GROUP BY g_0.e2", Arrays.asList(1, 2));
    hdm.addData("SELECT g_0.e2 AS c_0, g_0.e1 AS c_1 FROM pm2.g2 AS g_0 ORDER BY c_0", Arrays.asList(1, "other"));
    BasicSourceCapabilities bsc = TestAggregatePushdown.getAggregateCapabilities();
    bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_INNER, false);
    bsc.setCapabilitySupport(Capability.QUERY_FROM_JOIN_OUTER, false);
    TransformationMetadata metadata = RealMetadataFactory.example1Cached();
    final List<?>[] expected = new List<?>[] { Arrays.asList("a", "other", 2), Arrays.asList("b", "other", 2) };
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("exampleMultiBinding");
    vdb.setVersion(1);
    ModelMetaData model = new ModelMetaData();
    model.setName("pm1");
    model.setModelType(Model.Type.PHYSICAL);
    model.setVisible(true);
    model.setSupportsMultiSourceBindings(true);
    model.addProperty(MultiSourceMetadataWrapper.MULTISOURCE_COLUMN_NAME, "e1");
    vdb.addModel(model);
    helpTestMultiSourcePlan(metadata, userSql, "pm1", 2, hdm, expected, vdb, null, new Options().implicitMultiSourceJoin(false), bsc);
}
Also used : Options(org.teiid.query.util.Options) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) HardcodedDataManager(org.teiid.query.processor.HardcodedDataManager) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) List(java.util.List) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 4 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestConnectorCapabilitiesFinder method testFindRequiresSource.

@Test
public void testFindRequiresSource() throws Exception {
    // $NON-NLS-1$
    String modelName = "model";
    // $NON-NLS-1$
    String functionName = "fakeFunction";
    ArrayList<String> bindings = new ArrayList<String>();
    bindings.add(modelName);
    VDBMetaData vdb = Mockito.mock(VDBMetaData.class);
    ModelMetaData model = Mockito.mock(ModelMetaData.class);
    Mockito.stub(vdb.getModel(modelName)).toReturn(model);
    Mockito.stub(model.getSourceNames()).toReturn(bindings);
    BasicSourceCapabilities basicSourceCapabilities = new BasicSourceCapabilities();
    basicSourceCapabilities.setFunctionSupport(functionName, true);
    ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
    ConnectorManager cm = Mockito.mock(ConnectorManager.class);
    Mockito.stub(cm.getCapabilities()).toThrow(new TranslatorException());
    Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(cm);
    CachedFinder finder = new CachedFinder(repo, vdb);
    // Test
    SourceCapabilities actual = finder.findCapabilities(modelName);
    // $NON-NLS-1$
    assertNotNull(actual);
    assertFalse(finder.isValid(modelName));
}
Also used : BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) SourceCapabilities(org.teiid.query.optimizer.capabilities.SourceCapabilities) BasicSourceCapabilities(org.teiid.query.optimizer.capabilities.BasicSourceCapabilities) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 5 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestODataIntegration method testEntityId.

@Test
public void testEntityId() throws Exception {
    HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
    hc.addUpdate("UPDATE x SET c = 6 WHERE x.a = 'a'", new int[] { 1 });
    hc.addUpdate("UPDATE x SET b = '6' WHERE x.a = 'a'", new int[] { 1 });
    teiid.addTranslator("x1", hc);
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("m");
        mmd.addSourceMetadata("ddl", "create foreign table x (a string, b string, c integer, " + "primary key (a)) options (updatable true);");
        mmd.addSourceMapping("x1", "x1", null);
        teiid.deployVDB("northwind", mmd);
        localClient = getClient(teiid.getDriver(), "northwind", new Properties());
        ContentResponse response = http.newRequest(baseURL + "/northwind/m/$entity?$id=" + baseURL + "/northwind/m/x('a')&$select=b").method("GET").send();
        assertEquals(200, response.getStatus());
        assertEquals("{\"@odata.context\":\"$metadata#x(b)/$entity\"," + "\"@odata.id\":\"" + baseURL + "/northwind/m/x('ABCDEFG')\"," + "\"b\":\"ABCDEFG\"}", response.getContentAsString());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

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