Examples of IQuery


Examples of org.eclipse.persistence.jpa.jpql.tools.spi.IQuery

      Annotation[] annotations = type.getAnnotations();
      NamedQueries namedQueries = getAnnotation(annotations, NamedQueries.class);

      if (namedQueries != null) {
        for (NamedQuery namedQuery : namedQueries.value()) {
          IQuery query = buildQuery(namedQuery);
          queries.put(namedQuery.name(), query);
        }
      }
      else {
        NamedQuery namedQuery = getAnnotation(annotations, NamedQuery.class);
        if (namedQuery != null) {
          IQuery query = buildQuery(namedQuery);
          queries.put(namedQuery.name(), query);
        }
      }
    }
    catch (Exception e) {
View Full Code Here

Examples of org.saiku.olap.query.IQuery

    return queryList;
  }

  @NotNull
  public SaikuQuery getQuery(String queryName) {
    IQuery q = getIQuery(queryName);
    return ObjectUtil.convert(q);
  }
View Full Code Here

Examples of org.saiku.olap.query.IQuery

  public void cancel(String queryName) {
    try {
      //System.out.println("Cancel: ID " + Thread.currentThread().getId() + " Name: " +
      // Thread.currentThread().getName());
      IQuery q = getIQuery(queryName);
      q.cancel();
    } catch (Exception e) {
      throw new SaikuServiceException("Error cancelling query: " + queryName, e);
    }
  }
View Full Code Here

Examples of org.saiku.olap.query.IQuery

  CellDataSet execute(String queryName, @NotNull 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().getConnection());


      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();

      result.setRuntime(new Double(format - start).intValue());
      getIQuery(queryName).storeCellset(cellSet);
      getIQuery(queryName).storeFormatter(formatter);
      // we could do a check if query.getTotalFunctions() actually includes a total function and if not
      // dont execute the following
      if (QueryType.QM.equals(query.getType()) && formatter instanceof FlattenedCellSetFormatter) {
        QueryDimension queryDimension = query.getDimension("Measures");
        Measure[] selectedMeasures = new Measure[queryDimension.getInclusions().size()];
        for (int i = 0; i < selectedMeasures.length; i++) {
          selectedMeasures[i] = (Measure) queryDimension.getInclusions().get(i).getRootElement();
        }
        result.setSelectedMeasures(selectedMeasures);

        int rowsIndex = 0;
        if (!cellSet.getAxes().get(0).getAxisOrdinal().equals(Axis.ROWS)) {
          rowsIndex = rowsIndex + 1 & 1;
        }
        // TODO - refactor this using axis ordinals etc.
        //@formatter:off
        final AxisInfo[] axisInfos = new AxisInfo[] { new AxisInfo(cellSet.getAxes().get(rowsIndex)),
          new AxisInfo(cellSet.getAxes().get(rowsIndex + 1 & 1)) };
        //@formatter:on
        List<TotalNode>[][] totals = new List[2][];
        TotalsListsBuilder builder = null;
        for (int index = 0; index < 2; index++) {
          final int second = index + 1 & 1;
          TotalAggregator[] aggregators = new TotalAggregator[axisInfos[second].maxDepth + 1];
          for (int i = 1; i < aggregators.length - 1; i++) {
            String totalFunctionName = query.getTotalFunction(axisInfos[second].uniqueLevelNames.get(i - 1));
            aggregators[i] = TotalAggregator.newInstanceByFunctionName(totalFunctionName);
          }
          String totalFunctionName = query.getTotalFunction(axisInfos[second].axis.getAxisOrdinal().name());
          aggregators[0] =
              totalFunctionName != null ? TotalAggregator.newInstanceByFunctionName(totalFunctionName) : null;
          builder = new TotalsListsBuilder(selectedMeasures, aggregators, cellSet, axisInfos[index], axisInfos[second]);
          totals[index] = builder.buildTotalsLists();
        }
View Full Code Here

Examples of org.saiku.olap.query.IQuery

  }

  @NotNull
  public SaikuQuery simulateTag(String queryName, @NotNull SaikuTag tag) {
    try {
      IQuery query = getIQuery(queryName);
      OlapConnection con = olapDiscoverService.getNativeConnection(query.getSaikuCube().getConnection());
      return ObjectUtil.convert(applyTag(query, con, tag));
    } catch (Exception e) {
      throw new SaikuServiceException("Can't apply tag: " + tag + " to query " + queryName, e);
    }
  }
View Full Code Here

Examples of org.saiku.olap.query.IQuery

    return query;
  }

  public void setMdx(String queryName, String mdx) {
    IQuery q = getIQuery(queryName);
    q.setMdx(mdx);
  }
View Full Code Here

Examples of org.saiku.olap.query.IQuery

  }

  public List<SimpleCubeElement> getResultMetadataMembers(String queryName, boolean preferResult, String dimensionName,
                                                          String hierarchyName, String levelName, String searchString,
                                                          int searchLimit) {
    IQuery query = getIQuery(queryName);
    CellSet cs = query.getCellset();
    List<SimpleCubeElement> members = new ArrayList<SimpleCubeElement>();
    Set<Level> levels = new HashSet<Level>();
    boolean search = StringUtils.isNotBlank(searchString);
    preferResult = preferResult && !search;
    searchString = search ? searchString.toLowerCase() : null;

    if (cs != null && preferResult) {
      for (CellSetAxis axis : cs.getAxes()) {
        int posIndex = 0;
        for (Hierarchy h : axis.getAxisMetaData().getHierarchies()) {
          if (h.getUniqueName().equals(hierarchyName) || h.getName().equals(hierarchyName)) {
            LOG.debug("Found hierarchy in the result: " + hierarchyName);
            if (h.getLevels().size() == 1) {
              break;
            }
            Set<Member> mset = new HashSet<Member>();
            for (Position pos : axis.getPositions()) {
              Member m = pos.getMembers().get(posIndex);
              if (!m.getLevel().getLevelType().equals(Type.ALL)) {
                levels.add(m.getLevel());
              }
              if (m.getLevel().getUniqueName().equals(levelName) || m.getLevel().getName().equals(levelName)) {
                mset.add(m);
              }
            }

            members = ObjectUtil.convert2Simple(mset);
            Collections.sort(members, new SaikuUniqueNameComparator());

            break;
          }
          posIndex++;
        }
      }
      LOG.debug("Found members in the result: " + members.size());

    }
    if (cs == null || !preferResult || members.size() == 0 || levels.size() == 1) {
      members = olapDiscoverService
          .getLevelMembers(query.getSaikuCube(), hierarchyName, levelName, searchString, searchLimit);
    }
    return members;
  }
View Full Code Here

Examples of org.saiku.olap.query.IQuery

  public ResultSet drillthrough(String queryName, @NotNull 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.getConnection());
      stmt = con.createStatement();

      SelectNode sn = new DefaultMdxParserImpl().parseSelect(getMDXQuery(queryName));
View Full Code Here

Examples of org.saiku.olap.query.IQuery


  public void setCellValue(String queryName, List<Integer> position, String value) {
    try {

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

      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);
      }

      String 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);
    }
View Full Code Here

Examples of org.saiku.olap.query.IQuery


  }

  public IQuery swapAxes(String queryName) {
    IQuery query = getIQuery(queryName);
    if (QueryType.QM.equals(query.getType())) {
      query.swapAxes();
    }
    return query;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.