rolaplevel.java

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

JAVA
429
字号
/*
// $Id: //open/mondrian/src/main/mondrian/rolap/RolapLevel.java#29 $
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// (C) Copyright 2001-2005 Kana Software, Inc. and others.
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
//
// jhyde, 10 August, 2001
*/

package mondrian.rolap;
import mondrian.olap.*;
import mondrian.resource.MondrianResource;

import org.apache.log4j.Logger;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * <code>RolapLevel</code> implements {@link Level} for a ROLAP database.
 *
 * @author jhyde
 * @since 10 August, 2001
 * @version $Id: //open/mondrian/src/main/mondrian/rolap/RolapLevel.java#29 $
 */
public class RolapLevel extends LevelBase {

    private static final Logger LOGGER = Logger.getLogger(RolapEvaluator.class);

    public static RolapLevel lookupLevel(RolapLevel[] levels, String levelName) {
        for (int i = 0; i < levels.length; i++) {
            RolapLevel level = levels[i];
            if (level.getName().equals(levelName)) {
                return level;
            }
        }
        return null;
    }

    static final int NUMERIC = 1;
    static final int ALL = 2;
    static final int UNIQUE = 4;

    /** The column or expression which yields the level's key. */
    private final MondrianDef.Expression keyExp;
    /** The column or expression which yields the level's ordinal. */
    private final MondrianDef.Expression ordinalExp;
    /** The column or expression which yields the level members' caption. */
    private final MondrianDef.Expression captionExp;
    /** For SQL generator. Whether values of "column" are unique globally
     * unique (as opposed to unique only within the context of the parent
     * member). **/
    private final boolean unique;
    private final int flags;
    private final RolapProperty[] properties;
    private final RolapProperty[] inheritedProperties;

    /**
     * Ths expression which gives the name of members of this level. If null,
     * members are named using the key expression.
     */
    private final MondrianDef.Expression nameExp;
    /** The expression which joins to the parent member in a parent-child
     * hierarchy, or null if this is a regular hierarchy. */
    private final MondrianDef.Expression parentExp;
    /** Value which indicates a null parent in a parent-child hierarchy. */
    private final String nullParentValue;
    /** For a parent-child hierarchy with a closure provided by the schema,
     * the equivalent level in the closed hierarchy; otherwise null */
    private RolapLevel closedPeer;

    /** Condition under which members are hidden. */
    private final HideMemberCondition hideMemberCondition;
    private final MondrianDef.Closure xmlClosure;

    /**
     * Creates a level.
     *
     * @pre parentExp != null || nullParentValue == null
     * @pre properties != null
     * @pre levelType != null
     * @pre hideMemberCondition != null
     */
    RolapLevel(RolapHierarchy hierarchy,
        int depth,
        String name,
        MondrianDef.Expression keyExp,
        MondrianDef.Expression nameExp,
        MondrianDef.Expression captionExp,
        MondrianDef.Expression ordinalExp,
        MondrianDef.Expression parentExp,
        String nullParentValue,
        MondrianDef.Closure xmlClosure,
        RolapProperty[] properties,
        int flags,
        HideMemberCondition
        hideMemberCondition,
        LevelType levelType)
    {
        super(hierarchy, name, depth, levelType);

        Util.assertPrecondition(properties != null, "properties != null");
        Util.assertPrecondition(hideMemberCondition != null,
                "hideMemberCondition != null");
        Util.assertPrecondition(levelType != null, "levelType != null");

        if (keyExp instanceof MondrianDef.Column) {
            checkColumn((MondrianDef.Column) keyExp);
        }

        this.flags = flags;
        final boolean isAll = (flags & ALL) == ALL;
        this.unique = (flags & UNIQUE) == UNIQUE;
        this.keyExp = keyExp;
        if (nameExp != null) {
            if (nameExp instanceof MondrianDef.Column) {
                checkColumn((MondrianDef.Column) nameExp);
            }
        }
        this.nameExp = nameExp;
        if (captionExp != null) {
            if (captionExp instanceof MondrianDef.Column) {
                checkColumn((MondrianDef.Column) captionExp);
            }
        }
        this.captionExp = captionExp;
        if (ordinalExp != null) {
            if (ordinalExp instanceof MondrianDef.Column) {
                checkColumn((MondrianDef.Column) ordinalExp);
            }
            this.ordinalExp = ordinalExp;
        } else {
            this.ordinalExp = this.keyExp;
        }
        this.parentExp = parentExp;
        if (parentExp != null) {
            Util.assertTrue(!isAll, "'All' level '" + this + "' must not be parent-child");
            Util.assertTrue(unique, "Parent-child level '" + this + "' must have uniqueMembers=\"true\"");
        }
        this.nullParentValue = nullParentValue;
        Util.assertPrecondition(parentExp != null || nullParentValue == null,
                "parentExp != null || nullParentValue == null");
        this.xmlClosure = xmlClosure;
        for (int i = 0; i < properties.length; i++) {
            RolapProperty property = properties[i];
            if (property.getExp() instanceof MondrianDef.Column) {
                checkColumn((MondrianDef.Column) property.getExp());
            }
        }
        this.properties = properties;
        List list = new ArrayList();
        for (Level level = this; level != null;
                level = level.getParentLevel()) {
            final Property[] levelProperties = level.getProperties();
            for (int i = 0; i < levelProperties.length; i++) {
                final Property levelProperty = levelProperties[i];
                Property existingProperty = lookupProperty(
                        list, levelProperty.getName());
                if (existingProperty == null) {
                    list.add(levelProperty);
                } else if (existingProperty.getType() !=
                        levelProperty.getType()) {
                    throw Util.newError(
                            "Property " + this.getName() + "." +
                            levelProperty.getName() + " overrides a " +
                            "property with the same name but different type");
                }
            }
        }
        this.inheritedProperties = (RolapProperty[]) list.toArray(
                RolapProperty.emptyArray);

        Dimension dim = hierarchy.getDimension();
        if (dim.getDimensionType() == DimensionType.TimeDimension) {
            if (!levelType.isTime() && !isAll) {
                throw MondrianResource.instance()
                        .NonTimeLevelInTimeHierarchy.ex(getUniqueName());
           }
        } else if (dim.getDimensionType() == null) {
            // there was no dimension type assigned to the dimension
            // - check later
        } else {
            if (levelType.isTime()) {
                throw MondrianResource.instance()
                        .TimeLevelInNonTimeHierarchy.ex(getUniqueName());
            }
        }
        this.hideMemberCondition = hideMemberCondition;
        this.closedPeer = null;
    }

    protected Logger getLogger() {
        return LOGGER;
    }

    String getTableName() {
        String tableName = null;

        MondrianDef.Expression expr = getKeyExp();
        if (expr instanceof MondrianDef.Column) {
            MondrianDef.Column mc = (MondrianDef.Column) expr;
            tableName = mc.getTableAlias();
        }
        return tableName;
    }

    public MondrianDef.Expression getKeyExp() {
        return keyExp;
    }
    MondrianDef.Expression getOrdinalExp() {
        return ordinalExp;

⌨️ 快捷键说明

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