Java源码示例:mondrian.olap.MondrianDef

示例1
/**
 * Get the Dimension that includes the level
 *
 * @param level
 * @return the dimension that includes the level
 */
public MondrianDef.CubeDimension getMondrianDimension(Level level) {

	logger.debug("IN");

	String dimension = level.getDimension().getName();
	MondrianDef.CubeDimension[] dimensons = editCube.dimensions;
	for (int i = 0; i < dimensons.length; i++) {
		MondrianDef.CubeDimension aDimension = dimensons[i];
		if (aDimension.name.equals(dimension)) {
			logger.debug("OUT");
			return aDimension;
		}
	}

	logger.error("Impossible to find the dimension for the level " + level.getUniqueName());
	throw new SpagoBIEngineRuntimeException("Impossible to find the dimension for the level " + level.getUniqueName());
}
 
示例2
/**
 * Gets the hierarchy of the level inside the passed dimension
 *
 * @param level
 * @param thisDimension
 * @return the hierarchy of the level inside the passed dimension
 */
public MondrianDef.Hierarchy getMondrianHierarchy(Level level, Dimension thisDimension) {
	logger.debug("IN");
	String hierarchy = level.getHierarchy().getName();
	MondrianDef.Hierarchy[] thisHierarchies = thisDimension.hierarchies;
	for (int j = 0; j < thisHierarchies.length; j++) {
		MondrianDef.Hierarchy aHierarchy = thisHierarchies[j];
		if (aHierarchy.name == null || aHierarchy.name.equals(hierarchy)) {
			logger.debug("OUT");
			return aHierarchy;
		}

	}
	logger.error("Impossible to find the hierarchy for the level " + level.getUniqueName());
	throw new SpagoBIEngineRuntimeException("Impossible to find the hierarchy for the level " + level.getUniqueName());
}
 
示例3
/**
 * Gets the first n levels of a hierarchy
 *
 * @param levelsDepth
 *            the number of levels to get
 * @param aHierarchy
 * @return the first "levelsDepth" levels of aHierarchy
 */
public List<MondrianDef.Level> getLevels(Level memberLevel, MondrianDef.Hierarchy aHierarchy) {
	logger.debug("IN");
	List<MondrianDef.Level> levelColumns = new ArrayList<MondrianDef.Level>();

	if (memberLevel.getName().equals(ALL_MEMBER_NAME)) {
		logger.debug("All member for Hierarchy " + aHierarchy.getName());
	} else {
		MondrianDef.Level[] schemaLevels = aHierarchy.levels;
		int i = 0;

		while (true) {
			MondrianDef.Level aMondrianLevel = schemaLevels[i];
			levelColumns.add(aMondrianLevel);
			if (aMondrianLevel.name.equals(memberLevel.getName())) {
				break;
			}
			i++;
		}
	}

	logger.debug("OUT");
	return levelColumns;
}
 
示例4
public List<TableEntry> getLevels() {
	if (levels == null) {
		levels = new ArrayList<TableEntry>();
		MondrianDef.Level[] schemaLevels = hieararchy.levels;

		for (int i = 0; i < schemaLevels.length; i++) {
			MondrianDef.Level aLevel = schemaLevels[i];

			String table = aLevel.table;
			if (table == null) {
				table = MondrianSchemaRetriver.getTableName(hieararchy);
			}
			levels.add(new TableEntry(aLevel.column, table));

		}
	}
	return levels;
}
 
示例5
private String makeAlias(
    final RolapStar.Column column,
    final List<String> columnNames,
    final Set<String> columnNameSet)
{
    String columnName = column.getName();
    if (columnName != null) {
        // nothing
    } else if (column.getExpression() instanceof MondrianDef.Column) {
        columnName = ((MondrianDef.Column) column.getExpression()).name;
    } else {
        columnName = "c" + Integer.toString(columnNames.size());
    }
    // Register the column name, and if it's not unique, append numeric
    // suffixes until it is. Also make sure that it is within the
    // range allowed by this SQL dialect.
    String originalColumnName = columnName;
    if (columnName.length() > maxColumnNameLength) {
        columnName = columnName.substring(0, maxColumnNameLength);
    }
    for (int j = 0; !columnNameSet.add(columnName); j++) {
        final String suffix = "_" + Integer.toString(j);
        columnName = originalColumnName;
        if (originalColumnName.length() + suffix.length()
            > maxColumnNameLength)
        {
            columnName =
                originalColumnName.substring(
                    0, maxColumnNameLength - suffix.length());
        }
        columnName += suffix;
    }

    return columnName;
}
 
