@Test public void buildUndoSQL() { String sql = executor.buildUndoSQL().toLowerCase(); Assertions.assertNotNull(sql); Assertions.assertTrue(sql.contains("insert")); Assertions.assertTrue(sql.contains("id")); }
@Override protected String buildUndoSQL() { KeywordChecker keywordChecker = KeywordCheckerFactory.getKeywordChecker(JdbcConstants.MYSQL); TableRecords beforeImage = sqlUndoLog.getBeforeImage(); List<Row> beforeImageRows = beforeImage.getRows(); if (beforeImageRows == null || beforeImageRows.size() == 0) { throw new ShouldNeverHappenException("Invalid UNDO LOG"); } Row row = beforeImageRows.get(0); List<Field> fields = new ArrayList<>(row.nonPrimaryKeys()); Field pkField = row.primaryKeys().get(0); fields.add(pkField); String insertColumns = fields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName())) .collect(Collectors.joining(", ")); String insertValues = fields.stream().map(field -> "?") .collect(Collectors.joining(", ")); return String.format(INSERT_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), insertColumns, insertValues); }
MySQLUndoDeleteExecutor extends AbstractUndoExecutor { @Override protected String buildUndoSQL() { KeywordChecker keywordChecker = KeywordCheckerFactory.getKeywordChecker(JdbcConstants.MYSQL); TableRecords beforeImage = sqlUndoLog.getBeforeImage(); List<Row> beforeImageRows = beforeImage.getRows(); if (beforeImageRows == null || beforeImageRows.size() == 0) { throw new ShouldNeverHappenException("Invalid UNDO LOG"); } Row row = beforeImageRows.get(0); List<Field> fields = new ArrayList<>(row.nonPrimaryKeys()); Field pkField = row.primaryKeys().get(0); fields.add(pkField); String insertColumns = fields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName())) .collect(Collectors.joining(", ")); String insertValues = fields.stream().map(field -> "?") .collect(Collectors.joining(", ")); return String.format(INSERT_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), insertColumns, insertValues); } }
MySQLUndoDeleteExecutor extends AbstractUndoExecutor { @Override protected String buildUndoSQL() { KeywordChecker keywordChecker = KeywordCheckerFactory.getKeywordChecker(JdbcConstants.MYSQL); TableRecords beforeImage = sqlUndoLog.getBeforeImage(); List<Row> beforeImageRows = beforeImage.getRows(); if (beforeImageRows == null || beforeImageRows.size() == 0) { throw new ShouldNeverHappenException("Invalid UNDO LOG"); } Row row = beforeImageRows.get(0); List<Field> fields = new ArrayList<>(row.nonPrimaryKeys()); Field pkField = row.primaryKeys().get(0); fields.add(pkField); String insertColumns = fields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName())) .collect(Collectors.joining(", ")); String insertValues = fields.stream().map(field -> "?") .collect(Collectors.joining(", ")); return String.format(INSERT_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), insertColumns, insertValues); } MySQLUndoDeleteExecutor(SQLUndoLog sqlUndoLog); }
MySQLUndoDeleteExecutor extends AbstractUndoExecutor { @Override protected String buildUndoSQL() { KeywordChecker keywordChecker = KeywordCheckerFactory.getKeywordChecker(JdbcConstants.MYSQL); TableRecords beforeImage = sqlUndoLog.getBeforeImage(); List<Row> beforeImageRows = beforeImage.getRows(); if (beforeImageRows == null || beforeImageRows.size() == 0) { throw new ShouldNeverHappenException("Invalid UNDO LOG"); } Row row = beforeImageRows.get(0); List<Field> fields = new ArrayList<>(row.nonPrimaryKeys()); Field pkField = row.primaryKeys().get(0); fields.add(pkField); String insertColumns = fields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName())) .collect(Collectors.joining(", ")); String insertValues = fields.stream().map(field -> "?") .collect(Collectors.joining(", ")); return String.format(INSERT_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), insertColumns, insertValues); } MySQLUndoDeleteExecutor(SQLUndoLog sqlUndoLog);  }
MySQLUndoDeleteExecutor extends AbstractUndoExecutor { @Override protected String buildUndoSQL() { KeywordChecker keywordChecker = KeywordCheckerFactory.getKeywordChecker(JdbcConstants.MYSQL); TableRecords beforeImage = sqlUndoLog.getBeforeImage(); List<Row> beforeImageRows = beforeImage.getRows(); if (beforeImageRows == null || beforeImageRows.size() == 0) { throw new ShouldNeverHappenException("Invalid UNDO LOG"); } Row row = beforeImageRows.get(0); List<Field> fields = new ArrayList<>(row.nonPrimaryKeys()); Field pkField = row.primaryKeys().get(0); fields.add(pkField); String insertColumns = fields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName())) .collect(Collectors.joining(", ")); String insertValues = fields.stream().map(field -> "?") .collect(Collectors.joining(", ")); return String.format(INSERT_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), insertColumns, insertValues); } MySQLUndoDeleteExecutor(SQLUndoLog sqlUndoLog);   }