1 13 package com.tonbeller.jpivot.mondrian; 14 15 import java.util.ArrayList ; 16 import java.util.Iterator ; 17 import java.util.List ; 18 19 import com.tonbeller.jpivot.olap.model.Axis; 20 import com.tonbeller.jpivot.olap.model.impl.FormatStringParser; 21 import com.tonbeller.jpivot.olap.query.ResultBase; 22 import mondrian.olap.Position; 23 import mondrian.olap.Member; 24 import mondrian.olap.MemoryLimitExceededException; 25 26 29 public class MondrianResult extends ResultBase { 30 31 private mondrian.olap.Result monResult = null; 32 private int[] posize; 33 private FormatStringParser formatStringParser = new FormatStringParser(); 34 35 39 protected MondrianResult(mondrian.olap.Result monResult, MondrianModel model) 40 throws MemoryLimitExceededException { 41 super(model); 42 this.monResult = monResult; 43 44 initData(); 45 } 46 47 50 private void initData() throws MemoryLimitExceededException { 51 MondrianModel mmodel = (MondrianModel) model; 52 53 mondrian.olap.Axis[] monAxes = monResult.getAxes(); 54 int nCells = 1; 56 posize = new int[monAxes.length]; 57 for (int i = 0; i < monAxes.length; i++) { 58 List monPositions = monAxes[i].getPositions(); 59 int size = 0; 60 Iterator pit = monPositions.iterator(); 61 while (pit.hasNext()) { 62 Position position = (Position) pit.next(); 63 Iterator mit = position.iterator(); 64 while (mit.hasNext()) { 65 mmodel.addMember((Member) mit.next()); 66 } 67 size++; 68 } 69 mmodel.checkListener(); 71 72 posize[i] = size; 73 nCells = nCells * size; 74 } 75 mondrian.olap.Axis monSlicer = monResult.getSlicerAxis(); 76 List monPositions = monSlicer.getPositions(); 77 Iterator pit = monPositions.iterator(); 78 while (pit.hasNext()) { 79 Position position = (Position) pit.next(); 80 Iterator mit = position.iterator(); 81 while (mit.hasNext()) { 82 mmodel.addMember((Member) mit.next()); 83 } 84 mmodel.checkListener(); 86 } 87 88 axesList = new ArrayList (); 90 for (int i = 0; i < monAxes.length; i++) { 91 axesList.add(new MondrianAxis(i, monAxes[i], mmodel)); 92 mmodel.checkListener(); 94 } 95 slicer = new MondrianAxis(-1, monSlicer, mmodel); 96 97 int[] iar = new int[monAxes.length]; 98 for (int i = 0; i < monAxes.length; i++) { 99 iar[i] = 0; 100 } 101 for (int i = 0; i < nCells; i++) { 102 mondrian.olap.Cell monCell = monResult.getCell(iar); 103 MondrianCell cell = new MondrianCell(monCell, mmodel); 104 cell.setFormattedValue(monCell.getFormattedValue(), formatStringParser); 105 aCells.add(cell); 106 if (nCells > 1) { 107 increment(iar); 109 } 110 111 if (i % 1000 == 0) { 113 mmodel.checkListener(); 114 } 115 } 116 117 } 118 119 125 private void increment(int[] iar) { 126 int nn = ++iar[0]; 127 if (iar.length > 1 && nn >= posize[0]) { 129 iar[0] = 0; 130 for (int i = 1; i < iar.length; i++) { 131 int kk = ++iar[i]; 132 if (kk < posize[i]) 133 break; 134 else 135 iar[i] = 0; 136 } 137 } 138 } 139 140 144 public Axis[] getAxes() { 145 if (monResult == null) 146 return null; return (Axis[]) axesList.toArray(new MondrianAxis[0]); 148 } 149 150 } | Popular Tags |