use of io.seata.rm.datasource.undo.AbstractUndoExecutor in project seata by seata.
the class MySQLUndoDeleteExecutor method buildUndoSQL.
/**
* Undo delete.
*
* Notice: PK is at last one.
* @see AbstractUndoExecutor#undoPrepare
*
* @return sql
*/
@Override
protected String buildUndoSQL() {
TableRecords beforeImage = sqlUndoLog.getBeforeImage();
List<Row> beforeImageRows = beforeImage.getRows();
if (CollectionUtils.isEmpty(beforeImageRows)) {
throw new ShouldNeverHappenException("Invalid UNDO LOG");
}
Row row = beforeImageRows.get(0);
List<Field> fields = new ArrayList<>(row.nonPrimaryKeys());
fields.addAll(getOrderedPkList(beforeImage, row, JdbcConstants.MYSQL));
// delete sql undo log before image all field come from table meta, need add escape.
// see BaseTransactionalExecutor#buildTableRecords
String insertColumns = fields.stream().map(field -> ColumnUtils.addEscape(field.getName(), JdbcConstants.MYSQL)).collect(Collectors.joining(", "));
String insertValues = fields.stream().map(field -> "?").collect(Collectors.joining(", "));
return String.format(INSERT_SQL_TEMPLATE, sqlUndoLog.getTableName(), insertColumns, insertValues);
}
Aggregations