test_class.file: mybatis-plus-extension/src/test/java/com/baomidou/mybatisplus/extension/plugins/inner/DynamicTableNameInnerInterceptorTest.java
test_class.identifier: DynamicTableNameInnerInterceptorTest
test_case.body: @Test
      @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
      void doIt() {
          DynamicTableNameInnerInterceptor interceptor = new DynamicTableNameInnerInterceptor();
          interceptor.setTableNameHandlerMap(newTableNameHandlerMap());
          // 表名相互包含
          @Language("SQL")
          String origin = "SELECT * FROM t_user, t_user_role", replaced = "SELECT * FROM t_user_r, t_user_role";
          assertEquals(replaced, interceptor.changeTable(origin));
          // 表名在末尾
          origin = "SELECT * FROM t_user";
          replaced = "SELECT * FROM t_user_r";
          assertEquals(replaced, interceptor.changeTable(origin));
          // 表名前后有注释
          origin = "SELECT * FROM /**/t_user/* t_user */";
          replaced = "SELECT * FROM /**/t_user_r/* t_user */";
          assertEquals(replaced, interceptor.changeTable(origin));
          // 值中带有表名
          origin = "SELECT * FROM t_user WHERE name = 't_user'";
          replaced = "SELECT * FROM t_user_r WHERE name = 't_user'";
          assertEquals(replaced, interceptor.changeTable(origin));
          // 别名被声明要替换
          origin = "SELECT t_user.* FROM t_user_real t_user";
          assertEquals(origin, interceptor.changeTable(origin));
      }
test_case.class_method_signature: DynamicTableNameInnerInterceptorTest.doIt()
test_case.full_signature: @Test @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"}) void doIt()
test_case.identifier: doIt
test_case.invocations: setTableNameHandlerMap newTableNameHandlerMap assertEquals changeTable assertEquals changeTable assertEquals changeTable assertEquals changeTable assertEquals changeTable
test_case.modifiers: @Test @SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
test_case.parameters: ()
test_case.return: void
test_case.signature: void doIt()
focal_class.declarator: tableNameHandlerMap
focal_class.modifier: private
focal_class.original_string: private Map<String, TableNameHandler> tableNameHandlerMap;
focal_class.type: Map<String, TableNameHandler>
focal_class.var_name: tableNameHandlerMap
focal_class.file: mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/DynamicTableNameInnerInterceptor.java
focal_class.identifier: DynamicTableNameInnerInterceptor
focal_class.interfaces: implements InnerInterceptor
focal_class.class_method_signature: DynamicTableNameInnerInterceptor.beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql)
focal_class.full_signature: @Override public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql)
focal_class.identifier: beforeQuery
focal_class.modifiers: @Override public
focal_class.parameters: (Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql)
focal_class.return: void
focal_class.signature: void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql)
focal_class.class_method_signature: DynamicTableNameInnerInterceptor.beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout)
focal_class.full_signature: @Override public void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout)
focal_class.identifier: beforePrepare
focal_class.modifiers: @Override public
focal_class.parameters: (StatementHandler sh, Connection connection, Integer transactionTimeout)
focal_class.return: void
focal_class.signature: void beforePrepare(StatementHandler sh, Connection connection, Integer transactionTimeout)
focal_class.class_method_signature: DynamicTableNameInnerInterceptor.changeTable(String sql)
focal_class.full_signature: protected String changeTable(String sql)
focal_class.identifier: changeTable
focal_class.modifiers: protected
focal_class.parameters: (String sql)
focal_class.return: String
focal_class.signature: String changeTable(String sql)
focal_method.body: protected String changeTable(String sql) {
          TableNameParser parser = new TableNameParser(sql);
          List<TableNameParser.SqlToken> names = new ArrayList<>();
          parser.accept(names::add);
          StringBuilder builder = new StringBuilder();
          int last = 0;
          for (TableNameParser.SqlToken name : names) {
              int start = name.getStart();
              if (start != last) {
                  builder.append(sql, last, start);
                  String value = name.getValue();
                  TableNameHandler handler = tableNameHandlerMap.get(value);
                  if (handler != null) {
                      builder.append(handler.dynamicTableName(sql, value));
                  } else {
                      builder.append(value);
                  }
              }
              last = name.getEnd();
          }
          if (last != sql.length()) {
              builder.append(sql.substring(last));
          }
          return builder.toString();
      }
focal_method.class_method_signature: DynamicTableNameInnerInterceptor.changeTable(String sql)
focal_method.full_signature: protected String changeTable(String sql)
focal_method.identifier: changeTable
focal_method.invocations: accept getStart append getValue get append dynamicTableName append getEnd length append substring toString
focal_method.modifiers: protected
focal_method.parameters: (String sql)
focal_method.return: String
focal_method.signature: String changeTable(String sql)