rowsetdefinition.java
来自「数据仓库展示程序」· Java 代码 · 共 1,174 行 · 第 1/5 页
JAVA
1,174 行
final Hierarchy[] hierarchies = dimension.getHierarchies();
for (int k = 0; k < hierarchies.length; k++) {
HierarchyBase hierarchy = (HierarchyBase)hierarchies[k];
Row row = new Row();
row.set(CatalogName.name, cube.getSchema().getName());
row.set(SchemaName.name, cube.getSchema().getName());
row.set(CubeName.name, cube.getName());
row.set(DimensionUniqueName.name, dimension.getUniqueName());
row.set(HierarchyName.name, hierarchy.getName());
row.set(HierarchyUniqueName.name, hierarchy.getUniqueName());
row.set(HierarchyCaption.name, hierarchy.getCaption());
row.set(DimensionType.name, getDimensionType(dimension));
row.set(DefaultMember.name, hierarchy.getDefaultMember());
if (hierarchy.hasAll()) {
row.set(AllMember.name, Util.makeFqName(
hierarchy,
hierarchy.getAllMemberName()));
}
emit(row, saxHandler);
}
}
}
}
}
// REF http://msdn.microsoft.com/library/en-us/oledb/htm/olaplevels_rowset.asp
static class MdschemaLevelsRowset extends Rowset {
MdschemaLevelsRowset(HashMap restrictions, Properties properties) {
super(definition, restrictions, properties);
}
public static final int MDLEVEL_TYPE_UNKNOWN = 0x0000;
public static final int MDLEVEL_TYPE_REGULAR = 0x0000;
public static final int MDLEVEL_TYPE_ALL = 0x0001;
public static final int MDLEVEL_TYPE_CALCULATED = 0x0002;
public static final int MDLEVEL_TYPE_TIME = 0x0004;
public static final int MDLEVEL_TYPE_RESERVED1 = 0x0008;
public static final int MDLEVEL_TYPE_TIME_YEARS = 0x0014;
public static final int MDLEVEL_TYPE_TIME_HALF_YEAR = 0x0024;
public static final int MDLEVEL_TYPE_TIME_QUARTERS = 0x0044;
public static final int MDLEVEL_TYPE_TIME_MONTHS = 0x0084;
public static final int MDLEVEL_TYPE_TIME_WEEKS = 0x0104;
public static final int MDLEVEL_TYPE_TIME_DAYS = 0x0204;
public static final int MDLEVEL_TYPE_TIME_HOURS = 0x0304;
public static final int MDLEVEL_TYPE_TIME_MINUTES = 0x0404;
public static final int MDLEVEL_TYPE_TIME_SECONDS = 0x0804;
public static final int MDLEVEL_TYPE_TIME_UNDEFINED = 0x1004;
private static final Column CatalogName = new Column("CATALOG_NAME", Type.String, null, true, false, null);
private static final Column SchemaName = new Column("SCHEMA_NAME", Type.String, null, true, true, null);
private static final Column CubeName = new Column("CUBE_NAME", Type.String, null, true, false, null);
private static final Column DimensionUniqueName = new Column("DIMENSION_UNIQUE_NAME", Type.String, null, true, false, null);
private static final Column HierarchyUniqueName = new Column("HIERARCHY_UNIQUE_NAME", Type.String, null, true, false, null);
private static final Column LevelName = new Column("LEVEL_NAME", Type.String, null, true, false, null);
private static final Column LevelUniqueName = new Column("LEVEL_UNIQUE_NAME", Type.String, null, true, false, null);
private static final Column LevelCaption = new Column("LEVEL_CAPTION", Type.String, null, true, false, null);
private static final Column LevelNumber = new Column("LEVEL_NUMBER", Type.Integer, null, true, false, null);
private static final Column LevelType = new Column("LEVEL_TYPE", Type.Integer, null, true, false, null);
public static final RowsetDefinition definition = new RowsetDefinition(
"MDSCHEMA_LEVELS", MDSCHEMA_LEVELS, null, new Column[] {
CatalogName,
SchemaName,
CubeName,
DimensionUniqueName,
HierarchyUniqueName,
LevelName,
LevelUniqueName,
LevelCaption,
LevelNumber,
LevelType,
}) {
public Rowset getRowset(HashMap restrictions, Properties properties) {
return new MdschemaLevelsRowset(restrictions, properties);
}
};
public void unparse(SAXHandler saxHandler) throws SAXException {
final Connection connection = XmlaMediator.getConnection(properties);
final Cube[] cubes = connection.getSchema().getCubes();
for (int i = 0; i < cubes.length; i++) {
Cube cube = cubes[i];
final Dimension[] dimensions = cube.getDimensions();
for (int j = 0; j < dimensions.length; j++) {
Dimension dimension = dimensions[j];
final Hierarchy[] hierarchies = dimension.getHierarchies();
for (int k = 0; k < hierarchies.length; k++) {
Hierarchy hierarchy = hierarchies[k];
final Level[] levels = hierarchy.getLevels();
for (int m = 0; m < levels.length; m++) {
Level level = levels[m];
Row row = new Row();
row.set(CatalogName.name, cube.getSchema().getName());
row.set(SchemaName.name, cube.getSchema().getName());
row.set(CubeName.name, cube.getName());
row.set(DimensionUniqueName.name, dimension.getUniqueName());
row.set(HierarchyUniqueName.name, hierarchy.getUniqueName());
row.set(LevelName.name, level.getName());
row.set(LevelUniqueName.name, level.getUniqueName());
row.set(LevelCaption.name, level.getCaption());
row.set(LevelNumber.name, level.getDepth()); // see notes on this #getDepth()
row.set(LevelType.name, getLevelType(level));
emit(row, saxHandler);
}
}
}
}
}
private int getLevelType(Level lev) {
if (lev.isAll()) {
return MDLEVEL_TYPE_ALL;
} else {
mondrian.olap.LevelType type = lev.getLevelType();
switch(type.getOrdinal()) {
case mondrian.olap.LevelType.RegularORDINAL:
return MDLEVEL_TYPE_REGULAR;
case mondrian.olap.LevelType.TimeDaysORDINAL:
return MDLEVEL_TYPE_TIME_DAYS;
case mondrian.olap.LevelType.TimeMonthsORDINAL:
return MDLEVEL_TYPE_TIME_MONTHS;
case mondrian.olap.LevelType.TimeQuartersORDINAL:
return MDLEVEL_TYPE_TIME_QUARTERS;
case mondrian.olap.LevelType.TimeWeeksORDINAL:
return MDLEVEL_TYPE_TIME_WEEKS;
case mondrian.olap.LevelType.TimeYearsORDINAL:
return MDLEVEL_TYPE_TIME_YEARS;
default:
return MDLEVEL_TYPE_UNKNOWN;
}
}
}
}
// REF http://msdn.microsoft.com/library/en-us/oledb/htm/olapmeasures_rowset.asp
static class MdschemaMeasuresRowset extends Rowset {
MdschemaMeasuresRowset(HashMap restrictions, Properties properties) {
super(definition, restrictions, properties);
}
private static final Column CatalogName = new Column("CATALOG_NAME", Type.String, null, true, false, null);
private static final Column SchemaName = new Column("SCHEMA_NAME", Type.String, null, true, true, null);
private static final Column CubeName = new Column("CUBE_NAME", Type.String, null, true, false, null);
private static final Column MeasureName = new Column("MEASURE_NAME", Type.String, null, true, false, null);
private static final Column MeasureUniqueName = new Column("MEASURE_UNIQUE_NAME", Type.String, null, true, false, null);
private static final Column MeasureCaption = new Column("MEASURE_CAPTION", Type.String, null, true, false, null);
public static final RowsetDefinition definition = new RowsetDefinition(
"MDSCHEMA_MEASURES", MDSCHEMA_MEASURES, null, new Column[] {
CatalogName,
SchemaName,
CubeName,
MeasureName,
MeasureUniqueName,
MeasureCaption,
}) {
public Rowset getRowset(HashMap restrictions, Properties properties) {
return new MdschemaMeasuresRowset(restrictions, properties);
}
};
public void unparse(SAXHandler saxHandler) throws SAXException {
// return both stored and calculated members on hierarchy [Measures]
final Connection connection = XmlaMediator.getConnection(properties);
final Role role = connection.getRole();
final Cube[] cubes = connection.getSchema().getCubes();
for (int i = 0; i < cubes.length; i++) {
Cube cube = cubes[i];
SchemaReader schemaReader = cube.getSchemaReader(role);
final Dimension measuresDimension = cube.getDimensions()[0];
final Hierarchy measuresHierarchy = measuresDimension.getHierarchies()[0];
Member[] storedMembers = schemaReader.getLevelMembers(measuresHierarchy.getLevels()[0]);
for (int j = 0; j < storedMembers.length; j++) {
emitMember(saxHandler, storedMembers[j], cube);
}
List calculatedMembers = schemaReader.getCalculatedMembers(measuresHierarchy);
for (Iterator it = calculatedMembers.iterator(); it.hasNext();){
emitMember(saxHandler, (Member)it.next(), cube);
}
}
}
private void emitMember(SAXHandler saxHandler, Member member, Cube cube) throws SAXException {
Row row = new Row();
row.set(CatalogName.name, cube.getSchema().getName());
row.set(SchemaName.name, cube.getSchema().getName());
row.set(CubeName.name, cube.getName());
row.set(MeasureName.name, member.getName());
row.set(MeasureUniqueName.name, member.getUniqueName());
row.set(MeasureCaption.name, member.getCaption());
emit(row, saxHandler);
}
}
static class MdschemaMembersRowset extends Rowset {
MdschemaMembersRowset(HashMap restrictions, Properties properties) {
super(definition, restrictions, properties);
}
private static final Column CatalogName = new Column("CATALOG_NAME", Type.String, null, true, false, null);
private static final Column SchemaName = new Column("SCHEMA_NAME", Type.String, null, true, true, null);
private static final Column CubeName = new Column("CUBE_NAME", Type.String, null, true, false, null);
private static final Column DimensionUniqueName = new Column("DIMENSION_UNIQUE_NAME", Type.String, null, true, false, null);
private static final Column HierarchyUniqueName = new Column("HIERARCHY_UNIQUE_NAME", Type.String, null, true, false, null);
private static final Column LevelUniqueName = new Column("LEVEL_UNIQUE_NAME", Type.String, null, true, false, null);
private static final Column LevelNumber = new Column("LEVEL_NUMBER", Type.UnsignedInteger, null, true, false, null);
private static final Column MemberName = new Column("MEMBER_NAME", Type.String, null, true, false, null);
private static final Column MemberOrdinal = new Column("MEMBER_ORDINAL", Type.Integer, null, true, false, null);
private static final Column MemberUniqueName = new Column("MEMBER_UNIQUE_NAME", Type.String, null, true, false, null);
private static final Column MemberType = new Column("MEMBER_TYPE", Type.Integer, null, true, false, null);
private static final Column MemberCaption = new Column("MEMBER_CAPTION", Type.String, null, true, false, null);
private static final Column ChildrenCardinality = new Column("CHILDREN_CARDINALITY", Type.Integer, null, true, false, null);
private static final Column ParentLevel = new Column("PARENT_LEVEL", Type.Integer, null, false, false, null);
private static final Column ParentUniqueName = new Column("PARENT_UNIQUE_NAME", Type.String, null, true, true, null);
private static final Column TreeOp = new Column("TREE_OP", Type.Enumeration, Enumeration.TreeOp.enumeration, true, true, null);
public static final RowsetDefinition definition = new RowsetDefinition(
"MDSCHEMA_MEMBERS", MDSCHEMA_MEMBERS, null, new Column[] {
CatalogName,
SchemaName,
CubeName,
DimensionUniqueName,
HierarchyUniqueName,
LevelUniqueName,
LevelNumber,
MemberName,
MemberOrdinal,
MemberUniqueName,
MemberType,
MemberCaption,
ChildrenCardinality,
ParentLevel,
ParentUniqueName,
TreeOp,
}) {
public Rowset getRowset(HashMap restrict
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?