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;
}
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;
}
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);
}
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));
}
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");
}
}
Aggregations