aggtablemanager.java
来自「数据仓库展示程序」· Java 代码 · 共 496 行 · 第 1/2 页
JAVA
496 行
dbTable.setTableUsage(JdbcSchema.AGG_TABLE_USAGE);
String alias = null;
dbTable.table = new MondrianDef.Table(schema,
name,
alias);
AggStar aggStar = AggStar.makeAggStar(star,
dbTable,
msgRecorder);
star.addAggStar(aggStar);
}
// Note: if the dbTable name matches but the columnsOK does
// not, then this is an error and the aggregate tables
// can not be loaded.
// We do not "reset" the column usages in the dbTable allowing
// it maybe to match another rule.
}
}
} catch (RecorderException ex) {
throw new MondrianException(ex);
} finally {
msgRecorder.logInfoMessage(getLogger());
msgRecorder.logWarningMessage(getLogger());
msgRecorder.logErrorMessage(getLogger());
if (msgRecorder.hasErrors()) {
throw mres.AggLoadingExceededErrorCount.ex(
new Integer(msgRecorder.getErrorCount()));
}
}
}
private boolean runTrigger() {
if (RolapSchema.cacheContains(schema)) {
return true;
} else {
// must remove triggers
deregisterTriggers(MondrianProperties.instance());
return false;
}
}
/**
* Registers triggers for the following properties:
* <ul>
* <li>{@link MondrianProperties#ChooseAggregateByVolume}
* <li>{@link MondrianProperties#AggregateRules}
* <li>{@link MondrianProperties#AggregateRuleTag}
* <li>{@link MondrianProperties#ReadAggregates}
* </ul>
*/
private void registerTriggers() {
final MondrianProperties properties = MondrianProperties.instance();
triggers = new Trigger[] {
// When the ordering AggStars property is changed, we must
// reorder them, so we create a trigger.
// There is no need to provide equals/hashCode methods for this
// Trigger since it is never explicitly removed.
new Trigger() {
public boolean isPersistent() {
return false;
}
public int phase() {
return Trigger.SECONDARY_PHASE;
}
public void execute(Property property, String value) {
if (AggTableManager.this.runTrigger()) {
reOrderAggStarList();
}
}
},
// Register to know when the Default resource/url has changed
// so that the default aggregate table recognition rules can
// be re-loaded.
// There is no need to provide equals/hashCode methods for this
// Trigger since it is never explicitly removed.
new Trigger() {
public boolean isPersistent() {
return false;
}
public int phase() {
return Trigger.SECONDARY_PHASE;
}
public void execute(Property property, String value) {
if (AggTableManager.this.runTrigger()) {
reLoadRolapStarAggregates();
}
}
},
// If the system started not using aggregates, i.e., the aggregate
// tables were not loaded, but then the property
// was changed to use aggregates, we must then load the aggregates
// if they were never loaded.
new Trigger() {
public boolean isPersistent() {
return false;
}
public int phase() {
return Trigger.SECONDARY_PHASE;
}
public void execute(Property property, String value) {
if (AggTableManager.this.runTrigger()) {
reLoadRolapStarAggregates();
}
}
}
};
properties.ChooseAggregateByVolume.addTrigger(triggers[0]);
properties.AggregateRules.addTrigger(triggers[1]);
properties.AggregateRuleTag.addTrigger(triggers[1]);
properties.ReadAggregates.addTrigger(triggers[2]);
}
private void deregisterTriggers(final MondrianProperties properties) {
properties.ChooseAggregateByVolume.removeTrigger(triggers[0]);
properties.AggregateRules.addTrigger(triggers[1]);
properties.AggregateRuleTag.addTrigger(triggers[1]);
properties.ReadAggregates.addTrigger(triggers[2]);
}
private Iterator getStars() {
return schema.getStars();
}
private void reOrderAggStarList() {
for (Iterator it = getStars(); it.hasNext(); ) {
RolapStar star = (RolapStar) it.next();
star.reOrderAggStarList();
}
}
/**
* Returns a list containing every
* {@link mondrian.rolap.aggmatcher.ExplicitRules.Group} in every
* cubes in a given {@link RolapStar}.
*/
protected List getAggGroups(RolapStar star) {
List list = schema.getCubesWithStar(star);
List aggGroups = Collections.EMPTY_LIST;
for (Iterator it = list.iterator(); it.hasNext(); ) {
RolapCube cube = (RolapCube) it.next();
if (cube.hasAggGroup() && cube.getAggGroup().hasRules()) {
if (aggGroups == Collections.EMPTY_LIST) {
aggGroups = new ArrayList();
}
aggGroups.add(cube.getAggGroup());
}
}
return aggGroups;
}
/**
* This method mines the RolapStar and annotes the JdbcSchema.Table
* dbFactTable by creating JdbcSchema.Table.Column.Usage instances. For
* example, a measure in the RolapStar becomes a measure usage for the
* column with the same name and a RolapStar foreign key column becomes a
* foreign key usage for the column with the same name.
*
* @param dbFactTable
* @param star
* @param msgRecorder
*/
void bindToStar(final JdbcSchema.Table dbFactTable,
final RolapStar star,
final MessageRecorder msgRecorder) throws SQLException {
msgRecorder.pushContextName("AggTableManager.bindToStar");
try {
// load columns
dbFactTable.load();
dbFactTable.setTableUsage(JdbcSchema.FACT_TABLE_USAGE);
MondrianDef.Relation relation = star.getFactTable().getRelation();
String schema = null;
if (relation instanceof MondrianDef.Table) {
schema = ((MondrianDef.Table) relation).schema;
}
String tableName = dbFactTable.getName();
String alias = null;
dbFactTable.table = new MondrianDef.Table(schema, tableName, alias);
for (Iterator it = dbFactTable.getColumns(); it.hasNext(); ) {
JdbcSchema.Table.Column factColumn =
(JdbcSchema.Table.Column) it.next();
String cname = factColumn.getName();
RolapStar.Column[] rcs =
star.getFactTable().lookupColumns(cname);
for (int i = 0; i < rcs.length; i++) {
RolapStar.Column rc = rcs[i];
// its a measure
if (rc instanceof RolapStar.Measure) {
RolapStar.Measure rm = (RolapStar.Measure) rc;
JdbcSchema.Table.Column.Usage usage =
factColumn.newUsage(JdbcSchema.MEASURE_COLUMN_USAGE);
usage.setSymbolicName(rm.getName());
usage.setAggregator(rm.getAggregator());
usage.rMeasure = rm;
}
}
// it still might be a foreign key
RolapStar.Table rTable =
star.getFactTable().findTableWithLeftJoinCondition(cname);
if (rTable != null) {
JdbcSchema.Table.Column.Usage usage =
factColumn.newUsage(JdbcSchema.FOREIGN_KEY_COLUMN_USAGE);
usage.setSymbolicName("FOREIGN_KEY");
usage.rTable = rTable;
} else {
RolapStar.Column rColumn =
star.getFactTable().lookupColumn(cname);
if ((rColumn != null) &&
! (rColumn instanceof RolapStar.Measure)) {
// Ok, maybe its used in a non-shared dimension
// This is a column in the fact table which is
// (not necessarily) a measure but is also not
// a foreign key to an external dimension table.
JdbcSchema.Table.Column.Usage usage =
factColumn.newUsage(
JdbcSchema.FOREIGN_KEY_COLUMN_USAGE);
usage.setSymbolicName("FOREIGN_KEY");
usage.rColumn = rColumn;
}
}
// warn if it has not been identified
if (! factColumn.hasUsage()) {
String msg = mres.UnknownFactTableColumn.str(
msgRecorder.getContext(),
dbFactTable.getName(),
factColumn.getName());
msgRecorder.reportInfo(msg);
}
}
} finally {
msgRecorder.popContextName();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?