@Test public void buildUndoSQL() { String sql = executor.buildUndoSQL().toLowerCase(); Assertions.assertNotNull(sql); Assertions.assertTrue(sql.contains("update")); Assertions.assertTrue(sql.contains("id")); Assertions.assertTrue(sql.contains("age")); }
@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); Field pkField = row.primaryKeys().get(0); List<Field> nonPkFields = row.nonPrimaryKeys(); String updateColumns = nonPkFields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName()) + " = ?") .collect(Collectors.joining(", ")); return String.format(UPDATE_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), updateColumns, keywordChecker.checkAndReplace(pkField.getName())); }
MySQLUndoUpdateExecutor 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); Field pkField = row.primaryKeys().get(0); List<Field> nonPkFields = row.nonPrimaryKeys(); String updateColumns = nonPkFields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName()) + " = ?") .collect(Collectors.joining(", ")); return String.format(UPDATE_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), updateColumns, keywordChecker.checkAndReplace(pkField.getName())); } }
MySQLUndoUpdateExecutor 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); Field pkField = row.primaryKeys().get(0); List<Field> nonPkFields = row.nonPrimaryKeys(); String updateColumns = nonPkFields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName()) + " = ?") .collect(Collectors.joining(", ")); return String.format(UPDATE_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), updateColumns, keywordChecker.checkAndReplace(pkField.getName())); } MySQLUndoUpdateExecutor(SQLUndoLog sqlUndoLog); }
MySQLUndoUpdateExecutor 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); Field pkField = row.primaryKeys().get(0); List<Field> nonPkFields = row.nonPrimaryKeys(); String updateColumns = nonPkFields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName()) + " = ?") .collect(Collectors.joining(", ")); return String.format(UPDATE_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), updateColumns, keywordChecker.checkAndReplace(pkField.getName())); } MySQLUndoUpdateExecutor(SQLUndoLog sqlUndoLog);  }
MySQLUndoUpdateExecutor 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); Field pkField = row.primaryKeys().get(0); List<Field> nonPkFields = row.nonPrimaryKeys(); String updateColumns = nonPkFields.stream() .map(field -> keywordChecker.checkAndReplace(field.getName()) + " = ?") .collect(Collectors.joining(", ")); return String.format(UPDATE_SQL_TEMPLATE, keywordChecker.checkAndReplace(sqlUndoLog.getTableName()), updateColumns, keywordChecker.checkAndReplace(pkField.getName())); } MySQLUndoUpdateExecutor(SQLUndoLog sqlUndoLog);   }