Esempio n. 1
0
 private void clearHandlesResources() {
   SingleNodeHandler singleHander = singleNodeHandler;
   if (singleHander != null) {
     singleHander.clearResources();
     singleNodeHandler = null;
   }
   MultiNodeQueryHandler multiHandler = multiNodeHandler;
   if (multiHandler != null) {
     multiHandler.clearResources();
     multiNodeHandler = null;
   }
 }
Esempio n. 2
0
  @Override
  public void execute(RouteResultset rrs, int type) {
    // clear prev execute resources
    clearHandlesResources();
    if (LOGGER.isDebugEnabled()) {
      StringBuilder s = new StringBuilder();
      LOGGER.debug(s.append(this.conInf.toString()).append(rrs).toString() + " rrs ");
    }

    // 检查路由结果是否为空
    RouteResultsetNode[] nodes = rrs.getNodes();
    if (nodes == null
        || nodes.length == 0
        || nodes[0].getName() == null
        || nodes[0].getName().equals("")) {
      writeErrMessage(
          ErrorCode.ER_NO_DB_ERROR,
          "No dataNode found ,please check tables defined in schema:" + this.conInf.getSchema());
      return;
    }

    if (nodes.length == 1) {
      singleNodeHandler = new SingleNodeHandler(rrs, this);
      try {
        singleNodeHandler.execute();
      } catch (Exception e) {
        LOGGER.warn(new StringBuilder().append(this.conInf.toString()).append(rrs), e);
        writeErrMessage(ErrorCode.ERR_HANDLE_DATA, e.toString());
      }
    } else {
      boolean autocommit = this.autocommit;
      DataMergeService dataMergeSvr = null;
      if (ServerParse.SELECT == type && rrs.needMerge()) {
        dataMergeSvr = new DataMergeService(rrs);
      }
      multiNodeHandler = new MultiNodeQueryHandler(rrs, autocommit, this, dataMergeSvr);

      try {
        multiNodeHandler.execute();
      } catch (Exception e) {
        LOGGER.warn(new StringBuilder().append(this.conInf.toString()).append(rrs), e);
        writeErrMessage(ErrorCode.ERR_HANDLE_DATA, e.toString());
      }
    }
  }