public static void compareSchema(DBSchema schema1, DBSchema schema2) { for (DBTable t2 : schema2.getTables()) { DBTable t1 = schema1.getTable(t2.getTableName()); if (t1 == null) { SQL sql = new SQLCreateTable(t2); System.out.println(sql.getDDL()); } else { compareTable(t1, t2); } } for (DBTable t1 : schema1.getTables()) { if (schema2.getTable(t1.getTableName()) == null) { SQL sql = new SQLDropTable(t1); System.out.println(sql.getDDL()); } } }
public static void compareData(DBSchema schema1, DBSchema schema2, Connection c1, Connection c2) throws SQLException { for (DBTable t2 : schema2.getTables()) { List<Map<String, Object>> data2 = read(t2, c2); DBTable t1 = schema1.getTable(t2.getTableName()); if (t1 == null) { if (!data2.isEmpty()) { System.out.println(insertEntireTable(t2, data2)); } } else { List<Map<String, Object>> data1 = read(t1, c1); String s = compareTableData(t2, data1, data2); if (!StringUtils.isEmpty(s)) { System.out.println(compareTableData(t2, data1, data2)); } } } }
public static void getSnapShotDML(Connection conn, String schem) throws SQLException { DBSchema schema = new DBSchema(); schema.importSchema(conn, schem); compareData(new DBSchema(), schema, null, conn); }