简体   繁体   English

使用WSO2 DSS的return = UDT数组调用Oracle DB中的过程或函数

[英]Call a procedure or function in Oracle DB with return = array of UDT from WSO2 DSS

I follow this post[1] as a guide to build an example of query an array of UDT in WSO2 DSS. 我按照这篇文章[1]作为指导,建立一个在WSO2 DSS中查询UDT数组的示例。 In the post just query an UDT, my config try to query an UDT array. 在仅查询UDT的帖子中,我的配置尝试查询UDT数组。

I created this in my DB, a dummy PROCEDURE to try this: 我在数据库中创建了一个虚拟的PROCEDURE来尝试此操作:

create or replace
TYPE "LIST_CUSTOMERS" IS TABLE OF customer_t


CREATE OR REPLACE 
PROCEDURE getCustomer2(listcust OUT list_customers) IS 
cust customer_t;
cust2 customer_t;
BEGIN 
listcust := list_customers();
cust := customer_t(1, 'prabath'); 
cust2 := customer_t(2, 'jorge'); 
listcust.extend;
listcust(1) := cust;
listcust.extend;
listcust(2) := cust2;
END;

My DS is this: 我的DS是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<data name="UDTSample2">
   <config id="default">
      <property name="org.wso2.ws.dataservice.driver">oracle.jdbc.driver.OracleDriver</property>
      <property name="org.wso2.ws.dataservice.protocol">jdbc:oracle:thin:@localhost:1521:DBMB</property>
      <property name="org.wso2.ws.dataservice.user">****</property>
      <property name="org.wso2.ws.dataservice.password">****</property>
   </config>
   <query id="q3" useConfig="default">
      <sql>call getCustomer2(?)</sql>
      <result element="customers">
<element name="customer" arrayName="custArray" column="cust" optional="true"/> 
</result>
      <param name="cust" paramType="ARRAY" sqlType="ARRAY" type="OUT" structType="LIST_CUSTOMERS" />

   </query>
   <operation name="op3">
      <call-query href="q3" />
   </operation>
</data>

ant return: 蚂蚁回报:

<customers xmlns="http://ws.wso2.org/dataservice">
   <customer>{1,prabath}</customer>
   <customer>{2,jorge}</customer>
</customers>

but I want something like this: 但我想要这样的东西:

<customers xmlns="http://ws.wso2.org/dataservice">
    <customer>
        <id>1</id>
        <name>prabath<name>
    </customer>
    <customer>
        <id>2</id>
        <name>Jorge<name>
    </customer>
</customers>

How can I accomplish this? 我该怎么做?

[1] http://prabathabey.blogspot.com/2012/05/query-udtsuser-defined-types-with-wso2.html

Not sure whether this kind of transformation can be done at DSS level because DSS gives back what it recieves from database. 不确定是否可以在DSS级别上完成这种转换,因为DSS会返回其从数据库中收到的信息。 Better use WSO2 esb for this kind of transformation. 最好将WSO2 esb用于此类转换。

By the moment it's not possible to accomplish this scenario using just DSS. 目前,仅使用DSS不可能完成此方案。 the DS response must be send to the WSO2 ESB to do the corresponding transformation before send the response to the client. 在将响应发送到客户端之前,必须将DS响应发送到WSO2 ESB进行相应的转换。 A JIRA was created to do this in the future https://wso2.org/jira/browse/DS-1104 创建了JIRA以在将来执行此操作https://wso2.org/jira/browse/DS-1104

As a workaround, you can use a procedure returning a sys_refcursor. 解决方法是,您可以使用返回sys_refcursor的过程。 It would look like this: 它看起来像这样:

PROCEDURE getCustomer_CUR(cur_cust OUT SYS_REFCURSOR) 
l_cust LIST_CUSTOMERS;
IS
-- Retrieve cust list:
getCustomer2(l_cust);

OPEN cur_cust for 
select cast(multiset(select * from TABLE(l_cust)) as customer_t) from dual;
...
END;

Then you can do your DSS mapping something like: 然后,您可以进行DSS映射,例如:

   <sql>call getCustomer_CUR(?)</sql>
  <result element="customers">
      <element arrayName="custArray" name="Customers">
               <element column="custArray[0]" name="col0" xsdType=.../>
               ...
      </element>
</result>
  <param name="cust" sqlType="ORACLE_REF_CURSOR" type="OUT"/>

It is tedious but it works. 这很乏味,但是有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM