是否可以将Oracle类型对象作为存储过程的输出,使用spring integration调用它?
例如,我在数据库中有以下内容:
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;
然而,当我尝试调用它时,我遇到以下异常:
PLS-00306:调用'TEST_PROC'时参数的数量或类型错误
请参阅下面的弹簧集成配置:
<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>
请注意,如果我们更改上面的SP声明,仅在请求中使用STRUCT,例如用VARCHAR或任何其他Oracle原始数据类型替换ESP_TRAINING_RESP_OBJ,它就可以正常工作。
例如:
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;
答案 0 :(得分:2)
我已经修好了以下内容:
将Spring集成版本更新为3.0.0.RELEASE, 在sql-parameter-definition中支持type-name和return-type attribues。
更新了存储过程声明,如下所示:
<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"/>
更改了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;
}
...
}
答案 1 :(得分:1)
<int-jdbc:sql-parameter-definition>
param和return-type
OUT
上的SqlReturnStruct
必须帮助您解决问题。
Framework源代码中的测试用例包含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>