Exemple #1
0
  public ResultSet drillthrough(
      String queryName, List<Integer> cellPosition, Integer maxrows, String returns) {
    OlapStatement stmt = null;
    try {
      IQuery query = getIQuery(queryName);
      CellSet cs = query.getCellset();
      SaikuCube cube = getQuery(queryName).getCube();
      final OlapConnection con = olapDiscoverService.getNativeConnection(cube.getConnectionName());
      stmt = con.createStatement();

      String select = null;
      StringBuffer buf = new StringBuffer();
      buf.append("SELECT (");
      for (int i = 0; i < cellPosition.size(); i++) {
        List<Member> members =
            cs.getAxes().get(i).getPositions().get(cellPosition.get(i)).getMembers();
        for (int k = 0; k < members.size(); k++) {
          Member m = members.get(k);
          if (k > 0 || i > 0) {
            buf.append(", ");
          }
          buf.append(m.getUniqueName());
        }
      }
      buf.append(") ON COLUMNS \r\n");
      buf.append("FROM " + cube.getCubeName() + "\r\n");

      SelectNode sn = (new DefaultMdxParserImpl().parseSelect(getMDXQuery(queryName)));
      final Writer writer = new StringWriter();
      sn.getFilterAxis().unparse(new ParseTreeWriter(new PrintWriter(writer)));
      if (StringUtils.isNotBlank(writer.toString())) {
        buf.append("WHERE " + writer.toString());
      }
      select = buf.toString();
      if (maxrows > 0) {
        select = "DRILLTHROUGH MAXROWS " + maxrows + " " + select + "\r\n";
      } else {
        select = "DRILLTHROUGH " + select + "\r\n";
      }
      if (StringUtils.isNotBlank(returns)) {
        select += "\r\n RETURN " + returns;
      }

      log.debug("Drill Through for query (" + queryName + ") : \r\n" + select);
      ResultSet rs = stmt.executeQuery(select);
      return rs;
    } catch (Exception e) {
      throw new SaikuServiceException("Error DRILLTHROUGH: " + queryName, e);
    } finally {
      try {
        if (stmt != null) stmt.close();
      } catch (Exception e) {
      }
    }
  }
  public SelectNode apply(SelectNode sn) {
    // do a deep copy of the existing query SelectNode before
    // modifying it:
    SelectNode newSelectNode = sn.deepCopy();

    for (AxisNode an : newSelectNode.getAxisList()) {
      if (an.getAxis() == axis) {
        // this is the axis we're drilling

        ParseTreeNode initialAxisExp = an.getExpression();

        // apply the drill operation
        ParseTreeNode newAxisExp = processAxisExp(initialAxisExp);

        // replace the expression in the axis by the new generated one
        an.setExpression(newAxisExp);
      }
    }
    return newSelectNode;
  }