我正在对一个使用Mondrian OLAP引擎和Olap4j的应用程序做一点规划,应该向用户呈现/显示数据。我理解所有后端的东西,但是我不确定我应该如何在视图层中显示数据。
例如,olap4j有一个格式化程序,可以很好地将SELECT打印到控制台中。
我从olap4j得到的数据在视图层中是如何显示的?我刚刚浏览了olap4j应用程序接口,似乎没有任何东西可以将结果转换为可以进一步处理和显示的表单。这一过程是Pentaho解决方案的一部分吗?因此,否则,仅仅从Mondrian OLAP引擎和olap4j呈现数据真的不容易吗?
编辑:我习惯于从数据库获取一些数据到我的DTO中,并将其显示在视图层中。但是如何为如此复杂的结果集创建do呢?
发布于 2011-02-17 03:04:21
你可以创建你自己的视图层,只是有点棘手。
OlapStatement.executeOlapQuery()返回一个CellSet,您必须使用它。也请阅读specifications,它是一个很好的信息来源。
这里有一个例子,它创建了List<List<MyCell>> (不是最好的表示,但很容易理解它的工作原理)。这将创建一个类似于http://www.olap4j.org/api/index.html?org/olap4j/Position.html的表(没有“性别”和“产品”标签)。
private final static int COLUMNS = 0; //see Cellset javadoc
private final static int ROWS= 1; //see Cellset javadoc
/**
* Outer list: rows, inner list: elements in a row
*/
private List<List<MyCell>> getListFromCellSet(CellSet cellSet) {
List<List<MyCell>> toReturn= new ArrayList<List<MyCell>>();
//Column header
//See http://www.olap4j.org/api/index.html?org/olap4j/Position.html on how Position works, it helps a lot
//Every position will be a column in the header
for (Position pos : cellSet.getAxes().get(COLUMNS).getPositions()) {
for (int i = 0; i < pos.getMembers().size(); i++) {
if (toReturn.size() <= i) {
toReturn.add(i, new ArrayList<MyCell>());
}
Member m = pos.getMembers().get(i);
MyCell myCell = new MyCell(m); //use m.getCaption() for display
toReturn.get(i).add(myCell );
}
}
//Put empty elements to the beginning of the list, so there will be place for the rows header
if (cellSet.getAxes().get(ROWS).getPositions().size() > 0) {
for (int count=0; count < cellSet.getAxes().get(1).getPositions().get(0).getMembers().size(); count++) {
for (int i = 0; i < toReturn.size(); i++) {
toReturn.get(i).add(0, new MyCell());
}
}
}
//Content + row header
for(int i = 0; i < cellSet.getAxes().get(ROWS).getPositionCount(); i++) {
List<MyCell> row = new ArrayList<MyCell>();
//Header
for (org.olap4j.metadata.Member m : cellSet.getAxes().get(ROWS).getPositions().get(i).getMembers()) {
row.add(new MyCell(m));
}
//Content
for (int j = 0; j < cellSet.getAxes().get(COLUMNS).getPositionCount(); j++) {
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(j); //coordinte
list.add(i); //coordinte
row.add(new MyCell(cellSet.getCell(list))); //use cell.getFormattedValue() for display
}
toReturn.add(row);
}
return toReturn;
}使用以下构造函数创建MyCell类:
public class MyCell {
...
public MyCell(){...}
public MyCell(Member m){...}
public MyCell(Cell c){...}
}别忘了显示过滤器,为此使用Cellset.getFilterAxis()。
您也可以在SourceForge上检查Rectangular格式化程序,但它有点长。
https://stackoverflow.com/questions/4893993
复制相似问题