本文共 3528 字,大约阅读时间需要 11 分钟。
这篇文章的目的是讲解RM Executor模块当中一些通用的方法,这些方法在各个Executor的父类当中实现的,各个子类Executor模块都会复用,因此抽取出来统一的进行讲解。
个人是认为抽取通用的内容放在一篇文章讲解完后可以针对每类Executor讲解特有的功能,这样能够有更好的理解。这篇文章讲解Executor的实现类DeleteExecutor。
public class DeleteExecutorextends AbstractDMLBaseExecutor { public DeleteExecutor(StatementProxy statementProxy, StatementCallback statementCallback, SQLRecognizer sqlRecognizer) { super(statementProxy, statementCallback, sqlRecognizer); } @Override protected TableRecords beforeImage() throws SQLException { SQLDeleteRecognizer visitor = (SQLDeleteRecognizer) sqlRecognizer; // 获取表的所有的列 TableMeta tmeta = getTableMeta(visitor.getTableName()); List columns = new ArrayList<>(); for (String column : tmeta.getAllColumns().keySet()) { columns.add(column); } // 拼接SELECT的SQL语句 StringBuffer selectSQLAppender = new StringBuffer("SELECT "); for (int i = 0; i < columns.size(); i++) { selectSQLAppender.append(getColumnNameInSQL(columns.get(i))); if (i < (columns.size() - 1)) { selectSQLAppender.append(", "); } } String whereCondition = null; // 解析并获取where条件 ArrayList
说明:
public class DeleteExecutorextends AbstractDMLBaseExecutor { public DeleteExecutor(StatementProxy statementProxy, StatementCallback statementCallback, SQLRecognizer sqlRecognizer) { super(statementProxy, statementCallback, sqlRecognizer); } @Override protected TableRecords afterImage(TableRecords beforeImage) throws SQLException { return TableRecords.empty(getTableMeta()); }}
说明:
DeleteExecutor生成执行前后镜像的过程分析完后,会接着分析UpdateExecutor。
转载地址:http://gutla.baihongyu.com/