public QueryAxis getAxis(String name) throws SaikuOlapException { if ("UNUSED".equals(name)) { return getUnusedAxis(); } Standard standardAxis = Standard.valueOf(name); if (standardAxis == null) throw new SaikuOlapException( "Axis (" + name + ") not found for query (" + query.getName() + ")"); Axis queryAxis = Axis.Factory.forOrdinal(standardAxis.axisOrdinal()); return query.getAxis(queryAxis); }
private QueryAxis findAxis(QueryDimension dimension) { if (query.getUnusedAxis().getDimensions().contains(dimension)) { return query.getUnusedAxis(); } else { Map<Axis, QueryAxis> axes = query.getAxes(); for (Axis axis : axes.keySet()) { if (axes.get(axis).getDimensions().contains(dimension)) { return axes.get(axis); } } } return null; }
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; }
public void moveDimension(QueryDimension dimension, Axis axis, int position) { dimension.setHierarchizeMode(HierarchizeMode.PRE); if (dimension.getName() != "Measures") { dimension.setHierarchyConsistent(true); } QueryAxis oldQueryAxis = findAxis(dimension); QueryAxis newQueryAxis = query.getAxis(axis); if (oldQueryAxis != null && newQueryAxis != null) { oldQueryAxis.removeDimension(dimension); newQueryAxis.addDimension(position, dimension); } }
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 ***********************/"); }
public Boolean isDrillThroughEnabled() { return query.getCube().isDrillThroughEnabled(); }
private void applyDefaultProperties() { if (SaikuProperties.olapDefaultNonEmpty) { query.getAxis(Axis.ROWS).setNonEmpty(true); query.getAxis(Axis.COLUMNS).setNonEmpty(true); } }
public String getName() { return query.getName(); }