Example #1
0
  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++);
        }
      }
    }
  }
Example #2
0
 private Cell getCellAt(int axisCoord, int perpAxisCoord) {
   final Position[] positions =
       new Position[] {
         dataAxisInfo.fullPositions.get(axisCoord), totalsAxisInfo.fullPositions.get(perpAxisCoord)
       };
   Cell cell = cellSet.getCell(positions[col], positions[row]);
   return cell;
 }
Example #3
0
  public void setCellValue(
      String queryName, List<Integer> position, String value, String allocationPolicy) {
    try {

      IQuery query = getIQuery(queryName);
      OlapConnection con =
          olapDiscoverService.getNativeConnection(query.getSaikuCube().getConnectionName());

      Scenario s;
      if (query.getScenario() == null) {
        s = con.createScenario();
        query.setScenario(s);
        con.setScenario(s);
        System.out.println("Created scenario:" + s + " : cell:" + position + " value" + value);
      } else {
        s = query.getScenario();
        con.setScenario(s);
        System.out.println("Using scenario:" + s + " : cell:" + position + " value" + value);
      }

      CellSet cs1 = query.execute();
      query.storeCellset(cs1);

      Object v = null;
      try {
        v = Integer.parseInt(value);
      } catch (Exception e) {
        v = Double.parseDouble(value);
      }
      if (v == null) {
        throw new SaikuServiceException("Error setting value of query " + queryName + " to:" + v);
      }

      allocationPolicy = AllocationPolicy.EQUAL_ALLOCATION.toString();

      AllocationPolicy ap = AllocationPolicy.valueOf(allocationPolicy);
      CellSet cs = query.getCellset();
      cs.getCell(position).setValue(v, ap);
      con.setScenario(null);
    } catch (Exception e) {
      throw new SaikuServiceException("Error setting value: " + queryName, e);
    }
  }
Example #4
0
  // coordinates.size should be 0 at very first
  public static void explore(
      List<CellSetAxis> axes, List<Position> coordinates, CellSet cs, List<OlapCell> cellList) {
    int level = coordinates.size();
    // System.out.println(level + "  " + axes.size());
    if (level < axes.size()) {
      for (Position p : axes.get(level).getPositions()) {
        coordinates.add(p);
        explore(axes, coordinates, cs, cellList);
      }

      if (level > 0) {
        coordinates.remove(level - 1);
      }

    } else {
      Position[] positions = new Position[coordinates.size()];
      positions = coordinates.toArray(positions);
      Cell cell = cs.getCell(positions);
      OlapCell olapCell = new OlapCell(positions, cell.getValue());
      cellList.add(olapCell);
      // System.out.println((++count) + " " + olapCell.toString());
      coordinates.remove(level - 1);
    }
  }
 /**
  * Prints the formatted value of a Cell at a given position.
  *
  * @param cellSet Cell set
  * @param pw Print writer
  * @param pos Cell coordinates
  */
 private static void printCell(CellSet cellSet, PrintWriter pw, List<Integer> pos) {
   Cell cell = cellSet.getCell(pos);
   pw.print(cell.getFormattedValue());
 }