@Test public void testForeignTable() throws Exception { String ddl = "CREATE FOREIGN TABLE G1 (\n" + " e1 integer,\n" + " e2 string(10),\n" + " e3 date NOT NULL DEFAULT current_date() OPTIONS (\"teiid_rel:default_handling\" 'expression'),\n" + " e4 bigdecimal(12,3),\n" + " e5 integer AUTO_INCREMENT OPTIONS (UUID 'uuid', NAMEINSOURCE 'nis', SELECTABLE FALSE),\n" + " e6 string DEFAULT 'hello',\n" + " PRIMARY KEY(e1),\n" + " UNIQUE(e2),\n" + " UNIQUE(e3),\n" + " INDEX(e5),\n" + " INDEX(e6)\n" + ") OPTIONS (ANNOTATION 'Test Table', CARDINALITY '12', FOO 'BAR', UPDATABLE 'true', UUID 'uuid2');"; MetadataFactory mf = new MetadataFactory("test", 1, "model", TestDDLParser.getDataTypes(), new Properties(), null); Table table = mf.addTable("G1"); table.setVirtual(false); mf.addColumn("e1","integer", table); Column e2 = mf.addColumn("e2","varchar", table); e2.setLength(10); Column e3 = mf.addColumn("e3","date", table); e3.setNullType(NullType.No_Nulls); SQLParserUtil.setDefault(e3, new Function("current_date", new Expression[0])); Column e4 = mf.addColumn("e4","decimal", table); e4.setPrecision(12); e4.setScale(3); Column e5 = mf.addColumn("e5","integer", table); e5.setAutoIncremented(true); e5.setUUID("uuid"); e5.setNameInSource("nis"); e5.setSelectable(false); Column e6 = mf.addColumn("e6","varchar", table); e6.setDefaultValue("hello"); mf.addPrimaryKey("PK", Arrays.asList("e1"), table); mf.addIndex("UNIQUE0", false, Arrays.asList("e2"), table); mf.addIndex("UNIQUE1", false, Arrays.asList("e3"), table); mf.addIndex("INDEX0", true, Arrays.asList("e5"), table); mf.addIndex("INDEX1", true, Arrays.asList("e6"), table); Map<String, String> options = new HashMap<String, String>(); options.put("CARDINALITY", "12"); options.put("UUID", "uuid2"); options.put("UPDATABLE", "true"); options.put("FOO", "BAR"); options.put("ANNOTATION", "Test Table"); table.setProperties(options); String metadataDDL = DDLStringVisitor.getDDLString(mf.getSchema(), null, null); assertEquals(ddl, 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; }