示例6
public List<String> getAllCubes() {
	List<String> cubesList = new ArrayList<String>();
	MondrianDef.Cube[] cubes = schema.cubes;
	MondrianDef.VirtualCube[] virtualCubes = schema.virtualCubes;
	for (int i = 0; i < cubes.length; i++) {
		cubesList.add(cubes[i].name);

	}
	for (int i = 0; i < virtualCubes.length; i++) {
		cubesList.add(virtualCubes[i].name);
	}
	return cubesList;
}
 
示例7
public List<String> getCubes() {
	List<String> cubesList = new ArrayList<String>();
	MondrianDef.Cube[] cubes = schema.cubes;
	MondrianDef.VirtualCube[] virtualCubes = schema.virtualCubes;
	for (int i = 0; i < cubes.length; i++) {
		cubesList.add(cubes[i].name);

	}
	
	return cubesList;
}
 
示例8
/**
 * For each level starting from the root to the Get the map between the
 * hierarchy of the member( root member, child, granchild, .... member) and
 * the level. We need this information because we want to know table and
 * column linked to the members
 *
 * @param member
 * @param mondrianHierarchy
 * @return the map Level-->Member of the level
 */
public Map<TableEntry, Member> getMemberColumnMap(Member member, MondrianDef.Hierarchy mondrianHierarchy) {

	logger.debug("IN");

	Map<TableEntry, Member> mapTableEntryValue = new HashMap<TableEntry, Member>();
	// int memberDepth = member.getDepth();
	Level memberLevel = member.getLevel();

	// get all the levels starting from the root to the one that contains
	// the passed member
	List<MondrianDef.Level> memberValues = getLevels(memberLevel, mondrianHierarchy);

	// Create a Map that links the member with the level that contains it
	Member aMember = member;
	for (int i = memberValues.size() - 1; i >= 0; i--) {
		MondrianDef.Level aLevel = memberValues.get(i);
		String table = aLevel.table;
		if (table == null) {
			table = getTableName(mondrianHierarchy);
		}
		mapTableEntryValue.put(new TableEntry(aLevel.column, table), aMember);
		aMember = aMember.getParentMember();
	}

	logger.debug("OUT");
	return mapTableEntryValue;
}
 
示例9
/**
 * Returns physical name of all columns of edit cube
 *
 * @return columns names list
 */

public List<String> getColumnNamesList() {
	logger.debug("IN");
	List<String> toReturn = new ArrayList<String>();

	// add measures names
	MondrianDef.Measure[] measures = editCube.measures;
	for (int i = 0; i < measures.length; i++) {
		Measure measure = measures[i];
		if (measure.column != null && !measure.column.equalsIgnoreCase("")) {
			toReturn.add(measure.column);
		}
	}

	// add dimension names
	MondrianDef.CubeDimension[] dimensions = editCube.dimensions;
	for (int i = 0; i < dimensions.length; i++) {
		CubeDimension dimensione = dimensions[i];
		if (dimensione.foreignKey != null && !dimensione.foreignKey.equalsIgnoreCase("")) {
			toReturn.add(dimensione.foreignKey);
		}
	}

	logger.debug("OUT");
	return toReturn;
}
 
示例10
public String getVersionColumnName() {
	;
	logger.debug("IN");
	if (versionColumnName != null) {
		logger.debug("Version column name is in the cache");
		return versionColumnName;
	}
	logger.debug("Version column name isn't in the cache");
	String dimension = WhatIfConstants.VERSION_DIMENSION_NAME;
	Dimension thisDimension = null;
	MondrianDef.CubeDimension[] dimensons = editCube.dimensions;
	for (int i = 0; i < dimensons.length; i++) {
		MondrianDef.CubeDimension aDimension = dimensons[i];
		if (aDimension.name.equals(dimension)) {
			thisDimension = aDimension.getDimension(schema);
			break;
		}
	}
	if (thisDimension == null) {
		logger.error("Error loading the verison dimension " + WhatIfConstants.VERSION_DIMENSION_NAME);
		throw new SpagoBIEngineRuntimeException("Error loading the verison dimension " + WhatIfConstants.VERSION_DIMENSION_NAME);
	}
	MondrianDef.Hierarchy thisHierarchy = thisDimension.hierarchies[0];
	versionColumnName = thisHierarchy.levels[0].column;

	logger.debug("OUT");

	return versionColumnName;

}
 
