explicitrules.java
来自「数据仓库展示程序」· Java 代码 · 共 1,597 行 · 第 1/4 页
JAVA
1,597 行
aggExclude.isIgnoreCase())
: (Exclude) new ExcludePattern(aggExclude.getPattern(),
aggExclude.isIgnoreCase());
}
/**
* Interface of an Exclude type. There are two implementations, one that
* excludes by exact name match (as an option, ignore case) and the second
* that matches a regular expression.
*/
private interface Exclude {
/**
* Return true if the tableName is exculed.
*
* @param tableName
* @return
*/
boolean isExcluded(final String tableName);
void validate(final MessageRecorder msgRecorder);
void print(final PrintWriter pw, final String prefix);
}
/**
* This class is an exact name matching Exclude implementation.
*/
private static class ExcludeName implements Exclude {
private final String name;
private final boolean ignoreCase;
private ExcludeName(final String name, final boolean ignoreCase) {
this.name = name;
this.ignoreCase = ignoreCase;
}
/**
* Get the name that is to be matched.
*
* @return
*/
public String getName() {
return name;
}
/**
* Returns true if the matching can ignore case.
*
* @return
*/
public boolean isIgnoreCase() {
return ignoreCase;
}
/**
* Return true if the tableName is exculed.
*
* @param tableName
* @return
*/
public boolean isExcluded(final String tableName) {
return (this.ignoreCase)
? this.name.equals(tableName)
: this.name.equalsIgnoreCase(tableName);
}
/**
* Validate that the exclude name matches the table pattern.
*
* @param msgRecorder
*/
public void validate(final MessageRecorder msgRecorder) {
msgRecorder.pushContextName("ExcludeName");
try {
String name = getName();
checkAttributeString(msgRecorder, name, "name");
/*
RME TODO
// If name does not match the PatternTableDef pattern,
// then issue warning.
// Why, because no table with the exclude's name will
// ever match the pattern, so the exclude is superfluous.
// This is best effort.
Pattern pattern = ExplicitRules.PatternTableDef.this.getPattern();
boolean patternIgnoreCase =
ExplicitRules.PatternTableDef.this.isIgnoreCase();
boolean ignoreCase = isIgnoreCase();
// If pattern is ignoreCase and name is any case or pattern
// is not ignoreCase and name is not ignoreCase, then simply
// see if name matches.
// Else pattern in not ignoreCase and name is ignoreCase,
// then pattern could be "AB.*" and name "abc".
// Here "abc" would name, but not pattern - but who cares
if (patternIgnoreCase || ! ignoreCase) {
if (! pattern.matcher(name).matches()) {
msgRecorder.reportWarning(
mres.getSuperfluousExludeName(
msgRecorder.getContext(),
name,
pattern.pattern()));
}
}
*/
} finally {
msgRecorder.popContextName();
}
}
public void print(final PrintWriter pw, final String prefix) {
pw.print(prefix);
pw.println("ExplicitRules.PatternTableDef.ExcludeName:");
String subprefix = prefix + " ";
pw.print(subprefix);
pw.print("name=");
pw.println(this.name);
pw.print(subprefix);
pw.print("ignoreCase=");
pw.println(this.ignoreCase);
}
}
/**
* This class is a regular expression base name matching Exclude
* implementation.
*/
private static class ExcludePattern implements Exclude {
private final Pattern pattern;
private ExcludePattern(final String pattern,
final boolean ignoreCase) {
this.pattern = (ignoreCase)
? Pattern.compile(pattern, Pattern.CASE_INSENSITIVE)
: Pattern.compile(pattern);
}
/**
* Return true if the tableName is exculed.
*
* @param tableName
* @return
*/
public boolean isExcluded(final String tableName) {
return pattern.matcher(tableName).matches();
}
/**
* Validate that the exclude pattern overlaps with table pattern.
*
* @param msgRecorder
*/
public void validate(final MessageRecorder msgRecorder) {
msgRecorder.pushContextName("ExcludePattern");
try {
checkAttributeString(msgRecorder,
pattern.pattern(),
"pattern");
//String context = msgRecorder.getContext();
// Is there any way to determine if the exclude pattern
// is never a sub-set of the table pattern.
// I will have to think about this.
// Until then, this method is empty.
} finally {
msgRecorder.popContextName();
}
}
public void print(final PrintWriter pw, final String prefix) {
pw.print(prefix);
pw.println("ExplicitRules.PatternTableDef.ExcludePattern:");
String subprefix = prefix + " ";
pw.print(subprefix);
pw.print("pattern=");
pw.print(this.pattern.pattern());
pw.print(":");
pw.println(this.pattern.flags());
}
}
/**
* This is the base class for the exact name based and name pattern based
* aggregate table mapping definitions. It contains the mappings for the
* fact count column, optional ignore columns, foreign key mappings,
* measure column mappings and level column mappings.
*/
public static abstract class TableDef {
/**
* Given a MondrianDef.AggTable instance create a TableDef instance
* which is either a NameTableDef or PatternTableDef.
*
* @param aggTable
* @param group
* @return
*/
static ExplicitRules.TableDef make(final MondrianDef.AggTable aggTable,
final ExplicitRules.Group group) {
return (aggTable instanceof MondrianDef.AggName)
? ExplicitRules.NameTableDef.make(
(MondrianDef.AggName) aggTable, group)
: (ExplicitRules.TableDef)
ExplicitRules.PatternTableDef.make(
(MondrianDef.AggPattern) aggTable, group);
}
/**
* This method extracts information from the MondrianDef.AggTable and
* places it in the ExplicitRules.TableDef. This code is used for both
* the NameTableDef and PatternTableDef subclasses of TableDef (it
* extracts information common to both).
*
* @param tableDef
* @param aggTable
*/
private static void add(final ExplicitRules.TableDef tableDef,
final MondrianDef.AggTable aggTable) {
tableDef.setFactCountName(aggTable.getAggFactCount().getColumnName());
MondrianDef.AggIgnoreColumn[] ignores =
aggTable.getAggIgnoreColumns();
if (ignores != null) {
for (int i = 0; i < ignores.length; i++) {
tableDef.addIgnoreColumnName(ignores[i].getColumnName());
}
}
MondrianDef.AggForeignKey[] fks = aggTable.getAggForeignKeys();
if (fks != null) {
for (int i = 0; i < fks.length; i++) {
tableDef.addFK(fks[i]);
}
}
MondrianDef.AggMeasure[] measures = aggTable.getAggMeasures();
if (measures != null) {
for (int i = 0; i < measures.length; i++) {
addTo(tableDef, measures[i]);
}
}
MondrianDef.AggLevel[] levels = aggTable.getAggLevels();
if (levels != null) {
for (int i = 0; i < levels.length; i++) {
addTo(tableDef, levels[i]);
}
}
}
private static void addTo(final ExplicitRules.TableDef tableDef,
final MondrianDef.AggLevel aggLevel) {
addLevelTo(tableDef,
aggLevel.getNameAttribute(),
aggLevel.getColumnName());
}
private static void addTo(final ExplicitRules.TableDef tableDef,
final MondrianDef.AggMeasure aggMeasure) {
addMeasureTo(tableDef,
aggMeasure.getNameAttribute(),
aggMeasure.getColumn());
}
public static void addLevelTo(final ExplicitRules.TableDef tableDef,
final String name,
final String columnName) {
Level level = tableDef.new Level(name, columnName);
tableDef.add(level);
}
public static void addMeasureTo(final ExplicitRules.TableDef tableDef,
final String name,
final String column) {
Measure measure = tableDef.new Measure(name, column);
tableDef.add(measure);
}
/**
* This class is used to map from a Level's symbolic name,
* [Time].[Year] to the aggregate table's column name, TIME_YEAR.
*/
class Level {
private final String name;
private final String columnName;
private RolapLevel rlevel;
Level(final String name, final String columnName) {
this.name = name;
this.columnName = columnName;
}
/**
* Get the symbolic name, the level name.
*
* @return
*/
public String getName() {
return name;
}
/**
* Get the foreign key column name of the aggregate table.
*
* @return
*/
public String getColumnName() {
return columnName;
}
/**
* Get the RolapLevel associated with level name.
*
* @return
*/
public RolapLevel getRolapLevel() {
return rlevel;
}
/**
* Validates a level's name
* AggLevel name is a [hierarchy usage name].[level name]
* Check that is of length 2, starts with a hierarchy and
* the "level name" exists.
*
* @param msgRecorder
*/
public void validate(final MessageRecorder msgRecorder) {
msgRecorder.pushContextName("Level");
try {
String name = getName();
String columnName = getColumnName();
checkAttributeString(msgRecorder, name, "name");
checkAttributeString(msgRecorder, columnName, "column");
String[] names = Util.explode(name);
// must be [hierarchy usage name].[level name]
if (names.length != 2) {
msgRecorder.reportError(
mres.BadLevelNameFormat.str(
msgRecorder.getContext(),
name));
} else {
RolapCube cube = ExplicitRules.TableDef.this.getCube();
SchemaReader schemaReader = cube.getSchemaReader();
RolapLevel level =
(RolapLevel) schemaReader.lookupCompound(
cube,
names,
false,
Category.Level);
if (level == null) {
Hierarchy hierarchy = (Hierarchy)
schemaReader.lookupCompound(
cube,
new String[] { names[0] },
false,
Category.Hierarchy);
if (hierarchy == null) {
msgRecorder.reportError(
mres.UnknownHierarchyName.str(
msgRecorder.getContext(),
names[0]));
} else {
msgRecorder.reportError(
mres.UnknownLevelName.str(
msgRecorder.getContext(),
names[0],
names[1]));
}
}
rlevel = level;
}
} finally {
msgRecorder.popContextName();
}
}
public String toString() {
StringWriter sw = new StringWriter(256);
PrintWriter pw = new PrintWriter(sw);
print(pw, "");
pw.flush();
return sw.toString();
}
public void print(final PrintWriter pw, final String prefix) {
pw.print(prefix);
pw.println("Level:");
String subprefix = prefix + " ";
pw.print(subprefix);
pw.print("name=");
pw.println(this.name);
pw.print(subprefix);
pw.print("columnName=");
pw.println(this.columnName);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?