/** * 初始化:读取配置信息 * * @return boolean */ public boolean init() { // 页面大小 this.pageSize = JdomUtils.getAttributeIntValue(eleConfig, "pageSize", DEFAULT_PAGE_SIZE); // 从配置文件中读取代理类名并实例化代理类 this.agentClassName = JdomUtils.getAttributeValue(eleConfig, "agentClass", ""); if (agentClassName.length() > 0) { try { this.agentClass = (IValueFetch) ClassUtils.newInstance(agentClassName); } catch (RuntimeException ex) { QueryManager.logError(logger, this.query, "结果获取代理类(" + agentClassName + ")实例化失败"); } } if (agentClass == null) agentClass = this; // 读取是否首次显示 this.firstShow = JdomUtils.getAttributeBooleanValue(eleConfig, "firstShow", true); // 读取Sql配置信息 Element eleSql = eleConfig.getChild("sql"); if (eleSql == null) { QueryManager.logError(logger, query, "没有配置valuefetch中的sql"); return false; } // 读取Cache配置 Element eleCache = eleConfig.getChild("cache"); if (eleCache != null) { this.needCache = true; this.needRadom = JdomUtils.getAttributeBooleanValue(eleCache, "radom", false); this.cacheLimit = JdomUtils.getAttributeIntValue(eleCache, "radom", DEFAULT_CACHE_LIMIT); } // 读取Sql配置 this.sqlSelect = StringUtils.trimToEmpty(eleSql.getChildText("SqlSelect")); this.sqlStringFromWhere = new SqlString(StringUtils.trimToEmpty(eleSql.getChildText("SqlFromWhere"))); this.sqlSum = StringUtils.trimToEmpty(eleSql.getChildTextTrim("SqlSum")); this.sqlOrder = StringUtils.trimToEmpty(eleSql.getChildTextTrim("SqlOrder")); // 读取Group定义 Element eleSqlGroup = eleConfig.getChild("sql").getChild("SqlGroup"); if (eleSqlGroup != null) { drillURL = JdomUtils.getAttributeValue(eleSqlGroup, "drillURL"); this.needTotalX = JdomUtils.getAttributeBooleanValue(eleSqlGroup, "needTotalX", true); this.needTotalY = JdomUtils.getAttributeBooleanValue(eleSqlGroup, "needTotalY", true); // 统计缺省第一次不运行 firstShow = false; this.pageSize = -1; groupList = new ArrayList(); groupMap = new HashMap(); groupListY = new ArrayList(); groupListX = new ArrayList(); groupListSelect = new ArrayList(); Iterator iterator = eleSqlGroup.getChildren("Group").iterator(); while (iterator.hasNext()) { Element eleGroup = (Element) iterator.next(); String groupName = JdomUtils.getAttributeValue(eleGroup, "groupName"); String groupLabel = JdomUtils.getAttributeValue(eleGroup, "groupLabel"); String metadatasql = JdomUtils.getAttributeValue(eleGroup, "metadatasql"); String macrovalue = JdomUtils.getAttributeValue(eleGroup, "macrovalue"); String position = JdomUtils.getAttributeValue(eleGroup, "position"); Group group = new Group(groupName, groupLabel, metadatasql, macrovalue, position); if (JdomUtils.getAttributeBooleanValue(eleGroup, "subTotal", false)) group.needSubTotal = true; group.needDrill = JdomUtils.getAttributeBooleanValue(eleGroup, "drill", false); if (!group.metadatasql.equals("") && !group.metadataSqlString.needParse()) group.metadata = JdbcUtils.queryForList(metadatasql); if (StringUtils.contains(position, "y")) groupListY.add(group); else if (StringUtils.contains(position, "x")) groupListX.add(group); else groupListSelect.add(group); groupMap.put(group.groupName, group); Collections.sort(groupListY); Collections.sort(groupListX); Collections.sort(groupListSelect); } groupList.addAll(groupListX); groupList.addAll(groupListY); // 读取统计量配置 ArrayList sqlGroupSelectList = new ArrayList(); sqlGroupSelect = new MultiCheckbox(); sqlGroupSelect.name = "sqlGroupSelect"; Iterator iteratorSqlGroupSelect = eleConfig .getChild("sql") .getChild("SqlGroupSelect") .getChildren("GroupSelect") .iterator(); while (iteratorSqlGroupSelect.hasNext()) { Element eleGroupSelect = (Element) iteratorSqlGroupSelect.next(); String label = JdomUtils.getAttributeValue(eleGroupSelect, "label"); String value = JdomUtils.getAttributeValue(eleGroupSelect, "value"); String addvalue = JdomUtils.getAttributeValue(eleGroupSelect, "addvalue"); Checkbox groupSelect = new Checkbox("", label, value, addvalue, true); sqlGroupSelectList.add(groupSelect); } this.sqlGroupSelect.metadata = sqlGroupSelectList; // 读取Group关系定义 Element eleSqlGroupRelation = eleConfig.getChild("sql").getChild("SqlGroupRelation"); groupRelationList = new ArrayList(); if (eleSqlGroupRelation != null) { iterator = eleSqlGroupRelation.getChildren("GroupRelation").iterator(); while (iterator.hasNext()) { Element eleGroupRelation = (Element) iterator.next(); String groupName1 = JdomUtils.getAttributeValue(eleGroupRelation, "groupName1"); String groupName2 = JdomUtils.getAttributeValue(eleGroupRelation, "groupName2"); String relationsql = JdomUtils.getAttributeValue(eleGroupRelation, "relationsql"); ArrayList relation = JdbcUtils.queryForList(relationsql); GroupRelation groupRelation = new GroupRelation(groupName1, groupName2, relation); groupRelationList.add(groupRelation); } } } if ((sqlSelect.length() == 0 && groupList == null) || sqlStringFromWhere.getSql().length() == 0) { QueryManager.logError(logger, query, "没有配置valuefetch中的sql中的SqlSelect或者SqlFromWhere"); return false; } needCount = JdomUtils.getAttributeBooleanValue(eleSql, "count", true); // 读取宏替换配置 Element elementReplaces = eleConfig.getChild("sql").getChild("replaces"); replaceMap = new HashMap(); if (elementReplaces != null) { Iterator iterator = elementReplaces.getChildren().iterator(); while (iterator.hasNext()) { Element elementReplace = (Element) iterator.next(); String replacename = JdomUtils.getAttributeValue(elementReplace, "replacename", ""); ArrayList paraReplaceList = new ArrayList(); MacroReplace replace = null; if (elementReplace.getAttributeValue("replacevalue") == null) // 配置放在下面的parareplace节点 { Iterator iteratorParaReplace = elementReplace.getChildren().iterator(); while (iteratorParaReplace.hasNext()) { Element elementParaReplace = (Element) iteratorParaReplace.next(); String conditionExpr = JdomUtils.getAttributeValue(elementParaReplace, "conditionExpr", ""); String paraname = JdomUtils.getAttributeValue(elementParaReplace, "paraname", ""); String paravalue = JdomUtils.getAttributeValue(elementParaReplace, "paravalue", ""); String relation = JdomUtils.getAttributeValue(elementParaReplace, "relation", "!="); String replacevalue = JdomUtils.getAttributeValue(elementParaReplace, "replacevalue", ""); replace = new MacroReplace(conditionExpr, paraname, paravalue, relation, replacevalue); paraReplaceList.add(replace); } replaceMap.put(replacename, paraReplaceList); } else // 配置就放在replace节点 { String conditionExpr = JdomUtils.getAttributeValue(elementReplace, "conditionExpr", ""); String paraname = JdomUtils.getAttributeValue(elementReplace, "paraname", ""); String paravalue = JdomUtils.getAttributeValue(elementReplace, "paravalue", ""); String relation = JdomUtils.getAttributeValue(elementReplace, "paravalue", "!="); String replacevalue = JdomUtils.getAttributeValue(elementReplace, "replacevalue", ""); replace = new MacroReplace(conditionExpr, paraname, paravalue, relation, replacevalue); paraReplaceList.add(replace); replaceMap.put(replacename, paraReplaceList); } } } return true; }