示例11
public String getVersionTableName() {
	;
	logger.debug("IN");
	if (versionTableName != null) {
		logger.debug("Version table name is in the cache");
		return versionTableName;
	}
	logger.debug("Version table name isn't in the cache");
	String dimension = WhatIfConstants.VERSION_DIMENSION_NAME;
	Dimension thisDimension = null;
	MondrianDef.CubeDimension[] dimensons = editCube.dimensions;
	for (int i = 0; i < dimensons.length; i++) {
		MondrianDef.CubeDimension aDimension = dimensons[i];
		if (aDimension.name.equals(dimension)) {
			thisDimension = aDimension.getDimension(schema);
			break;
		}
	}
	if (thisDimension == null) {
		logger.error("Error loading the verison dimension " + WhatIfConstants.VERSION_DIMENSION_NAME);
		throw new SpagoBIEngineRuntimeException("Error loading the verison dimension " + WhatIfConstants.VERSION_DIMENSION_NAME);
	}
	MondrianDef.Hierarchy thisHierarchy = thisDimension.hierarchies[0];
	versionTableName = getTableName(thisHierarchy);

	logger.debug("OUT");

	return versionTableName;

}
 
示例12
public static String getTableName(MondrianDef.Hierarchy hierarchy) {
	String tableName = hierarchy.primaryKeyTable;
	if (tableName == null) {
		NodeDef[] children = hierarchy.getChildren();
		for (int i = 0; i < children.length; i++) {
			NodeDef node = children[i];
			if (node instanceof MondrianDef.Table) {
				tableName = ((MondrianDef.Table) node).name;
				break;
			}
		}
	}
	return tableName;
}
 
示例13
public EquiJoin getInnerDimensionJoinConditions() {
	MondrianDef.RelationOrJoin relOrJoin = getHieararchy().relation;
	if (relOrJoin instanceof MondrianDef.Join) {
		MondrianDef.Join join = (MondrianDef.Join) relOrJoin;
		MondrianDef.Table leftT = (MondrianDef.Table) join.left;
		MondrianDef.Table rightT = (MondrianDef.Table) join.right;
		TableEntry leftTable = new TableEntry(join.leftKey, leftT.name);
		TableEntry rightTable = new TableEntry(join.rightKey, rightT.name);
		return new EquiJoin(leftTable, rightTable);
	}
	return null;
}
 
示例14
public static List<ValidationMessage> validateCube(String catalogUrl, String cubeName, java.sql.Connection conn,
    List<MondrianSchemaValidator> validators) {
  MondrianDef.Schema schema = loadSchema(catalogUrl);
  MondrianDef.Cube cube = getCubeByName(schema, cubeName);
  MondrianSchemaValidatorManager man = new MondrianSchemaValidatorManager();
  man.setValidators(validators);
  List<ValidationMessage> messages = man.validateCube(schema, cube, conn);
  return messages;
}
 
示例15
public static Cube getCubeByName(MondrianDef.Schema schema, String name) {
  for (Cube cube : schema.cubes) {
    if (cube.name.equals(name)) {
      return cube;
    }
  }
  return null;
}
 
示例16
public String generateFull(Schema schema, List<? extends Output> outputs) {
    try {
        MondrianDef.Schema schemaDef = (MondrianDef.Schema)((RolapSchema)((MondrianSchema)schema).getRolapConnection().getSchema()).getXMLSchema().deepCopy();
        
        // locate the cube
        MondrianDef.Cube currentCube = null;
        for (MondrianDef.Cube cube : schemaDef.cubes) {
            if (cube.name.equals(((MondrianSchema)schema).getRolapCube().getName())) {
                currentCube = cube;
                break;
            }
        }
        
        if (!(currentCube.fact instanceof MondrianDef.Table)) {
            throw new RuntimeException("Fact Table must be of type TABLE");
        }

        MondrianDef.Table factTable = (MondrianDef.Table)currentCube.fact;

        List<MondrianDef.AggTable> aggTables = new ArrayList<MondrianDef.AggTable>();
        if (factTable.aggTables != null) {
            for (MondrianDef.AggTable aggTable : factTable.aggTables) {
                aggTables.add(aggTable);
            }
        }
        
        for (Output output : outputs) {
            aggTables.add(generateMondrianDef(schema, output));
        }
        
        factTable.aggTables = (MondrianDef.AggTable[])aggTables.toArray(new MondrianDef.AggTable[0]);
        return schemaDef.toXML();
    } catch (XOMException e) {
        e.printStackTrace();
    }
    return null;
    
}
 
