1 10 package mondrian.rolap; 11 12 import mondrian.olap.*; 13 import mondrian.rolap.agg.AggregationManager; 14 import mondrian.rolap.agg.CellRequest; 15 16 import java.sql.*; 17 18 22 class RolapCell implements Cell { 23 private final RolapResult result; 24 protected final int[] pos; 25 protected RolapResult.CellInfo ci; 26 27 RolapCell(RolapResult result, int[] pos, RolapResult.CellInfo ci) { 28 this.result = result; 29 this.pos = pos; 30 this.ci = ci; 31 } 32 33 public Object getValue() { 34 return ci.value; 35 } 36 37 public String getCachedFormatString() { 38 return ci.formatString; 39 } 40 41 public String getFormattedValue() { 42 return ci.getFormatValue(); 43 } 44 45 public boolean isNull() { 46 return (ci.value == Util.nullValue); 47 } 48 49 public boolean isError() { 50 return (ci.value instanceof Throwable ); 51 } 52 53 61 public String getDrillThroughSQL(boolean extendedContext) { 62 RolapAggregationManager aggMan = AggregationManager.instance(); 63 final Member[] currentMembers = getMembers(); 64 CellRequest cellRequest = RolapAggregationManager.makeRequest( 65 currentMembers, extendedContext, true); 66 return (cellRequest == null) 67 ? null 68 : aggMan.getDrillThroughSql(cellRequest, false); 69 } 70 71 72 public int getDrillThroughCount() { 73 RolapAggregationManager aggMan = AggregationManager.instance(); 74 final Member[] currentMembers = getMembers(); 75 CellRequest cellRequest = RolapAggregationManager.makeRequest( 76 currentMembers, false, true); 77 if (cellRequest == null) { 78 return -1; 79 } 80 RolapConnection connection = 81 (RolapConnection) result.getQuery().getConnection(); 82 final String sql = aggMan.getDrillThroughSql(cellRequest, true); 83 final SqlStatement stmt = 84 RolapUtil.executeQuery( 85 connection.getDataSource(), 86 sql, 87 "RolapCell.getDrillThroughCount", 88 "Error while counting drill-through"); 89 try { 90 ResultSet rs = stmt.getResultSet(); 91 rs.next(); 92 ++stmt.rowCount; 93 return rs.getInt(1); 94 } catch (SQLException e) { 95 throw stmt.handle(e); 96 } finally { 97 stmt.close(); 98 } 99 } 100 101 108 public boolean canDrillThrough() { 109 final Member[] currentMembers = getMembers(); 111 return (currentMembers[0] instanceof RolapStoredMeasure); 114 } 115 116 private RolapEvaluator getEvaluator() { 117 return result.getCellEvaluator(pos); 118 } 119 private Member[] getMembers() { 120 return result.getCellMembers(pos); 121 } 122 123 public Object getPropertyValue(String propertyName) { 124 Property property = Property.lookup(propertyName, true); 125 Object defaultValue = null; 126 if (property != null) { 127 switch (property.ordinal) { 128 case Property.CELL_ORDINAL_ORDINAL: 129 return result.getCellOrdinal(pos); 130 case Property.VALUE_ORDINAL: 131 return getValue(); 132 case Property.FORMAT_STRING_ORDINAL: 133 if (ci.formatString == null) { 134 ci.formatString = getEvaluator().getFormatString(); 135 } 136 return ci.formatString; 137 case Property.FORMATTED_VALUE_ORDINAL: 138 return getFormattedValue(); 139 case Property.FONT_FLAGS_ORDINAL: 140 defaultValue = 0; 141 break; 142 case Property.SOLVE_ORDER_ORDINAL: 143 defaultValue = 0; 144 break; 145 default: 146 } 148 } 149 return getEvaluator().getProperty(propertyName, defaultValue); 150 } 151 152 public Member getContextMember(Dimension dimension) { 153 return result.getMember(pos, dimension); 154 } 155 } 156 157 | Popular Tags |