<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:int="http://www.springframework.org/schema/integration"
	xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
	xsi:schemaLocation="http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
		http://www.springframework.org/schema/integration/jdbc https://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
		http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">

	<import resource="classpath:derby-stored-procedures-setup-context.xml"/>

	<int:poller id="defaultPoller" default="true" fixed-rate="5000"/>

	<int:channel id="startChannel">
		<int:queue/>
	</int:channel>

	<int:channel id="startErrorsChannel">
		<int:queue/>
	</int:channel>

	<int-jdbc:stored-proc-outbound-gateway request-channel="startChannel"
			data-source="dataSource"
			stored-procedure-name-expression="headers['my_stored_procedure']"
			auto-startup="true"
			id="gateway"
			ignore-column-meta-data="false"
			is-function="false"
			expect-single-result="true"
			reply-channel="outputChannel">
		<int:poller fixed-delay="100" error-channel="startErrorsChannel"/>
		<int-jdbc:parameter name="username" expression="payload.username"/>
		<int-jdbc:parameter name="password" expression="payload.password"/>
		<int-jdbc:parameter name="email"    expression="payload.email"/>
		<int-jdbc:returning-resultset name="out" row-mapper="org.springframework.integration.jdbc.storedproc.UserMapper" />
	</int-jdbc:stored-proc-outbound-gateway>

	<int:channel id="outputChannel">
		<int:queue/>
	</int:channel>

	<int:logging-channel-adapter channel="errorChannel" log-full-message="true"/>

	<int:channel id="output2Channel">
		<int:queue/>
	</int:channel>

	<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>


</beans>
