예제 #1
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);
    }
  }
예제 #2
0
  public CellDataSet execute(String queryName, ICellSetFormatter formatter) {
    String runId = "runId:" + ID_GENERATOR.getAndIncrement();
    try {
      //			System.out.println("Execute: ID " + Thread.currentThread().getId() + " Name: " +
      // Thread.currentThread().getName());
      IQuery query = getIQuery(queryName);
      OlapConnection con =
          olapDiscoverService.getNativeConnection(query.getSaikuCube().getConnectionName());

      Long start = (new Date()).getTime();
      if (query.getScenario() != null) {
        log.info(
            runId
                + "\tQuery: "
                + query.getName()
                + " Setting scenario:"
                + query.getScenario().getId());
        con.setScenario(query.getScenario());
      }

      if (query.getTag() != null) {
        query = applyTag(query, con, query.getTag());
      }

      String mdx = query.getMdx();
      log.info(runId + "\tType:" + query.getType() + ":\n" + mdx);

      CellSet cellSet = query.execute();
      Long exec = (new Date()).getTime();

      if (query.getScenario() != null) {
        log.info("Query (" + queryName + ") removing scenario:" + query.getScenario().getId());
        con.setScenario(null);
      }

      CellDataSet result = OlapResultSetUtil.cellSet2Matrix(cellSet, formatter);
      Long format = (new Date()).getTime();
      log.info(
          runId
              + "\tSize: "
              + result.getWidth()
              + "/"
              + result.getHeight()
              + "\tExecute:\t"
              + (exec - start)
              + "ms\tFormat:\t"
              + (format - exec)
              + "ms\t Total: "
              + (format - start)
              + "ms");
      result.setRuntime(new Double(format - start).intValue());
      getIQuery(queryName).storeCellset(cellSet);
      return result;
    } catch (Exception e) {
      if (log.isInfoEnabled()) {
        String error = ExceptionUtils.getRootCauseMessage(e);
        log.info(runId + "\tException: " + error);
      }
      throw new SaikuServiceException(runId + "\tCan't execute query: " + queryName, e);
    } catch (Error e) {
      if (log.isInfoEnabled()) {
        String error = ExceptionUtils.getRootCauseMessage(e);
        log.info(runId + "\tError: " + error);
      }
      throw new SaikuServiceException(runId + "\tCan't execute query: " + queryName, e);
    }
  }