defaultrules.java

来自「数据仓库展示程序」· Java 代码 · 共 433 行 · 第 1/2 页

JAVA
433
字号
        try {
            final Parser xmlParser = XOMUtil.createDefaultParser();
            DOMWrapper def = xmlParser.parse(inStream);
            return def;
        } catch (XOMException e) {
            throw mres.AggRuleParse.ex("InputStream",e);
        }
    }
    protected static DOMWrapper makeDOMWrapper(final String text,
                                               final String name) {
        try {
            final Parser xmlParser = XOMUtil.createDefaultParser();
            DOMWrapper def = xmlParser.parse(text);
            return def;
        } catch (XOMException e) {
            throw mres.AggRuleParse.ex(name,e);
        }
    }


    private final DefaultDef.AggRules rules;
    private final Map factToPattern;
    private final Map foreignKeyMatcherMap;
    private Recognizer.Matcher factCountMatcher;
    private String tag;

    private DefaultRules(final DefaultDef.AggRules rules) {
        this.rules = rules;
        this.factToPattern = new HashMap();
        this.foreignKeyMatcherMap = new HashMap();
        this.tag = MondrianProperties.instance().AggregateRuleTag
                .getDefaultValue();
    }

    public void validate(MessageRecorder msgRecorder) {
        rules.validate(msgRecorder);
    }

    /**
     * Sets the name (tag) of this rule.
     *
     * @param tag
     */
    private void setTag(final String tag) {
        this.tag = tag;
    }

    /**
     * Gets the tag of this rule (this is the value of the
     * {@link MondrianProperties#AggregateRuleTag} property).
     *
     * @return
     */
    public String getTag() {
        return this.tag;
    }


    /**
     * Returns the {@link mondrian.rolap.aggmatcher.DefaultDef.AggRule} whose
     * tag equals this rule's tag.
     */
    public DefaultDef.AggRule getAggRule() {
        return getAggRule(getTag());
    }

    /**
     * Returns the {@link mondrian.rolap.aggmatcher.DefaultDef.AggRule} whose
     * tag equals the parameter tag, or null if not found.
     *
     * @param tag
     * @return the AggRule with tag value equal to tag parameter, or null.
     */
    public DefaultDef.AggRule getAggRule(final String tag) {
        return this.rules.getAggRule(tag);
    }

    /**
     * Gets the {@link mondrian.rolap.aggmatcher.Recognizer.Matcher} for this
     * tableName.
     *
     * @param tableName
     */
    public Recognizer.Matcher getTableMatcher(final String tableName) {
        Recognizer.Matcher matcher =
            (Recognizer.Matcher) factToPattern.get(tableName);
        if (matcher == null) {
            // get default AggRule
            DefaultDef.AggRule rule = getAggRule();
            DefaultDef.TableMatch tableMatch = rule.getTableMatch();
            matcher = tableMatch.getMatcher(tableName);
            factToPattern.put(tableName, matcher);
        }
        return matcher;
    }

    /**
     * Gets the {@link mondrian.rolap.aggmatcher.Recognizer.Matcher} for the
     * fact count column.
     */
    public Recognizer.Matcher getFactCountMatcher() {
        if (factCountMatcher == null) {
            // get default AggRule
            DefaultDef.AggRule rule = getAggRule();
            DefaultDef.FactCountMatch factCountMatch =
                rule.getFactCountMatch();
            factCountMatcher = factCountMatch.getMatcher();
        }
        return factCountMatcher;
    }

    /**
     * Gets the {@link mondrian.rolap.aggmatcher.Recognizer.Matcher} for this
     * foreign key column name.
     *
     * @param foreignKeyName
     */
    public Recognizer.Matcher getForeignKeyMatcher(String foreignKeyName) {
        Recognizer.Matcher matcher =
            (Recognizer.Matcher) foreignKeyMatcherMap.get(foreignKeyName);
        if (matcher == null) {
            // get default AggRule
            DefaultDef.AggRule rule = getAggRule();
            DefaultDef.ForeignKeyMatch foreignKeyMatch =
                rule.getForeignKeyMatch();
            matcher = foreignKeyMatch.getMatcher(foreignKeyName);
            foreignKeyMatcherMap.put(foreignKeyName, matcher);
        }
        return matcher;
    }

    /**
     * Returns true if this candidate aggregate table name "matches" the
     * factTableName.
     *
     * @param factTableName
     * @param name candidate aggregate table name
     * @return
     */
    public boolean matchesTableName(final String factTableName,
                                    final String name) {
        Recognizer.Matcher matcher = getTableMatcher(factTableName);
        return matcher.matches(name);
    }

    /**
     * Creates a {@link mondrian.rolap.aggmatcher.Recognizer.Matcher} for the
     * given measure name (symbolic name), column name and aggregate name
     * (sum, count, etc.).
     *
     * @param measureName
     * @param measureColumnName
     * @param aggregateName
     * @return
     */
    public Recognizer.Matcher getMeasureMatcher(final String measureName,
                                                final String measureColumnName,
                                                final String aggregateName) {
        DefaultDef.AggRule rule = getAggRule();
        Recognizer.Matcher matcher =
            rule.getMeasureMap().getMatcher(measureName,
                                            measureColumnName,
                                            aggregateName);
        return matcher;
    }

    /**
     * Gets a {@link mondrian.rolap.aggmatcher.Recognizer.Matcher} for a given
     * level's hierarchy's name, level name and column name.
     *
     * @param hierarchyName
     * @param levelName
     * @param levelColumnName
     * @return
     */
    public Recognizer.Matcher getLevelMatcher(final String usagePrefix,
                                              final String hierarchyName,
                                              final String levelName,
                                              final String levelColumnName) {
        DefaultDef.AggRule rule = getAggRule();
        Recognizer.Matcher matcher =
            rule.getLevelMap().getMatcher(usagePrefix,
                                          hierarchyName,
                                          levelName,
                                          levelColumnName);
        return matcher;
    }

    /**
     * Uses the {@link DefaultRecognizer} Recognizer to determine if the
     * given aggTable's columns all match upto the dbFactTable's columns (where
     * present) making the column usages as a result.
     *
     * @param star
     * @param dbFactTable
     * @param aggTable
     * @param msgRecorder
     * @return
     */
    public boolean columnsOK(
            final RolapStar star,
            final JdbcSchema.Table dbFactTable,
            final JdbcSchema.Table aggTable,
            final MessageRecorder msgRecorder) {
        Recognizer cb = new DefaultRecognizer(
                this,
                star,
                dbFactTable,
                aggTable,
                msgRecorder);
        return cb.check();
    }
}

// End DefaultRules.java

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?