Esempio n. 1
0
  /**
   * 解析每一个rule
   *
   * @param rulesItr
   * @return
   */
  @SuppressWarnings("unchecked")
  private Map<String, DBRule> getRuleList(Iterator rulesItr, LogicTabMatrix aVtabMatrix) {
    Map<String, DBRule> rules = new HashMap<String, DBRule>();

    while (rulesItr.hasNext()) {

      Element ruleEle = (Element) rulesItr.next();
      String id = validAndTrim(ruleEle.attributeValue("id"), "必须指定Rule的id");
      DBRule rule = new DBRule();
      String exp = trim(ruleEle.elementText("expression"));
      rule.setExpression(exp);
      String primaryKey = trim(ruleEle.elementText("primaryKey"));
      rule.setPrimaryKey(primaryKey);
      String primaryKeyExp = trim(ruleEle.elementText("primaryKeyExp"));
      rule.setPrimaryKeyExp(primaryKeyExp);
      String parameters = trim(ruleEle.elementText("parameters"));
      rule.setParameters(parameters);
      String readPoolStr = ruleEle.elementText("readPools");
      String writePoolStr = ruleEle.elementText("writePools");
      if (readPoolStr == null
          || writePoolStr == null
          || readPoolStr.trim().equals("")
          || writePoolStr.trim().equals("")) {
        throw new TDLRunTimeException(
            "readPool和writePool必须同时指名" + "readPool可以和writePool同名,但writePool不能为多个,也不能为虚拟池");
      }
      String[] readPools = readPoolStr.trim().split(",");
      String[] writePools = writePoolStr.trim().split(",");

      rule.setReadPool(readPools);
      rule.setWritePool(writePools);
      Element subTableRuleElement = ruleEle.element("tableRule");
      if (subTableRuleElement != null) {
        TabRule tabRule = getTabRule(subTableRuleElement);

        tabRule.setPrimaryKey(primaryKey);
        rule.setDBSubTabRule(tabRule);
        log.debug("id:" + id + "的DBRule有subTableRule,因此使用subTableRule");
      }
      // add by shenxun 现在的逻辑是直接替换subRuleEle,以后不会再
      // 使用globalRule这个项目了,它只在载入的时候临时起作用
      else {
        TabRule tabRule = aVtabMatrix.getGlobalTableRule();
        if (tabRule != null) {
          tabRule.setPrimaryKey(primaryKey);
        }
        rule.setDBSubTabRule(tabRule);
        log.debug("id:" + id + "的DBRule没有subTableRule,因此使用globalTableRule");
      }
      rules.put(id, rule);
    }
    return rules;
  }