Beispiel #1
0
 public boolean removeLevel(
     String queryName, String dimensionName, String uniqueHierarchyName, String uniqueLevelName) {
   IQuery query = getIQuery(queryName);
   removeAllChildren(queryName, dimensionName);
   QueryDimension dimension = query.getDimension(dimensionName);
   try {
     for (Hierarchy hierarchy : dimension.getDimension().getHierarchies()) {
       if (hierarchy.getUniqueName().equals(uniqueHierarchyName)) {
         for (Level level : hierarchy.getLevels()) {
           if (level.getUniqueName().equals(uniqueLevelName)) {
             Selection inclusion = dimension.createSelection(level);
             dimension.getInclusions().remove(inclusion);
             ArrayList<Selection> removals = new ArrayList<Selection>();
             for (Selection sel : dimension.getInclusions()) {
               if ((sel.getRootElement() instanceof Member)) {
                 if (((Member) sel.getRootElement()).getLevel().equals(level)) {
                   if (dimension.getInclusions().contains(sel)) {
                     removals.add(sel);
                   }
                 }
               }
             }
             dimension.getInclusions().removeAll(removals);
           }
         }
       }
     }
   } catch (Exception e) {
     throw new SaikuServiceException(
         "Cannot remove level" + uniqueLevelName + "from dimension " + dimensionName, e);
   }
   return true;
 }
Beispiel #2
0
  public CellSet execute() throws Exception {

    if (scenario != null && query.getDimension("Scenario") != null) {
      QueryDimension dimension = query.getDimension("Scenario");
      moveDimension(dimension, Axis.FILTER);
      Selection sel =
          dimension.createSelection(
              IdentifierParser.parseIdentifier("[Scenario].[" + getScenario().getId() + "]"));
      if (!dimension.getInclusions().contains(sel)) {
        dimension.getInclusions().add(sel);
      }
    }

    Query mdx = this.query;
    mdx.validate();
    StringWriter writer = new StringWriter();
    mdx.getSelect().unparse(new ParseTreeWriter(new PrintWriter(writer)));
    log.debug("Executing query (" + this.getName() + ") :\n" + writer.toString());
    CellSet cellSet = mdx.execute();
    if (scenario != null && query.getDimension("Scenario") != null) {
      QueryDimension dimension = query.getDimension("Scenario");
      dimension.getInclusions().clear();
      moveDimension(dimension, null);
    }

    return cellSet;
  }
Beispiel #3
0
 public boolean removeMember(
     String queryName, String dimensionName, String uniqueMemberName, String selectionType)
     throws SaikuServiceException {
   IQuery query = getIQuery(queryName);
   removeAllChildren(queryName, dimensionName);
   List<IdentifierSegment> memberList =
       IdentifierNode.parseIdentifier(uniqueMemberName).getSegmentList();
   QueryDimension dimension = query.getDimension(dimensionName);
   final Selection.Operator selectionMode = Selection.Operator.valueOf(selectionType);
   try {
     if (log.isDebugEnabled()) {
       log.debug(
           "query: "
               + queryName
               + " remove:"
               + selectionMode.toString()
               + " "
               + memberList.size());
     }
     Selection selection = dimension.createSelection(selectionMode, memberList);
     dimension.getInclusions().remove(selection);
     return true;
   } catch (OlapException e) {
     throw new SaikuServiceException(
         "Error removing member (" + uniqueMemberName + ") of dimension (" + dimensionName + ")",
         e);
   }
 }
Beispiel #4
0
 public boolean includeLevel(
     String queryName, String dimensionName, String uniqueHierarchyName, String uniqueLevelName) {
   IQuery query = getIQuery(queryName);
   removeAllChildren(queryName, dimensionName);
   QueryDimension dimension = query.getDimension(dimensionName);
   for (Hierarchy hierarchy : dimension.getDimension().getHierarchies()) {
     if (hierarchy.getUniqueName().equals(uniqueHierarchyName)) {
       for (Level level : hierarchy.getLevels()) {
         if (level.getUniqueName().equals(uniqueLevelName)) {
           Selection sel = dimension.createSelection(level);
           if (!dimension.getInclusions().contains(sel)) {
             dimension.include(level);
           }
           return true;
         }
       }
     }
   }
   return false;
 }
