private boolean execute(final Executor executor) {
    Context context = MetricsContext.start("ShardingStatement-execute");
    postExecutionEvents();
    final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
    final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
    try {
      if (1 == statementExecutorWrappers.size()) {
        return executeInternal(
            executor, statementExecutorWrappers.iterator().next(), isExceptionThrown, dataMap);
      }
      List<Boolean> result =
          executorEngine.execute(
              statementExecutorWrappers,
              new ExecuteUnit<StatementExecutorWrapper, Boolean>() {

                @Override
                public Boolean execute(final StatementExecutorWrapper input) throws Exception {
                  return executeInternal(executor, input, isExceptionThrown, dataMap);
                }
              });
      return (null == result || result.isEmpty()) ? false : result.get(0);
    } finally {
      MetricsContext.stop(context);
    }
  }
  /**
   * 执行SQL查询.
   *
   * @return 结果集列表
   */
  public List<ResultSet> executeQuery() {
    Context context = MetricsContext.start("ShardingStatement-executeQuery");
    postExecutionEvents();
    final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
    final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
    List<ResultSet> result;
    try {
      if (1 == statementExecutorWrappers.size()) {
        return Collections.singletonList(
            executeQueryInternal(
                statementExecutorWrappers.iterator().next(), isExceptionThrown, dataMap));
      }
      result =
          executorEngine.execute(
              statementExecutorWrappers,
              new ExecuteUnit<StatementExecutorWrapper, ResultSet>() {

                @Override
                public ResultSet execute(final StatementExecutorWrapper input) throws Exception {
                  return executeQueryInternal(input, isExceptionThrown, dataMap);
                }
              });
    } finally {
      MetricsContext.stop(context);
    }
    return result;
  }
 private ResultSet executeQueryInternal(
     final StatementExecutorWrapper statementExecutorWrapper,
     final boolean isExceptionThrown,
     final Map<String, Object> dataMap) {
   ResultSet result;
   ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown);
   ExecutorDataMap.setDataMap(dataMap);
   try {
     result =
         statementExecutorWrapper
             .getStatement()
             .executeQuery(statementExecutorWrapper.getSqlExecutionUnit().getSql());
   } catch (final SQLException ex) {
     postExecutionEventsAfterExecution(
         statementExecutorWrapper, EventExecutionType.EXECUTE_FAILURE, Optional.of(ex));
     ExecutorExceptionHandler.handleException(ex);
     return null;
   }
   postExecutionEventsAfterExecution(statementExecutorWrapper);
   return result;
 }
  private int executeUpdate(final Updater updater) {
    Context context = MetricsContext.start("ShardingStatement-executeUpdate");
    postExecutionEvents();
    final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown();
    final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
    try {
      if (1 == statementExecutorWrappers.size()) {
        return executeUpdateInternal(
            updater, statementExecutorWrappers.iterator().next(), isExceptionThrown, dataMap);
      }
      return executorEngine.execute(
          statementExecutorWrappers,
          new ExecuteUnit<StatementExecutorWrapper, Integer>() {

            @Override
            public Integer execute(final StatementExecutorWrapper input) throws Exception {
              return executeUpdateInternal(updater, input, isExceptionThrown, dataMap);
            }
          },
          new MergeUnit<Integer, Integer>() {

            @Override
            public Integer merge(final List<Integer> results) {
              if (null == results) {
                return 0;
              }
              int result = 0;
              for (int each : results) {
                result += each;
              }
              return result;
            }
          });
    } finally {
      MetricsContext.stop(context);
    }
  }