Esempio n. 1
0
    private void evaluationJoinChain(TableFilter filter) {
      TableMate table1 = (TableMate) filter.getTable();
      Column[] columns1 = table1.getRuleColumns();
      if (columns1 == null) {
        throw new IllegalArgumentException("not sharding TableFilter");
      }
      ArrayList<IndexCondition> conditions = getIndexConditions(filter);
      List<IndexCondition> masks = New.arrayList(10);
      List<Column> compareColumns = New.arrayList(10);
      for (Column column : columns1) {
        for (IndexCondition condition : conditions) {
          Column compareColumn = condition.getCompareColumn();
          if ((condition.getMask(conditions) & IndexCondition.EQUALITY)
              != IndexCondition.EQUALITY) {
            continue;
          }
          if (condition.getColumn() != column || compareColumn == null) {
            continue;
          }
          masks.add(condition);
          compareColumns.add(compareColumn);
        }
      }

      Set<Table> tables = New.hashSet();
      for (IndexCondition mask : masks) {
        Column compareColumn = mask.getCompareColumn();
        Table table = compareColumn.getTable();
        if (!(table instanceof TableMate)) {
          continue;
        }
        TableMate tableMate = (TableMate) table;
        Column[] rc = tableMate.getRuleColumns();
        if (compareColumns.containsAll(Arrays.asList(rc))) {
          tables.add(table);
        }
      }
      if (tables.isEmpty()) {
        return;
      }
      for (Table table : tables) {
        for (TableFilter tf : filters) {
          if (tf.getTable() == table && !joinTableChain.contains(tf)) {
            joinTableChain.add(tf);
            evaluationJoinChain(tf);
          }
        }
      }
    }
Esempio n. 2
0
 private boolean isGropTableFilter(TableFilter filter) {
   TableMate table1 = (TableMate) filter.getTable();
   for (TableFilter item : filters) {
     if (item == filter || isNestedJoinTable(item)) {
       continue;
     }
     TableMate table2 = (TableMate) item.getTable();
     TableRule rule1 = table1.getTableRule();
     TableRule rule2 = table2.getTableRule();
     if (!rule1.isNodeComparable(rule2)) {
       return false;
     }
   }
   return true;
 }
Esempio n. 3
0
 private boolean isDirectLookup() {
   for (TableFilter tf : filters) {
     if (!tf.isFromTableMate() && !isNestedJoinTable(tf)) {
       return false;
     }
   }
   if (filters.size() == 1) {
     return true;
   } else {
     List<TableFilter> shardingTableFilter = New.arrayList();
     for (TableFilter tf : filters) {
       if (isNestedJoinTable(tf)) {
         continue;
       }
       if (!isGropTableFilter(tf)) {
         return false;
       }
       TableMate table = (TableMate) tf.getTable();
       if (table.getRuleColumns() != null) {
         shardingTableFilter.add(tf);
       }
     }
     if (shardingTableFilter.size() < 2) {
       return true;
     }
     this.joinTableChain = New.hashSet();
     evaluationJoinChain(shardingTableFilter.iterator().next());
     return joinTableChain.containsAll(shardingTableFilter);
   }
 }
Esempio n. 4
0
 private boolean isNestedJoinTable(TableFilter f) {
   return f.getTable() instanceof RangeTable
       && StringUtils.startsWith(f.getTableAlias(), Constants.PREFIX_JOIN);
 }