⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmla_soap.java

📁 OLAP 的客户端代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    pHash.put("DataSourceInfo", dataSource);
    pHash.put("Catalog", cat); // neccessary ???
    pHash.put("Content", "SchemaData");

    Rowhandler rh = new Rowhandler() {
      public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) {

        XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_LEVEL);
        levels.add(oi);

        Iterator it = eRow.getChildElements();
        while (it.hasNext()) {
          Object o = it.next();
          if (!(o instanceof SOAPElement))
            continue;
          SOAPElement e = (SOAPElement) o;

          String lname = e.getElementName().getLocalName();
          if (lname.equals("LEVEL_UNIQUE_NAME")) {
            oi.setUniqueName(e.getValue());
          } else if (lname.equals("LEVEL_CAPTION")) {
            oi.setCaption(e.getValue());
          } else if (lname.equals("LEVEL_NAME")) {
            oi.setName(e.getValue());
          } else {
            oi.setProperty(lname, e.getValue());
          }
        }
      }

    };

    discover("MDSCHEMA_LEVELS", url, rHash, pHash, rh);
    logger.debug("MDSCHEMA_LEVELS: found " + levels.size());
    if (levels.size() == 0) {
        throw new OlapException("No metadata schema levels for catalog: " + cat + " and cube: " + cube);
    }
    return levels;
  }

  /**
   * retrieve members in data source
   * @return List of OlapItems for the members
   * @see DataSourceBrowser
   */
  public List discoverMem(String cat, String cube, String dimension, String hierarchy, String level)
      throws OlapException {
    final List mems = new ArrayList();

    // restrictions
    HashMap rHash = new HashMap();
    rHash.put("CATALOG_NAME", cat);
    rHash.put("CUBE_NAME", cube);
    if (dimension != null)
      rHash.put("DIMENSION_UNIQUE_NAME", dimension);
    if (hierarchy != null)
      rHash.put("HIERARCHY_UNIQUE_NAME", hierarchy);
    if (level != null)
      rHash.put("LEVEL_UNIQUE_NAME", level);

    // properties   
    HashMap pHash = new HashMap();
    pHash.put("DataSourceInfo", dataSource);
    pHash.put("Catalog", cat); // neccessary ???
    pHash.put("Content", "SchemaData");

    Rowhandler rh = new Rowhandler() {

      public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) {

        XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_MEMBER);
        mems.add(oi);

        Iterator it = eRow.getChildElements();
        while (it.hasNext()) {
          Object o = it.next();
          if (!(o instanceof SOAPElement))
            continue;
          SOAPElement e = (SOAPElement) o;

          String lname = e.getElementName().getLocalName();
          if (lname.equals("MEMBER_UNIQUE_NAME")) {
            oi.setUniqueName(e.getValue());
          } else if (lname.equals("MEMBER_CAPTION")) {
            oi.setCaption(e.getValue());
          } else if (lname.equals("MEMBER_NAME")) {
            oi.setName(e.getValue());
          } else {
            oi.setProperty(lname, e.getValue());
          }
        }
      }

    };

    discover("MDSCHEMA_MEMBERS", url, rHash, pHash, rh);
    logger.debug("MDSCHEMA_MEMBERS: found " + mems.size());
    if (mems.size() == 0) {
        logger.error("No metadata schema members for catalog: " + cat + " and cube: " + cube);
    }

    return mems;
  }

  /**
   * retrieve member tree in data source for given catalog, cube, member
   * @param cat name of catalog 
   * @param cube name of cube  
   * @param member unique name of member
   * @param treeop bit combination according to TREEOP specification
   *               MDTREEOP_CHILDREN = 1
   *               MDTREEOP_SIBLINGS = 2
   *               MDTREEOP_PARENT = 4
   *               MDTREEOP_SELF = 8
   *               MDTREEOP_DESCENDANTS = 16
   *               MDTREEOP_ANCESTORS = 32
   * @return List of OlapItems for the members
   * @throws OlapException
   * @see com.tonbeller.jpivot.olap.model.OlapDiscoverer#discoverMemTree
   */

  public List discoverMemTree(String cat, String cube, String member, int treeop)
      throws OlapException {
    final List mems = new ArrayList();

    // restrictions
    HashMap rHash = new HashMap();
    rHash.put("CATALOG_NAME", cat);
    rHash.put("CUBE_NAME", cube);
    rHash.put("MEMBER_UNIQUE_NAME", member);
    rHash.put("TREE_OP", String.valueOf(treeop));

    // properties   
    HashMap pHash = new HashMap();
    pHash.put("DataSourceInfo", dataSource);
    pHash.put("Catalog", cat); // neccessary ???
    pHash.put("Content", "SchemaData");

    Rowhandler rh = new Rowhandler() {

      public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) {

        XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_MEMBER);
        mems.add(oi);

        Iterator it = eRow.getChildElements();
        while (it.hasNext()) {
          Object o = it.next();
          if (!(o instanceof SOAPElement))
            continue;
          SOAPElement e = (SOAPElement) o;

          String lname = e.getElementName().getLocalName();
          if (lname.equals("MEMBER_UNIQUE_NAME")) {
            oi.setUniqueName(e.getValue());
          } else if (lname.equals("MEMBER_CAPTION")) {
            oi.setCaption(e.getValue());
          } else if (lname.equals("MEMBER_NAME")) {
            oi.setName(e.getValue());
          } else {
            oi.setProperty(lname, e.getValue());
          }
        }
      }

    };

    discover("MDSCHEMA_MEMBERS", url, rHash, pHash, rh);
    logger.debug("MDSCHEMA_MEMBERS Tree: found " + mems.size());
    if (mems.size() == 0) {
        logger.error("No metadata schema members tree for catalog: " + cat + " and cube: " + cube +
                ", member unique name: " + member + ", tree operation: " + String.valueOf(treeop));
    }
    return mems;
  }

  /**
   * retrieve data source properties
   * @return Map of key/value strings 
   * @see DataSourceBrowser
   */
  public Map discoverDS() throws OlapException {
    // Microsoft wants restrictions
    HashMap rHash = new HashMap();

    HashMap pHash = new HashMap();
    pHash.put("Content", "Data");
    final Map resultMap = new HashMap();
    Rowhandler rh = new Rowhandler() {

      public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) {

        /*
         <row><DataSourceName>SAP_BW</DataSourceName>
         <DataSourceDescription>SAP BW Release 3.0A XML f. Analysis Service</DataSourceDescription>
         <URL>http://155.56.49.46:83/SAP/BW/XML/SOAP/XMLA</URL>
         <DataSourceInfo>default</DataSourceInfo>
         <ProviderName>SAP BW</ProviderName>
         <ProviderType>MDP</ProviderType>
         <AuthenticationMode>Integrated</AuthenticationMode></row>
         */
        Iterator it = eRow.getChildElements();
        while (it.hasNext()) {
          Object o = it.next();
          if (!(o instanceof SOAPElement))
            continue; //bypass text nodes
          SOAPElement e = (SOAPElement) o;
          String name = e.getElementName().getLocalName();
          String value = e.getValue();
          resultMap.put(name, value);
        }
      }
    };

    discover("DISCOVER_DATASOURCES", url, rHash, pHash, rh);
    logger.debug("DISCOVER_DATASOURCES: found " + resultMap.size());
    return resultMap;

  }

  /**
   * retrieve member properties in data source for given catalog, cube, dimension, hierarchy, level
   * @param cat name of catalog 
   * @param cube name of cube  
   * @param dimension unique name of dimension
   * @param hierarchy unique name of hierarchy   
   * @param level unique name of level
   * @return List of OlapItems for the members
   * @throws OlapException
   * @see com.tonbeller.jpivot.olap.model.OlapDiscoverer#discoverProp 
   */
  public List discoverProp(String cat, String cube, String dimension, String hierarchy, String level)
      throws OlapException {
    final List props = new ArrayList();

    // restrictions
    HashMap rHash = new HashMap();
    rHash.put("CATALOG_NAME", cat);
    rHash.put("CUBE_NAME", cube);
    if (dimension != null)
      rHash.put("DIMENSION_UNIQUE_NAME", dimension);
    if (hierarchy != null)
      rHash.put("HIERARCHY_UNIQUE_NAME", hierarchy);
    if (level != null)
      rHash.put("LEVEL_UNIQUE_NAME", level);

    // properties   
    HashMap pHash = new HashMap();
    pHash.put("DataSourceInfo", dataSource);
    pHash.put("Catalog", cat); // neccessary ???
    pHash.put("Content", "SchemaData");

    Rowhandler rh = new Rowhandler() {

      public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) {
        XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_PROPERTY);
        props.add(oi);

        Iterator it = eRow.getChildElements();
        while (it.hasNext()) {
          Object o = it.next();
          if (!(o instanceof SOAPElement))
            continue;
          SOAPElement e = (SOAPElement) o;

          String lname = e.getElementName().getLocalName();
          if (lname.equals("PROPERTY_NAME")) {
            oi.setName(e.getValue());
          } else if (lname.equals("PROPERTY_CAPTION")) {
            oi.setCaption(e.getValue());
          } else {
            oi.setProperty(lname, e.getValue());
          }
        }

      }
    };

    discover("MDSCHEMA_PROPERTIES", url, rHash, pHash, rh);
    logger.debug("MDSCHEMA_PROPERTIES: found " + props.size());

    return props;
  }

  /**
   * retrieve SAP variables for given catalog, cube
   * @param cat name of catalog 
   * @param cube name of cube  
   * @return List of OlapItems for the members
   * @throws OlapException
   * @see com.tonbeller.jpivot.olap.model.OlapDiscoverer#discoverProp 
   */
  public List discoverSapVar(String cat, String cube) throws OlapException {
    final List props = new ArrayList();

    // restrictions
    HashMap rHash = new HashMap();
    rHash.put("CATALOG_NAME", cat);
    rHash.put("CUBE_NAME", cube);

    // properties   
    HashMap pHash = new HashMap();
    pHash.put("DataSourceInfo", dataSource);
    pHash.put("Catalog", cat); // neccessary ???
    pHash.put("Content", "SchemaData");

    Rowhandler rh = new Rowhandler() {

      public void handleRow(SOAPElement eRow, SOAPEnvelope envelope) {
        XMLA_OlapItem oi = new XMLA_OlapItem(OlapItem.TYPE_PROPERTY);
        props.add(oi);

        Iterator it = eRow.getChildElements();
        while (it.hasNext()) {
          Object o = it.next();
          if (!(o instanceof SOAPElement))
            continue;
          SOAPElement e = (SOAPElement) o;

          String lname = e.getElementName().getLocalName();
          if (lname.equals("VARIABLE_NAME")) {
            // ??? probably not supported
            oi.setName(e.getValue());
          } else if (lname.equals("VARIABLE_CAPTION")) { // ?? probably not supported
            oi.setCaption(e.getValue());
          } else {
            oi.setProperty(lname, e.getValue());
          }
        }

      }
    };

    discover("SAP_VARIABLES", url, rHash, pHash, rh);

    return props;
  }

  /**
   * Execute query
   * @param query - MDX to be executed
   * @param catalog
   * @param handler Callback handler
   * @throws OlapException
   */
  public void executeQuery(String query, String catalog, QueryResultHandler handler)
      throws OlapException {

    SOAPConnection connection = null;
    SOAPMessage reply = null;

    try {
      connection = scf.createConnection();
      SOAPMessage msg = mf.createMessage();

      MimeHeaders mh = msg.getMimeHeaders();
      mh.setHeader("SOAPAction", "\"urn:schemas-microsoft-com:xml-analysis:Execute\"");

      SOAPPart soapPart = msg.getSOAPPart();
      SOAPEnvelope envelope = soapPart.getEnvelope();
      SOAPBody body = envelope.getBody();
      Name nEx = envelope.createName("Execute", "", XMLA_URI);

      SOAPElement eEx = body.addChildElement(nEx);

      // add the parameters

      // COMMAND parameter
      // <Command>
      // <Statement>select [Measures].members on Columns from Sales</Statement>
      // </Command>
      Name nCom = envelope.createName("Command");
      SOAPElement eCommand = eEx.addChildElement(nCom);
      Name nSta = envelope.createName("Statement");
      SOAPElement eStatement = eCommand.addChildElement(nSta);
      eStatement.addTextNode(query);

      // <Properties>
      // <PropertyList>
      //    <DataSourceInfo>Provider=MSOLAP;Data Source=local</DataSourceInfo>
      //    <Catalog>Foodmart 2000</Catalog>
      //    <Format>Multidimensional</Format>
      //    <AxisFormat>TupleFormat</AxisFormat> oder "ClusterFormat"
      // </PropertyList>
      // </Properties>
      Map paraList = new HashMap();
      paraList.put("DataSourceInfo", dataSource);
      paraList.put("Catalog", catalog);
      paraList.put("Format", "Multidimensional");
      paraList.put("AxisFormat", "TupleFormat");
      addParameterList(envelope, eEx, "Properties", "PropertyList", paraList);
      msg.saveChanges();

      // run the call
      reply = connection.call(msg, url);
      if (logger.isDebugEnabled()) {
        logger.debug("Reply from Execute");
        //reply.getSOAPPart().getContent().
        logSoapMsg(reply);
      }

      // error check
      errorCheck(reply);
      // process the reply

      SOAPElement eRoot = findExecRoot(reply);

      // determine axes from <OlapInfo><AxesInfo><AxisInfo>
      Name name = envelope.createName("OlapInfo", "", MDD_URI);
      SOAPElement eOlapInfo = selectSingleNode(eRoot, name);
      if (eOlapInfo == null)
        throw new OlapException("Excecute result has no eOlapInfo element");

      name = envelope.createName("AxesInfo", "", MDD_URI);
      SOAPElement eAxesInfo = selectSingleNode(eOlapInfo, name);
      if (eAxesInfo == null)
        throw new OlapException("Excecute result has no AxesInfo element");

      name = envelope.createName("AxisInfo", "", MDD_URI);
      Iterator itAxisInfo = eAxesInfo.getChildElements(name);

      int iOrdinal = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -