use of org.teiid.metadata.DataWrapper 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);
}
use of org.teiid.metadata.DataWrapper 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();
}
}
Aggregations