@Test public void testSchema() throws Exception { Database db = new Database("foo", "2"); DataWrapper dw = new DataWrapper("oracle"); db.addDataWrapper(dw); Server s = new Server("testing"); s.setDataWrapper(dw.getName()); s.setResourceName("java: 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); schema.setVisible(false); schema.setAnnotation("x"); db.addSchema(schema); String metadataDDL = DDLStringVisitor.getDDLString(db); String expected = "\n" + "\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';" + "\n" + "\n--############ Translators ############\n" + "\n--############ Servers ############\n" + "CREATE SERVER testing TYPE 'orcl' FOREIGN DATA WRAPPER oracle OPTIONS (\"resource-name\" 'java: "\n" + "\n--############ Schemas ############\n" + "CREATE SCHEMA SchemaA SERVER testing OPTIONS (ANNOTATION 'x', VISIBLE 'false');\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"; assertEquals(expected, metadataDDL); }
public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); }
DDLStringVisitor { public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); } }
DDLStringVisitor { public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); } DDLStringVisitor(EnumSet<SchemaObjectType> types, String regexPattern); }
DDLStringVisitor { public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); } DDLStringVisitor(EnumSet<SchemaObjectType> types, String regexPattern); static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern); static String getDDLString(Database database); void visit(Database database); String addTableBody(Table table); @Override String toString(); static String getDomainDDLString(Database database); }
DDLStringVisitor { public static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern) { DDLStringVisitor visitor = new DDLStringVisitor(types, regexPattern); visitor.visit(schema); return visitor.toString(); } DDLStringVisitor(EnumSet<SchemaObjectType> types, String regexPattern); static String getDDLString(Schema schema, EnumSet<SchemaObjectType> types, String regexPattern); static String getDDLString(Database database); void visit(Database database); String addTableBody(Table table); @Override String toString(); static String getDomainDDLString(Database database); static final String GENERATED; }