Beispiel #5
0
 public boolean includeChildren(String queryName, String dimensionName, String uniqueMemberName) {
   IQuery query = getIQuery(queryName);
   List<IdentifierSegment> memberList =
       IdentifierNode.parseIdentifier(uniqueMemberName).getSegmentList();
   QueryDimension dimension = query.getDimension(dimensionName);
   try {
     Selection sel = dimension.createSelection(Operator.CHILDREN, memberList);
     dimension.getInclusions().add(sel);
     return true;
   } catch (OlapException e) {
     throw new SaikuServiceException(
         "Cannot include children query ("
             + queryName
             + ") dimension ("
             + dimensionName
             + ") member ("
             + uniqueMemberName
             + ")",
         e);
   }
 }
Beispiel #6
0
  public boolean includeMember(
      String queryName,
      String dimensionName,
      String uniqueMemberName,
      String selectionType,
      int memberposition) {
    IQuery query = getIQuery(queryName);

    List<IdentifierSegment> memberList =
        IdentifierNode.parseIdentifier(uniqueMemberName).getSegmentList();
    QueryDimension dimension = query.getDimension(dimensionName);
    final Selection.Operator selectionMode = Selection.Operator.valueOf(selectionType);
    try {
      removeAllChildren(queryName, dimensionName);
      Selection sel = dimension.createSelection(selectionMode, memberList);
      if (dimension.getInclusions().contains(sel)) {
        dimension.getInclusions().remove(sel);
      }
      if (memberposition < 0) {
        memberposition = dimension.getInclusions().size();
      }
      dimension.getInclusions().add(memberposition, sel);
      return true;
    } catch (OlapException e) {
      throw new SaikuServiceException(
          "Cannot include member query ("
              + queryName
              + ") dimension ("
              + dimensionName
              + ") member ("
              + uniqueMemberName
              + ") operator ("
              + selectionType
              + ") position "
              + memberposition,
          e);
    }
  }
Beispiel #7
0
  private IQuery applyTag(IQuery query, OlapConnection con, SaikuTag t) throws Exception {
    String xml = query.toXml();
    QueryDeserializer qd = new QueryDeserializer();
    query = qd.unparse(xml, con);

    List<SimpleCubeElement> doneDimension = new ArrayList<SimpleCubeElement>();
    Map<String, QueryDimension> dimensionMap = new HashMap<String, QueryDimension>();
    if (t.getSaikuTupleDimensions() != null) {
      for (SimpleCubeElement st : t.getSaikuTupleDimensions()) {
        if (!doneDimension.contains(st)) {
          QueryDimension dim = query.getDimension(st.getName());
          dimensionMap.put(st.getUniqueName(), dim);
          dim.clearExclusions();
          dim.clearInclusions();
          query.moveDimension(dim, null);
          doneDimension.add(st);
        }
      }
      if (t.getSaikuTupleDimensions().size() > 0) {
        SimpleCubeElement rootDim = t.getSaikuTupleDimensions().get(0);
        QueryDimension dim = query.getDimension(rootDim.getName());
        query.moveDimension(dim, Axis.COLUMNS);

        for (SaikuTuple tuple : t.getSaikuTuples()) {
          SaikuMember m = tuple.getSaikuMember(rootDim.getUniqueName());
          List<SaikuMember> others = tuple.getOtherSaikuMembers(rootDim.getUniqueName());
          Selection sel = dim.createSelection(IdentifierParser.parseIdentifier(m.getUniqueName()));
          for (SaikuMember context : others) {
            QueryDimension otherDim = dimensionMap.get(context.getDimensionUniqueName());
            query.moveDimension(otherDim, Axis.COLUMNS);
            Selection ctxSel =
                otherDim.createSelection(IdentifierParser.parseIdentifier(context.getUniqueName()));
            sel.addContext(ctxSel);
          }
          dim.getInclusions().add(sel);
        }
      }
    }
    if (t.getSaikuDimensionSelections() != null) {
      for (SaikuDimensionSelection dimsel : t.getSaikuDimensionSelections()) {
        if (!dimsel.getName().equals("Measures")) {
          QueryDimension filterDim = query.getDimension(dimsel.getName());
          query.moveDimension(filterDim, Axis.FILTER);
          filterDim.clearInclusions();
          for (SaikuSelection ss : dimsel.getSelections()) {
            if (ss.getType() == SaikuSelection.Type.MEMBER) {
              Selection sel =
                  filterDim.createSelection(IdentifierParser.parseIdentifier(ss.getUniqueName()));
              if (!filterDim.getInclusions().contains(sel)) {
                filterDim.getInclusions().add(sel);
              }
            }
          }
          // TODO: Move it to columns since drilling through with 2 filter items of the same
          // dimension doesn't work
          //					if (filterDim.getInclusions().size() > 1) {
          //						query.moveDimension(filterDim, Axis.COLUMNS);
          //					}
        }
      }
    }

    return query;
  }