Package org.saiku.service.util

Examples of org.saiku.service.util.QueryContext


    tq.getProperties().putAll(cubeProperties);
    if (!context.containsKey(tq.getName())) {
      //Cube cub = olapDiscoverService.getNativeCube(tq.getCube());
      //Query query = new Query(tq.getName(), cub);
      //tq = Thin.convert(query, tq.getCube());
      QueryContext qt = new QueryContext(tq);
      qt.store(ObjectKey.QUERY, tq);
      this.context.put(tq.getName(), qt);
    }
    return tq;
  }
View Full Code Here


  }


  CellSet executeInternalQuery(@NotNull ThinQuery query) throws Exception {
    String runId = "RUN#:" + ID_GENERATOR.getAndIncrement();
    QueryContext queryContext = context.get(query.getName());

    if (queryContext == null) {
      queryContext = new QueryContext(query);
      this.context.put(query.getName(), queryContext);
    }

    OlapConnection con = olapDiscoverService.getNativeConnection(query.getCube().getConnection());
    if (StringUtils.isNotBlank(query.getCube().getCatalog())) {
      con.setCatalog(query.getCube().getCatalog());
    }

    if (queryContext.contains(ObjectKey.STATEMENT)) {
      Statement s = queryContext.getStatement();
      s.cancel();
      s.close();
      s = null;
      queryContext.remove();
    }

    OlapStatement stmt = con.createStatement();
    queryContext.store(ObjectKey.STATEMENT, stmt);

    query = updateQuery(query);

    try {
      String mdx = query.getParameterResolvedMdx();
      LOG.info(runId + "\tType:" + query.getType() + ":\n" + mdx);

      CellSet cs = stmt.executeOlapQuery(mdx);
      queryContext.store(ObjectKey.RESULT, cs);
      queryContext.store(ObjectKey.QUERY, query);
      return cs;
    } finally {
      stmt.close();
      queryContext.remove();
    }
  }
View Full Code Here

    return execute(tq, cf);
  }

  @NotNull
  public CellDataSet getFormattedResult(String query, @NotNull String format) throws Exception {
    QueryContext qc = getContext(query);
    ThinQuery tq = qc.getOlapQuery();
    CellSet cs = qc.getOlapResult();
    String formatterName = StringUtils.isBlank(format) ? "" : format.toLowerCase();
    ICellSetFormatter cf = cff.forName(formatterName);
    CellDataSet result = OlapResultSetUtil.cellSet2Matrix(cs, cf);

    if (ThinQuery.Type.QUERYMODEL.equals(tq.getType()) && cf instanceof FlattenedCellSetFormatter && tq
View Full Code Here

    }
  }

  public void cancel(String name) throws SQLException {
    if (context.containsKey(name)) {
      QueryContext queryContext = context.get(name);
      if (queryContext.contains(ObjectKey.STATEMENT)) {
        Statement stmt = queryContext.getStatement();
        if (stmt != null && !stmt.isClosed()) {
          stmt.cancel();
          stmt.close();
        }
        stmt = null;
        queryContext.remove();
      }
    }
  }
View Full Code Here

      ThinQuery tqAfter = Thin.convert(q, old.getCube());
      old.setQueryModel(tqAfter.getQueryModel());
      old.setMdx(tqAfter.getMdx());
    }
    if (context.containsKey(old.getName())) {
      QueryContext qc = context.get(old.getName());
      qc.store(ObjectKey.QUERY, old);
    }
    String mdx = old.getMdx();
    List<String> params = QueryUtil.parseParameters(mdx);
    old.addParameters(params);
View Full Code Here

  }

  public void deleteQuery(String queryName) {
    try {
      if (context.containsKey(queryName)) {
        QueryContext qc = context.remove(queryName);
        qc.destroy();
      }
    } catch (Exception e) {
      throw new SaikuServiceException(e);
    }
  }
View Full Code Here

  public ResultSet drillthrough(String queryName, @NotNull List<Integer> cellPosition, Integer maxrows,
                                String returns) {
    OlapStatement stmt = null;
    try {
      QueryContext queryContext = context.get(queryName);
      ThinQuery query = queryContext.getOlapQuery();
      CellSet cs = queryContext.getOlapResult();
      SaikuCube cube = query.getCube();
      final OlapConnection con = olapDiscoverService.getNativeConnection(cube.getConnection());
      stmt = con.createStatement();

      SelectNode sn = new DefaultMdxParserImpl().parseSelect(query.getMdx());
View Full Code Here


  public byte[] exportDrillthroughCsv(String queryName, int maxrows) {
    OlapStatement stmt = null;
    try {
      QueryContext queryContext = context.get(queryName);
      ThinQuery query = queryContext.getOlapQuery();
      final OlapConnection con = olapDiscoverService.getNativeConnection(query.getCube().getConnection());
      stmt = con.createStatement();
      String mdx = query.getMdx();
      if (maxrows > 0) {
        mdx = "DRILLTHROUGH MAXROWS " + maxrows + " " + mdx;
View Full Code Here

TOP

Related Classes of org.saiku.service.util.QueryContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.