public Iterator<Cell> iterator() { final int[] axisDimensions = new int[cellSet.getAxes().size() - pageCoords.length]; assert pageCoords.length <= axisDimensions.length; for ( int i = 0; i < axisDimensions.length; i++ ) { final CellSetAxis axis = cellSet.getAxes().get( i ); axisDimensions[i] = axis.getPositions().size(); final CoordinateIterator coordIter = new CoordinateIterator( axisDimensions, true ); return new Iterator<Cell>() { public boolean hasNext() {
/** * Computes a description of an axis. * * @param axis * Axis * @return Description of axis */ private AxisInfo computeAxisInfo( final CellSetAxis axis ) { if ( axis == null ) { return new AxisInfo( 0 ); } final AxisInfo axisInfo = new AxisInfo( axis.getAxisMetaData().getHierarchies().size() ); int p = -1; for ( final Position position : axis.getPositions() ) { ++p; int k = -1; for ( final Member member : position.getMembers() ) { ++k; final AxisOrdinalInfo axisOrdinalInfo = axisInfo.ordinalInfos.get( k ); final int topDepth = member.isAll() ? member.getDepth() : member.getHierarchy().hasAll() ? 1 : 0; if ( axisOrdinalInfo.minDepth > topDepth || p == 0 ) { axisOrdinalInfo.minDepth = topDepth; } axisOrdinalInfo.maxDepth = Math.max( axisOrdinalInfo.maxDepth, member.getDepth() ); } } return axisInfo; }
for ( int i = 0; i < axis.getPositions().size(); i++ ) { final int x = offset + i; final Position position = axis.getPositions().get( i ); int yOffset = 0; final List<Member> memberList = position.getMembers(); if ( member.getDepth() < ordinalInfo.minDepth ) { break; final int y = yOffset + member.getDepth() - ordinalInfo.minDepth; members[y] = member; member = member.getParentMember(); final Member member = members[y]; final List<String> memberPath = new ArrayList<String>(); for ( int z = 0; z <= position.getMembers().size() - 1; z++ ) { if ( i < axis.getPositions().size() - 1 ) { if ( axis.getPositions().get( i + 1 ).getMembers().get( z ).getParentMember() != null && axis.getPositions().get( i + 1 ).getMembers().get( z ).getParentMember().equals( member ) ) { if ( member == null || position.getMembers().get( z ).getUniqueName().equals( member.getUniqueName() ) ) { break; memberPath.add( position.getMembers().get( z ).getUniqueName() ); memberPath.add( member.getUniqueName() ); same = same && i > 0 && Olap4jUtil.equal( prevMembers[y], member );
public void openQuery() throws Exception { Class.forName( olap4jDriver ); OlapConnection connection = null; if ( Utils.isEmpty( username ) && Utils.isEmpty( password ) ) { connection = (OlapConnection) DriverManager.getConnection( olap4jUrl ); } else { connection = (OlapConnection) DriverManager.getConnection( olap4jUrl, username, password ); } OlapWrapper wrapper = connection; olapConnection = wrapper.unwrap( OlapConnection.class ); try { if ( !Utils.isEmpty( catalogName ) ) { olapConnection.setCatalog( catalogName ); } } catch ( SQLException e ) { throw new OlapException( "Error setting catalog for MDX statement: '" + catalogName + "'" ); } OlapStatement stmt = olapConnection.createStatement(); if ( !Utils.isEmpty( mdx ) ) { CellSet tmp = stmt.executeOlapQuery( mdx ); result = tmp; } else { throw new Exception( "Error executing empty MDX query" ); } }
new Matrix( xOffsset + ( columnsAxis == null ? 1 : columnsAxis.getPositions().size() ), yOffset + ( rowsAxis == null ? 1 : rowsAxis.getPositions().size() ) ); final List<Integer> coordList = cell.getCoordinateList(); int x = xOffsset; if ( coordList.size() > 0 ) { if ( cell.getValue() != null ) { if ( cell.getValue() instanceof Number ) { cellInfo.setRawNumber( (Number) cell.getValue() ); String cellValue = cell.getFormattedValue(); // First try to get a final Object value = cell.getValue(); if ( value == null || value.equals( "null" ) ) { cellValue = ""; try { DecimalFormat myFormatter = new DecimalFormat( "#,###.###" ); String output = myFormatter.format( cell.getValue() ); cellValue = output; } catch ( Exception e ) {
public Matrix format( final CellSet cellSet ) { if ( cellSet.getAxes().size() > 0 ) { columnsAxis = cellSet.getAxes().get( 0 ); } else { columnsAxis = null; if ( cellSet.getAxes().size() > 1 ) { rowsAxis = cellSet.getAxes().get( 1 ); } else { rowsAxis = null; if ( cellSet.getAxes().size() > 2 ) { final int[] dimensions = new int[cellSet.getAxes().size() - 2]; for ( int i = 2; i < cellSet.getAxes().size(); i++ ) { final CellSetAxis cellSetAxis = cellSet.getAxes().get( i ); dimensions[i - 2] = cellSetAxis.getPositions().size(); for ( final int[] pageCoords : CoordinateIterator.iterate( dimensions ) ) { matrix = formatPage( cellSet, pageCoords, columnsAxis, columnsAxisInfo, rowsAxis, rowsAxisInfo );
private void recurse( SaxWriter writer, List<Integer> pos, int axisOrdinal, int[] cellOrdinal) { if (axisOrdinal < 0) { emitCell(writer, pos, cellOrdinal[0]++); } else { CellSetAxis axis = cellSet.getAxes().get(axisOrdinal); List<Position> positions = axis.getPositions(); for (int i = 0, n = positions.size(); i < n; i++) { pos.set(axisOrdinal, i); recurse(writer, pos, axisOrdinal - 1, cellOrdinal); } } }
public void close() throws SQLException { cellSet.getStatement().getConnection().close(); }
public String getName(Object axisMetaData) { return ((CellSetAxisMetaData)axisMetaData) .getAxisOrdinal().name(); } };
public void flushSchemaCache(OlapConnection conn) throws OlapException { try { RolapConnection rConn = conn.unwrap(RolapConnection.class); rConn.getCacheControl(null).flushSchema( rConn.getSchema()); } catch (SQLException e) { throw new OlapException(e); } }
OlapException createException(String msg) { return new OlapException(msg); }
/** * Creates an exception in the context of a particular Cell. * * @param context Cell context for exception * @param msg Message * @return New exception */ OlapException createException(Cell context, String msg) { OlapException exception = new OlapException(msg); exception.setContext(context); return exception; }
protected MDDataSet_Multidimensional( CellSet cellSet, boolean omitDefaultSlicerInfo, boolean json) throws SQLException { super(cellSet); this.omitDefaultSlicerInfo = omitDefaultSlicerInfo; this.json = json; this.extra = getExtra(cellSet.getStatement().getConnection()); }
public Cell getCell(Position... positions) { int[] coords = new int[positions.length]; for (int i = 0; i < coords.length; i++) { coords[i] = positions[i].getOrdinal(); } return getCellInternal(coords); }
public ResultSet executeDrillthrough( OlapStatement olapStatement, String mdx, boolean advanced, String tabFields, int[] rowCountSlot) throws SQLException { return olapStatement.executeQuery(mdx); }
private List<Property> getProps(CellSetAxisMetaData queryAxis) { if (queryAxis == null) { return defaultProps; } return CompositeList.of( defaultProps, queryAxis.getProperties()); }
/** * Shorthand for catalog.database.connection.getLocale(). * Not part of the olap4j api; do not make public. * * @return Locale of current connection */ final Locale getLocale() { return olap4jCatalog.olap4jDatabase.getOlapConnection().getLocale(); }
/** * Converts a SQLException to an OlapException. Casts the exception * if it is already an OlapException, wraps otherwise. * * <p>This method is typically used as an adapter for SQLException * instances coming from a base class, where derived interface declares * that it throws the more specific OlapException. * * @param e Exception * @return Exception as an OlapException */ public OlapException toOlapException(SQLException e) { if (e instanceof OlapException) { return (OlapException) e; } else { return new OlapException(null, e); } } }
public Object getMemberKey(Member m) throws OlapException { try { return ((MondrianOlap4jMember)m) .unwrap(RolapMemberBase.class).getKey(); } catch (SQLException e) { throw new OlapException(e); } }