예제 #1
0
  @Override
  public RouteResultset routeToMultiNode(
      SchemaConfig schema,
      boolean isSelect,
      boolean cache,
      QueryTreeNode ast,
      RouteResultset rrs,
      Collection<String> dataNodes,
      String stmt)
      throws SQLSyntaxErrorException {
    if (isSelect) {
      String sql = SelectSQLAnalyser.analyseMergeInf(rrs, ast, true, schema.getDefaultMaxLimit());
      if (sql != null) {
        stmt = sql;
      }
    }
    RouteResultsetNode[] nodes = new RouteResultsetNode[dataNodes.size()];
    int i = 0;
    for (String dataNode : dataNodes) {

      nodes[i++] = new RouteResultsetNode(dataNode, rrs.getSqlType(), stmt);
    }
    rrs.setCacheAble(cache);
    rrs.setNodes(nodes);
    return rrs;
  }
예제 #2
0
 private static String addSQLLmit(
     SchemaConfig schema, RouteResultset rrs, QueryTreeNode ast, String sql)
     throws SQLSyntaxErrorException {
   if (!rrs.hasPrimaryKeyToCache()
       && schema.getDefaultMaxLimit() != -1
       && ast instanceof CursorNode
       && ((CursorNode) ast).getFetchFirstClause() == null) {
     String newstmt =
         SelectSQLAnalyser.addLimitCondtionForSelectSQL(
             rrs, (CursorNode) ast, schema.getDefaultMaxLimit());
     if (newstmt != null) {
       return newstmt;
     }
   }
   return sql;
 }
예제 #3
0
 private RouteResultset routeSelect(
     SchemaConfig schema,
     QueryTreeNode ast,
     RouteResultset rrs,
     String stmt,
     LayerCachePool cachePool)
     throws SQLNonTransientException {
   ResultSetNode rsNode = ((CursorNode) ast).getResultSetNode();
   if (rsNode instanceof SelectNode) {
     if (((SelectNode) rsNode).getFromList().isEmpty()) {
       // if it is a sql about system info, such as select charset etc.
       return RouterUtil.routeToSingleNode(rrs, schema.getRandomDataNode(), stmt);
     }
   }
   // standard SELECT operation
   SelectParseInf parsInf = new SelectParseInf();
   parsInf.ctx = new ShardingParseInfo();
   SelectSQLAnalyser.analyse(parsInf, ast);
   return tryRouteForTables(ast, true, rrs, schema, parsInf.ctx, stmt, cachePool);
 }