Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
  public SaikuQuery applyFilter(String queryname, SaikuFilter filter) throws Exception {
    IQuery query = getIQuery(queryname);
    if (filter != null
        && filter.getName() != null
        && filter.getDimension() != null
        && filter.getMembers() != null) {
      query.setFilter(filter);
      QueryDimension qDim = query.getDimension(filter.getDimension().getName());

      if (qDim != null) {
        qDim.clearInclusions();
        query.moveDimension(qDim, Axis.FILTER);
        for (SimpleCubeElement member : filter.getMembers()) {
          List<IdentifierSegment> memberList =
              IdentifierNode.parseIdentifier(member.getUniqueName()).getSegmentList();
          qDim.include(memberList);
        }
      }
    }
    return ObjectUtil.convert(query);
  }
Exemplo n.º 3
0
  public static void main(String[] args) throws Exception {

    // Load the driver
    Class.forName("mondrian.olap4j.MondrianOlap4jDriver");

    // Connect
    final Connection connection =
        DriverManager.getConnection(
            "jdbc:mondrian:" // Driver ident
                + "Jdbc=jdbc:hsqldb:file:foodmart/foodmart;" // Relational DB
                + "Catalog=file:foodmart/FoodMart.xml;"); // Catalog

    // We are dealing with an olap connection. we must unwrap it.
    final OlapConnection olapConnection = connection.unwrap(OlapConnection.class);

    // Get a cube object.
    Cube salesCube = olapConnection.getOlapSchema().getCubes().get("Sales");

    // Build a query object.
    Query myQuery = new Query("myQuery", salesCube);

    // Lookup some dimensions
    QueryDimension productDim = myQuery.getDimension("Product");
    QueryDimension storeDim = myQuery.getDimension("Store");
    QueryDimension timeDim = myQuery.getDimension("Time");

    // Place dimensions on some axis
    myQuery.getAxis(Axis.COLUMNS).addDimension(productDim);
    myQuery.getAxis(Axis.ROWS).addDimension(storeDim);
    myQuery.getAxis(Axis.FILTER).addDimension(timeDim);

    // Including a member by metadata
    Member year1997 =
        salesCube.lookupMember(IdentifierNode.ofNames("Time", "1997").getSegmentList());
    timeDim.include(year1997);

    // Including a member by name parts
    productDim.include(
        Selection.Operator.CHILDREN,
        IdentifierNode.ofNames("Product", "Drink", "Beverages").getSegmentList());

    // We can also exclude members
    productDim.exclude(
        IdentifierNode.ofNames("Product", "Drink", "Beverages", "Carbonated Beverages")
            .getSegmentList());

    // Validate this query
    myQuery.validate();

    // Print!
    System.out.println("/********************* QUERY ***********************/");

    System.out.println(myQuery.getSelect().toString());

    System.out.println("/********************* QUERY ***********************/");
    System.out.println(" ");
    System.out.println(" ");
    System.out.println(" ");
    System.out.println(" ");

    System.out.println("/********************* RESULTS ***********************/");

    RectangularCellSetFormatter formatter = new RectangularCellSetFormatter(false);

    PrintWriter writer = new PrintWriter(System.out);

    formatter.format(myQuery.execute(), writer);

    writer.flush();
    System.out.println("/********************* RESULTS ***********************/");
  }