示例17
public IMemberCoordinates getMemberCordinates(Member member) {
	logger.debug("IN");

	// get the dimension for the member
	MondrianDef.CubeDimension mondrianDimension = getMondrianDimension(member.getLevel());

	// get the hierarchy of the level
	MondrianDef.Hierarchy mondrianHierarchy = getMondrianHierarchy(member.getLevel(), mondrianDimension.getDimension(schema));

	// For each level starting from the root to the Get the map between the
	// hierarchy of the member( root member, child, granchild, .... member)
	// and the level
	Map<TableEntry, Member> mapTableEntryValue = getMemberColumnMap(member, mondrianHierarchy);

	logger.debug("OUT");

	return new MondrianMemberCoordinates(mondrianDimension, mondrianHierarchy, mapTableEntryValue);

}
 
示例18
public MondrianDef.CubeDimension getDimension() {
	return dimension;
}
 
示例19
public void setDimension(MondrianDef.CubeDimension dimension) {
	this.dimension = dimension;
}
 
示例20
public MondrianDef.Hierarchy getHieararchy() {
	return hieararchy;
}
 
示例21
public void setHieararchy(MondrianDef.Hierarchy hieararchy) {
	this.hieararchy = hieararchy;
}
 
示例22
private MondrianDef.AggName generateMondrianDef(Schema schema, Output output) {
    
    AggregateTableOutput tableOutput = (AggregateTableOutput)output;

    MondrianDef.AggName aggName = new MondrianDef.AggName();
    aggName.name = tableOutput.getTableName();
            
    List<MondrianDef.AggMeasure> measures = new ArrayList<MondrianDef.AggMeasure>();
    List<MondrianDef.AggLevel> levels = new ArrayList<MondrianDef.AggLevel>();
    
    int i = -1;
    
    for (AggregateTableOutput.ColumnOutput column : tableOutput.getColumnOutputs()) {
        ++i;
        String columnName = column.getName();
        Attribute attribute = column.getAttribute();
        if (attribute instanceof Measure) {
            Measure measure = (Measure)attribute;
            RolapStar.Measure rolapStarMeasure = ((MondrianMeasure)measure).getRolapStarMeasure();

            if (rolapStarMeasure.getName().equals("fact_count")) {
                // add as fact count
                MondrianDef.AggFactCount aggFactCount = new MondrianDef.AggFactCount();
                aggFactCount.column = columnName;
                aggName.factcount = aggFactCount;
            } else {
                // add as regular measure
                RolapMeasure rolapMeasure = findRolapMeasure(schema, measure);
                MondrianDef.AggMeasure measureDef = new MondrianDef.AggMeasure();
                measureDef.name = rolapMeasure.getUniqueName();
                measureDef.column = columnName;
                measures.add(measureDef);
            }
            
        } else {
            Level level = findLevel(schema, attribute);
            RolapCubeLevel rolapLevel = ((MondrianLevel)level).getRolapCubeLevel();
            
            MondrianDef.AggLevel levelDef = new MondrianDef.AggLevel();
            levelDef.name = rolapLevel.getUniqueName();
            levelDef.column = columnName;
            levels.add(levelDef);
        }
    }
    
    aggName.levels = (MondrianDef.AggLevel[])levels.toArray(new MondrianDef.AggLevel[0]);
    aggName.measures = (MondrianDef.AggMeasure[])measures.toArray(new MondrianDef.AggMeasure[0]);
    
    return aggName;
}
 
示例23
/**
 * Validates a cube.
 * @param schema schema containing cube
 * @param cube cube to validate
 * @param conn connection to use
 * @return a list of messages
 */
List<ValidationMessage> validateCube(MondrianDef.Schema schema, MondrianDef.Cube cube, java.sql.Connection conn);