示例#1
0
  private static RouteResultset routeChildTableInsert(
      SchemaConfig schema,
      TableConfig tc,
      QueryTreeNode ast,
      InsertParseInf parsInf,
      RouteResultset rrs,
      String stmt,
      LayerCachePool cachePool)
      throws SQLNonTransientException {
    if (tc.isChildTable()) {
      String joinKeyVal = parsInf.columnPairMap.get(tc.getJoinKey());
      if (joinKeyVal == null) {
        String inf = "joinKey not provided :" + tc.getJoinKey() + "," + stmt;
        LOGGER.warn(inf);
        throw new SQLNonTransientException(inf);
      }
      // try to route by ER parent partion key
      RouteResultset theRrs = RouterUtil.routeByERParentKey(stmt, rrs, tc, joinKeyVal);
      if (theRrs != null) {
        return theRrs;
      }

      // route by sql query root parent's datanode
      String findRootTBSql =
          RouterUtil.buildFindRootTbSql(
              tc.getLocateRTableKeySql(),
              joinKeyVal); // tc.getLocateRTableKeySql().toLowerCase() + " = " + joinKeyVal;
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("find root parent's node sql " + findRootTBSql);
      }
      FetchStoreNodeOfChildTableHandler fetchHandler = new FetchStoreNodeOfChildTableHandler();
      String dn =
          fetchHandler.execute(schema.getName(), findRootTBSql, tc.getRootParent().getDataNodes());
      if (dn == null) {
        throw new SQLNonTransientException(
            "can't find (root) parent sharding node for sql:" + stmt);
      }
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("found partion node for child table to insert " + dn + " sql :" + stmt);
      }
      return RouterUtil.routeToSingleNode(rrs, dn, stmt);
    }
    return null;
  }