Search in sources :

Example 1 with Dimension

use of org.olap4j.metadata.Dimension in project mondrian by pentaho.

the class MondrianOlap4jCube method getMeasures.

public List<Measure> getMeasures() {
    final Dimension dimension = getDimensions().get("Measures");
    if (dimension == null) {
        return Collections.emptyList();
    }
    final MondrianOlap4jConnection olap4jConnection = olap4jSchema.olap4jCatalog.olap4jDatabaseMetaData.olap4jConnection;
    try {
        final mondrian.olap.SchemaReader schemaReader = olap4jConnection.getMondrianConnection().getSchemaReader().withLocus();
        final MondrianOlap4jLevel measuresLevel = (MondrianOlap4jLevel) dimension.getDefaultHierarchy().getLevels().get(0);
        final List<Measure> measures = new ArrayList<Measure>();
        List<mondrian.olap.Member> levelMembers = schemaReader.getLevelMembers(measuresLevel.level, true);
        for (mondrian.olap.Member member : levelMembers) {
            // This corrects MONDRIAN-1123, a ClassCastException (see below)
            // that occurs when you create a calculated member on a
            // dimension other than Measures:
            // java.lang.ClassCastException:
            // mondrian.olap4j.MondrianOlap4jMember cannot be cast to
            // org.olap4j.metadata.Measure
            MondrianOlap4jMember olap4jMember = olap4jConnection.toOlap4j(member);
            if (olap4jMember instanceof Measure) {
                measures.add((Measure) olap4jMember);
            }
        }
        return measures;
    } catch (OlapException e) {
        // Demote from checked to unchecked exception.
        throw new RuntimeException(e);
    }
}
Also used : OlapException(org.olap4j.OlapException) Dimension(org.olap4j.metadata.Dimension) mondrian.olap(mondrian.olap) Member(org.olap4j.metadata.Member)

Aggregations

mondrian.olap (mondrian.olap)1 OlapException (org.olap4j.OlapException)1 Dimension (org.olap4j.metadata.Dimension)1 Member (org.olap4j.metadata.Member)1