@Test void result1Test() { Result result1 = DataGenerator.makeResult1(); InsertionBuilder insertionBuilder = new InsertionBuilder(new MySQLOptions()); List<String> insertionQueries = insertionBuilder.buildQueries(result1.getPaths().get(0)); List<String> expectedQueries = Arrays.asList( "INSERT INTO `table1` (`column1_1`, `column1_2`, `column1_3`) VALUES (1, 0.5, 'The first row of table 1.'), (2, 1.5, 'The second row.');" ); assertThat(insertionQueries).isEqualTo(expectedQueries); }
@Override public List<String> buildQueries(Path path) { return path.getFixture().getTables().stream().map(table -> { StringBuilder insertBuilder = new StringBuilder(); insertBuilder.append("INSERT INTO "); insertBuilder.append(getVendorOptions().escapeIdentifier(table.getSchema().getName())); insertBuilder.append(" ("); List<String> escapedColumnNames = table.getSchema().getColumns().stream() .map(c -> getVendorOptions().escapeIdentifier(c.getName())) .collect(Collectors.toList()); insertBuilder.append(String.join(", ", escapedColumnNames)); insertBuilder.append(") VALUES "); List<String> valueStrings = table.getRows().stream().map(row -> { StringBuilder valueBuilder = new StringBuilder(); valueBuilder.append("("); List<String> values = row.getTableSchema().getColumns().stream() .map(c -> getEscapedValue(c, row)) .collect(Collectors.toList()); valueBuilder.append(String.join(", ", values)); valueBuilder.append(")"); return valueBuilder.toString(); }).collect(Collectors.toList()); insertBuilder.append(String.join(", ", valueStrings)); insertBuilder.append(";"); return insertBuilder.toString(); }).collect(Collectors.toList()); }
InsertionBuilder extends QueryBuilder { @Override public List<String> buildQueries(Path path) { return path.getFixture().getTables().stream().map(table -> { StringBuilder insertBuilder = new StringBuilder(); insertBuilder.append("INSERT INTO "); insertBuilder.append(getVendorOptions().escapeIdentifier(table.getSchema().getName())); insertBuilder.append(" ("); List<String> escapedColumnNames = table.getSchema().getColumns().stream() .map(c -> getVendorOptions().escapeIdentifier(c.getName())) .collect(Collectors.toList()); insertBuilder.append(String.join(", ", escapedColumnNames)); insertBuilder.append(") VALUES "); List<String> valueStrings = table.getRows().stream().map(row -> { StringBuilder valueBuilder = new StringBuilder(); valueBuilder.append("("); List<String> values = row.getTableSchema().getColumns().stream() .map(c -> getEscapedValue(c, row)) .collect(Collectors.toList()); valueBuilder.append(String.join(", ", values)); valueBuilder.append(")"); return valueBuilder.toString(); }).collect(Collectors.toList()); insertBuilder.append(String.join(", ", valueStrings)); insertBuilder.append(";"); return insertBuilder.toString(); }).collect(Collectors.toList()); } }
InsertionBuilder extends QueryBuilder { @Override public List<String> buildQueries(Path path) { return path.getFixture().getTables().stream().map(table -> { StringBuilder insertBuilder = new StringBuilder(); insertBuilder.append("INSERT INTO "); insertBuilder.append(getVendorOptions().escapeIdentifier(table.getSchema().getName())); insertBuilder.append(" ("); List<String> escapedColumnNames = table.getSchema().getColumns().stream() .map(c -> getVendorOptions().escapeIdentifier(c.getName())) .collect(Collectors.toList()); insertBuilder.append(String.join(", ", escapedColumnNames)); insertBuilder.append(") VALUES "); List<String> valueStrings = table.getRows().stream().map(row -> { StringBuilder valueBuilder = new StringBuilder(); valueBuilder.append("("); List<String> values = row.getTableSchema().getColumns().stream() .map(c -> getEscapedValue(c, row)) .collect(Collectors.toList()); valueBuilder.append(String.join(", ", values)); valueBuilder.append(")"); return valueBuilder.toString(); }).collect(Collectors.toList()); insertBuilder.append(String.join(", ", valueStrings)); insertBuilder.append(";"); return insertBuilder.toString(); }).collect(Collectors.toList()); } InsertionBuilder(VendorOptions vendorOptions); }
InsertionBuilder extends QueryBuilder { @Override public List<String> buildQueries(Path path) { return path.getFixture().getTables().stream().map(table -> { StringBuilder insertBuilder = new StringBuilder(); insertBuilder.append("INSERT INTO "); insertBuilder.append(getVendorOptions().escapeIdentifier(table.getSchema().getName())); insertBuilder.append(" ("); List<String> escapedColumnNames = table.getSchema().getColumns().stream() .map(c -> getVendorOptions().escapeIdentifier(c.getName())) .collect(Collectors.toList()); insertBuilder.append(String.join(", ", escapedColumnNames)); insertBuilder.append(") VALUES "); List<String> valueStrings = table.getRows().stream().map(row -> { StringBuilder valueBuilder = new StringBuilder(); valueBuilder.append("("); List<String> values = row.getTableSchema().getColumns().stream() .map(c -> getEscapedValue(c, row)) .collect(Collectors.toList()); valueBuilder.append(String.join(", ", values)); valueBuilder.append(")"); return valueBuilder.toString(); }).collect(Collectors.toList()); insertBuilder.append(String.join(", ", valueStrings)); insertBuilder.append(";"); return insertBuilder.toString(); }).collect(Collectors.toList()); } InsertionBuilder(VendorOptions vendorOptions); @Override List<String> buildQueries(Path path); }
InsertionBuilder extends QueryBuilder { @Override public List<String> buildQueries(Path path) { return path.getFixture().getTables().stream().map(table -> { StringBuilder insertBuilder = new StringBuilder(); insertBuilder.append("INSERT INTO "); insertBuilder.append(getVendorOptions().escapeIdentifier(table.getSchema().getName())); insertBuilder.append(" ("); List<String> escapedColumnNames = table.getSchema().getColumns().stream() .map(c -> getVendorOptions().escapeIdentifier(c.getName())) .collect(Collectors.toList()); insertBuilder.append(String.join(", ", escapedColumnNames)); insertBuilder.append(") VALUES "); List<String> valueStrings = table.getRows().stream().map(row -> { StringBuilder valueBuilder = new StringBuilder(); valueBuilder.append("("); List<String> values = row.getTableSchema().getColumns().stream() .map(c -> getEscapedValue(c, row)) .collect(Collectors.toList()); valueBuilder.append(String.join(", ", values)); valueBuilder.append(")"); return valueBuilder.toString(); }).collect(Collectors.toList()); insertBuilder.append(String.join(", ", valueStrings)); insertBuilder.append(";"); return insertBuilder.toString(); }).collect(Collectors.toList()); } InsertionBuilder(VendorOptions vendorOptions); @Override List<String> buildQueries(Path path);  }