[英]Oracle Stored Procedure - Spring Integration - OUT Type Object
Is it possible to have Oracle type object as an output from a stored procedure, calling same using spring integration? 是否可以将Oracle类型对象作为存储过程的输出,使用spring集成调用它?
For example, I have the following in the database: 例如,我在数据库中有以下内容:
create or replace TYPE ESP_TRAINING_REQ_OBJ AS OBJECT
(
v_param1 varchar2(25),
v_param2 varchar2(25)
);
create or replace TYPE ESP_TRAINING_RESP_OBJ AS OBJECT
(
v_param1 varchar2(25),
v_param2 varchar2(25)
);
create or replace PROCEDURE TEST_PROC (
v_req_obj IN ESP_TRAINING_REQ_OBJ,
v_resp_obj OUT ESP_TRAINING_RESP_OBJ
) AS
BEGIN
v_resp_obj := ESP_TRAINING_RESP_OBJ(v_req_obj.v_param2, v_req_obj.v_param1);
dbms_output.put_line('TEST_PROC');
END;
However, when I try calling it, I'm getting the following exception: 但是,当我尝试调用它时,我得到以下异常:
PLS-00306: wrong number or types of arguments in call to 'TEST_PROC' PLS-00306:调用'TEST_PROC'时参数的数量或类型错误
Please find spring integration configuration bellow: 请参阅下面的弹簧集成配置:
<int-jdbc:stored-proc-outbound-gateway
id="ESP_TRAINING" request-channel="inputChannel"
stored-procedure-name="TEST_PROC" data-source="dataSource"
reply-channel="outputChannel"
skip-undeclared-results="false" ignore-column-meta-data="true">
<int-jdbc:sql-parameter-definition name="v_req_obj" direction="IN" type="STRUCT" />
<int-jdbc:sql-parameter-definition name="v_resp_obj" direction="OUT" type="STRUCT" />
<int-jdbc:parameter name="v_req_obj" expression="payload.v_req_obj"/>
</int-jdbc:stored-proc-outbound-gateway>
Please note it works fine if we change SP declaration above, for using STRUCT in request only, for example replacing ESP_TRAINING_RESP_OBJ by a VARCHAR or any other Oracle primitive data type. 请注意,如果我们更改上面的SP声明,仅在请求中使用STRUCT,例如用VARCHAR或任何其他Oracle原始数据类型替换ESP_TRAINING_RESP_OBJ,它可以正常工作。
For Example: 例如:
create or replace PROCEDURE TEST_PROC (
v_req_obj IN ESP_TRAINING_REQ_OBJ,
v_status OUT VARCHAR2
) AS
BEGIN
v_status := v_req_obj.v_param1 || ' and ' || v_req_obj.v_param2;
dbms_output.put_line('TEST_PROC');
END;
I've fixed it doing following: 我已经修好了以下内容:
Updated spring integration version to 3.0.0.RELEASE, giving support to both type-name and return-type attribues, inside sql-parameter-definition. 将spring集成版本更新为3.0.0.RELEASE,在sql-parameter-definition中支持type-name和return-type attribues。
Updated stored procedured declaration as follows: 更新存储的程序声明如下:
<int-jdbc:stored-proc-outbound-gateway id="ESP_TRAINING" request-channel="inputChannel" stored-procedure-name="TEST_PROC" data-source="dataSource" reply-channel="outputChannel" skip-undeclared-results="false" ignore-column-meta-data="true"> <int-jdbc:sql-parameter-definition name="v_req_obj" direction="IN" type="STRUCT" /> <int-jdbc:sql-parameter-definition name="v_resp_obj" direction="OUT" type="STRUCT" type-name="ESP_TRAINING_RESP_OBJ" return-type="espTrainingRespObj" /> <int-jdbc:parameter name="v_req_obj" expression="payload.v_req_obj"/> </int-jdbc:stored-proc-outbound-gateway> <beans:bean id="espTrainingRespObj" class="com.hsbc.esp.EspTrainingRespObj"/>
Changed EspTrainingRespObj to implement SQLReturnType, as follows: 更改了EspTrainingRespObj以实现SQLReturnType,如下所示:
public class EspTrainingRespObj implements SqlReturnType { private String param1; private String param2; public Object getTypeValue(CallableStatement cs, int paramIndex, int sqlType, String typeName) throws SQLException { Object[] attributes = ((STRUCT) cs.getObject(paramIndex)).getAttributes(); this.param1 = (String) attributes[0]; this.param2 = (String) attributes[1]; return this; } ... }
The return-type
on the <int-jdbc:sql-parameter-definition>
for OUT
param and SqlReturnStruct
must help you to solve the issue. OUT
param和SqlReturnStruct
的<int-jdbc:sql-parameter-definition>
上的return-type
必须帮助您解决问题。
The test-case in the Framework source codes contains this sample for CLOB
handling: 框架源代码中的测试用例包含此CLOB
处理示例:
<int-jdbc:stored-proc-outbound-gateway request-channel="getMessageChannel"
data-source="dataSource"
stored-procedure-name="GET_MESSAGE"
ignore-column-meta-data="true"
expect-single-result="true"
reply-channel="output2Channel">
<int-jdbc:sql-parameter-definition name="message_id"/>
<int-jdbc:sql-parameter-definition name="message_json" type="CLOB" direction="OUT" type-name="" return-type="clobSqlReturnType"/>
<int-jdbc:parameter name="message_id" expression="payload"/>
</int-jdbc:stored-proc-outbound-gateway>
<bean id="clobSqlReturnType" class="org.mockito.Mockito" factory-method="spy">
<constructor-arg>
<bean class="org.springframework.integration.jdbc.storedproc.ClobSqlReturnType"/>
</constructor-arg>
</bean>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.