test_class.declarator: routeService = new RouteService()
test_class.modifier: private
test_class.original_string: private RouteService routeService = new RouteService();
test_class.type: RouteService
test_class.var_name: routeService
test_class.file: baymax-core/src/test/java/com/tongbanjie/baymax/router/RouteServiceTest.java
test_class.identifier: RouteServiceTest
test_class.interfaces: implements SelectTestSql
test_case.body: @Test
      public void testRoute() throws Exception {
          List<String> tables = new ArrayList<String>();
          List<CalculateUnit > units = new ArrayList<CalculateUnit>();
  
          tables.add("table1");
  
          CalculateUnit unit1 = new CalculateUnit();
          unit1.addCondition(ConditionUnit.buildConditionUnit("table1", "a", new String[]{"2"}, ConditionUnitOperator.EQUAL));
  
          units.add(unit1);
  
          ExecutePlan plan =routeService.route(tables, units, "select", SqlType.SELECT);
  
          System.out.println(plan);
      }
test_case.class_method_signature: RouteServiceTest.testRoute()
test_case.full_signature: @Test public void testRoute()
test_case.identifier: testRoute
test_case.invocations: add addCondition buildConditionUnit add route println
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testRoute()
focal_class.declarator: logger = LoggerFactory.getLogger(RouteService.class)
focal_class.modifier: private final
focal_class.original_string: private final Logger logger = LoggerFactory.getLogger(RouteService.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.file: baymax-core/src/main/java/com/tongbanjie/baymax/router/RouteService.java
focal_class.identifier: RouteService
focal_class.interfaces: implements IRouteService
focal_class.class_method_signature: RouteService.doRoute(String sql, Map<Integer, ParameterCommand> parameterCommand)
focal_class.full_signature: public ExecutePlan doRoute(String sql, Map<Integer, ParameterCommand> parameterCommand)
focal_class.identifier: doRoute
focal_class.modifiers: public
focal_class.parameters: (String sql, Map<Integer, ParameterCommand> parameterCommand)
focal_class.return: ExecutePlan
focal_class.signature: ExecutePlan doRoute(String sql, Map<Integer, ParameterCommand> parameterCommand)
focal_class.class_method_signature: RouteService.route(List<String> tables, List<CalculateUnit> units, String sql, SqlType sqlType)
focal_class.full_signature: public ExecutePlan route(List<String> tables, List<CalculateUnit> units, String sql, SqlType sqlType)
focal_class.identifier: route
focal_class.modifiers: public
focal_class.parameters: (List<String> tables, List<CalculateUnit> units, String sql, SqlType sqlType)
focal_class.return: ExecutePlan
focal_class.signature: ExecutePlan route(List<String> tables, List<CalculateUnit> units, String sql, SqlType sqlType)
focal_class.class_method_signature: RouteService.buildExecutePlanTypeNo(String sql, String tableName, SqlType sqlType)
focal_class.full_signature: private ExecutePlan buildExecutePlanTypeNo(String sql, String tableName, SqlType sqlType)
focal_class.identifier: buildExecutePlanTypeNo
focal_class.modifiers: private
focal_class.parameters: (String sql, String tableName, SqlType sqlType)
focal_class.return: ExecutePlan
focal_class.signature: ExecutePlan buildExecutePlanTypeNo(String sql, String tableName, SqlType sqlType)
focal_class.class_method_signature: RouteService.buildExecutePlanTypeAll(PartitionTable partitionTable, SqlType sqlType)
focal_class.full_signature: private ExecutePlan buildExecutePlanTypeAll(PartitionTable partitionTable, SqlType sqlType)
focal_class.identifier: buildExecutePlanTypeAll
focal_class.modifiers: private
focal_class.parameters: (PartitionTable partitionTable, SqlType sqlType)
focal_class.return: ExecutePlan
focal_class.signature: ExecutePlan buildExecutePlanTypeAll(PartitionTable partitionTable, SqlType sqlType)
focal_class.class_method_signature: RouteService.buildExecutePlanTypePartition(PartitionTable partitionTable, SqlType sqlType, Set<TargetTableEntity> nodeSet)
focal_class.full_signature: private ExecutePlan buildExecutePlanTypePartition(PartitionTable partitionTable, SqlType sqlType, Set<TargetTableEntity> nodeSet)
focal_class.identifier: buildExecutePlanTypePartition
focal_class.modifiers: private
focal_class.parameters: (PartitionTable partitionTable, SqlType sqlType, Set<TargetTableEntity> nodeSet)
focal_class.return: ExecutePlan
focal_class.signature: ExecutePlan buildExecutePlanTypePartition(PartitionTable partitionTable, SqlType sqlType, Set<TargetTableEntity> nodeSet)
focal_class.class_method_signature: RouteService.buildParameters(Map<Integer, ParameterCommand> commonds)
focal_class.full_signature: public List<Object> buildParameters(Map<Integer, ParameterCommand> commonds)
focal_class.identifier: buildParameters
focal_class.modifiers: public
focal_class.parameters: (Map<Integer, ParameterCommand> commonds)
focal_class.return: List<Object>
focal_class.signature: List<Object> buildParameters(Map<Integer, ParameterCommand> commonds)
focal_method.body: public ExecutePlan route(List<String> tables, List<CalculateUnit> units, String sql, SqlType sqlType){
          if (logger.isDebugEnabled()){
              logger.debug("计算单元:" + PrintUtil.printCalculates(units));
          }
  
          // 判断是否解析到表名
          if (tables == null || tables.size() == 0){
              return buildExecutePlanTypeNo(sql, null, sqlType);
          }
          // 查找逻辑表对应的分区规则
          PartitionTable partitionTable = null;
          for (String tableName : tables){
              if (BaymaxContext.isPartitionTable(tableName)){
                  if (partitionTable != null){
                      throw new BayMaxException("sql中包含了两个分区表");
                  }else {
                      partitionTable = BaymaxContext.getPartitionTable(tableName);
                  }
              }
          }
          // 没有规则 无需路由
          if (partitionTable == null){
              return buildExecutePlanTypeNo(sql, null, sqlType);
          }
  
          // 没有计算单元 全表扫描
          if (units == null || units.size() == 0){
              return buildExecutePlanTypeAll(partitionTable, sqlType);
          }
  
          // 路由单元计算-合并
          Set<TargetTableEntity> nodeSet = new LinkedHashSet<TargetTableEntity>();
          for (CalculateUnit unit : units) {
              List<TargetTableEntity> temp = partitionTable.execute(unit);
              if (temp == null || temp.size() == 0){
                  // 这个单元没有路由结果 需要全表扫描
                  return buildExecutePlanTypeAll(partitionTable, sqlType);
              }else {
                  nodeSet.addAll(temp);
              }
          }
  
          if (nodeSet.size() == 0){
              return buildExecutePlanTypeNo(sql, partitionTable.getLogicTableName(), sqlType);
          }
  
          return buildExecutePlanTypePartition(partitionTable, sqlType, nodeSet);
      }
focal_method.class_method_signature: RouteService.route(List<String> tables, List<CalculateUnit> units, String sql, SqlType sqlType)
focal_method.full_signature: public ExecutePlan route(List<String> tables, List<CalculateUnit> units, String sql, SqlType sqlType)
focal_method.identifier: route
focal_method.invocations: isDebugEnabled debug culates(units)) size buildExecutePlanTypeNo isPartitionTable getPartitionTable buildExecutePlanTypeNo size buildExecutePlanTypeAll execute size buildExecutePlanTypeAll addAll size buildExecutePlanTypeNo getLogicTableName buildExecutePlanTypePartition
focal_method.modifiers: public
focal_method.parameters: (List<String> tables, List<CalculateUnit> units, String sql, SqlType sqlType)
focal_method.return: ExecutePlan
focal_method.signature: ExecutePlan route(List<String> tables, List<CalculateUnit> units, String sql, SqlType sqlType)