示例#1
0
 /**
  * 获取第一个节点作为路由
  *
  * @param rrs 数据路由集合
  * @param dataNode 数据库所在节点
  * @param stmt 执行语句
  * @return 数据路由集合
  * @author mycat
  */
 public static RouteResultset routeToSingleNode(RouteResultset rrs, String dataNode, String stmt) {
   if (dataNode == null) {
     return rrs;
   }
   RouteResultsetNode[] nodes = new RouteResultsetNode[1];
   nodes[0] = new RouteResultsetNode(dataNode, rrs.getSqlType(), stmt); // rrs.getStatement()
   rrs.setNodes(nodes);
   rrs.setFinishedRoute(true);
   if (rrs.getCanRunInReadDB() != null) {
     nodes[0].setCanRunInReadDB(rrs.getCanRunInReadDB());
   }
   return rrs;
 }
示例#2
0
  public static void routeForTableMeta(
      RouteResultset rrs, SchemaConfig schema, String tableName, String sql) {
    String dataNode = null;
    if (isNoSharding(schema, tableName)) { // 不分库的直接从schema中获取dataNode
      dataNode = schema.getDataNode();
    } else {
      dataNode = getMetaReadDataNode(schema, tableName);
    }

    RouteResultsetNode[] nodes = new RouteResultsetNode[1];
    nodes[0] = new RouteResultsetNode(dataNode, rrs.getSqlType(), sql);
    if (rrs.getCanRunInReadDB() != null) {
      nodes[0].setCanRunInReadDB(rrs.getCanRunInReadDB());
    }
    rrs.setNodes(nodes);
  }
示例#3
0
 public static RouteResultset routeToMultiNode(
     boolean cache, RouteResultset rrs, Collection<String> dataNodes, String stmt) {
   RouteResultsetNode[] nodes = new RouteResultsetNode[dataNodes.size()];
   int i = 0;
   RouteResultsetNode node;
   for (String dataNode : dataNodes) {
     node = new RouteResultsetNode(dataNode, rrs.getSqlType(), stmt);
     if (rrs.getCanRunInReadDB() != null) {
       node.setCanRunInReadDB(rrs.getCanRunInReadDB());
     }
     nodes[i++] = node;
   }
   rrs.setCacheAble(cache);
   rrs.setNodes(nodes);
   return rrs;
 }