Пример #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;
  }
Пример #2
0
 /**
  * 获取表规则。
  *
  * @param ele
  * @return
  */
 private TabRule getTabRule(Element ele) {
   TabRule tabRule = new TabRule();
   String parameters = trim(ele.elementText("parameters"));
   tabRule.setParameter(parameters);
   String expression = trim(ele.elementText("expression"));
   tabRule.setExpFunction(expression);
   String type = trim(ele.elementText("type"));
   if (type != null && !type.equals("")) {
     tabRule.setTableType(TableRuleType.valueOf(type.toUpperCase()));
   }
   String padding = trim(ele.elementText("padding"));
   tabRule.setPadding(padding);
   String width = trim(ele.elementText("width"));
   tabRule.setWidth(width);
   tabRule.setDefaultTable(trim(ele.elementText("defaultTableRange")));
   String offset = ele.elementText("offset");
   if (offset != null && !offset.trim().equals("")) {
     tabRule.setOffset(Integer.valueOf(offset.trim()).intValue());
   }
   return tabRule;
 }