public static void main1(String[] args) throws ClassNotFoundException, SQLException { OlapConnection conn = getConnection(url); CellSet cs = getResultSet(mdx, conn); // CellSetAxis c; int count = 0; if (cs.getAxes().size() > 1) { for (Position row : cs.getAxes().get(1)) { for (Position column : cs.getAxes().get(0)) { for (Member member : row.getMembers()) { System.out.println("rows:" + member.getUniqueName()); } for (Member member : column.getMembers()) { System.out.println("columns:" + member.getUniqueName()); } final Cell cell = cs.getCell(column, row); System.out.println("values:" + cell.getValue()); Position[] positions = new Position[2]; positions[0] = column; positions[1] = row; OlapCell oalpCell = new OlapCell(positions, cell.getValue()); System.out.println("****" + oalpCell.toString()); System.out.println(count++); } } } }
public static void main(String[] args) throws Exception { OlapConnection conn = getConnection(url); CellSet cs = getResultSet(mdx, conn); List<Position> coordinates = new ArrayList<Position>(); List<OlapCell> results = new ArrayList<OlapCell>(); explore(cs.getAxes(), coordinates, cs, results); Gson gson = new Gson(); System.out.println(gson.toJson(results)); }
/** * Prints the rows of cell set. * * @param cellSet Cell set * @param pw Writer * @param axis Axis ordinal * @param pos Partial coordinate */ private static void printRows(CellSet cellSet, PrintWriter pw, int axis, List<Integer> pos) { final CellSetAxis _axis = cellSet.getAxes().get(axis); final List<Position> positions = _axis.getPositions(); final int positionCount = positions.size(); for (int i = 0; i < positionCount; i++) { pos.set(axis, i); if (axis == 0) { int row = axis + 1 < pos.size() ? pos.get(axis + 1) : 0; pw.print("Row #" + row + ": "); printCell(cellSet, pw, pos); pw.println(); } else { printRows(cellSet, pw, axis - 1, pos); } } }
/** * Prints a cell set. * * @param cellSet Cell set * @param pw Writer */ private static void print(CellSet cellSet, PrintWriter pw) { pw.println("Axis #0:"); printAxis(pw, cellSet.getFilterAxis()); final List<CellSetAxis> axes = cellSet.getAxes(); final int axisCount = axes.size(); for (int i = 0; i < axisCount; i++) { CellSetAxis axis = axes.get(i); pw.println("Axis #" + (i + 1) + ":"); printAxis(pw, axis); } // Usually there are 3 axes: {filter, columns, rows}. Position is a // {column, row} pair. We call printRows with axis=2. When it // recurses to axis=-1, it prints. List<Integer> pos = new ArrayList<Integer>(axisCount); for (int i = 0; i < axisCount; i++) { pos.add(-1); } if (axisCount == 0) { printCell(cellSet, pw, pos); } else { printRows(cellSet, pw, axisCount - 1, pos); } }