protected void tearDown() throws Exception {
    if (olapConnection != null && !olapConnection.isClosed()) {
      olapConnection.close();
      olapConnection = null;
    }

    if (connection != null && !connection.isClosed()) {
      connection.close();
      connection = null;
    }
  }
  protected void setUp() throws SQLException {

    Olap4ldUtil.prepareLogging();

    Olap4ldUtil._isDebug = false;

    connection = tester.createConnection();
    connection.getCatalog();
    olapConnection = tester.getWrapper().unwrap(connection, OlapConnection.class);
    olapConnection.getMetaData();

    // Create a statement based upon the object model.
    // One can simply keep open the statement and issue new queries.
    OlapConnection olapconnection = (OlapConnection) connection;
    this.stmt = null;
    try {
      stmt = olapconnection.createStatement();
    } catch (OlapException e) {
      System.out.println("Validation failed: " + e);
      return;
    }
  }
  private void metadataTest(String dsUri, int numberOfDimensions, int numberOfMeasures) {
    try {

      // We have to use MDX encoded name
      String name = URLEncoder.encode(dsUri, "UTF-8");
      name = name.replace("%", "XXX");
      name = name.replace(".", "YYY");
      name = name.replace("-", "ZZZ");
      // xmla4js is attaching square brackets automatically
      // xmla-server is using a set of values for a restriction.
      Cube cube =
          olapConnection
              .getOlapDatabases()
              .get(0)
              .getCatalogs()
              .get(0)
              .getSchemas()
              .get(0)
              .getCubes()
              .get("[" + name + "]");

      // Currently, we have to first query for dimensions.
      List<Dimension> dimensions = cube.getDimensions();

      // Number of dimensions
      assertEquals(numberOfDimensions, dimensions.size());
      for (Dimension dimension : dimensions) {
        List<Member> members = dimension.getHierarchies().get(0).getLevels().get(0).getMembers();

        // Each dimension should have some members
        assertEquals(true, members.size() >= 1);
      }

      List<Measure> measures = cube.getMeasures();

      // Number of measures
      assertEquals(numberOfMeasures, measures.size());
    } catch (OlapException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Ejemplo n.º 4
0
 public static CellSet getResultSet(String mdx, OlapConnection conn) throws OlapException {
   OlapStatement statement = conn.createStatement();
   CellSet cellSet = statement.executeOlapQuery(mdx);
   return cellSet;
 }