Announcement Announcement Module
Collapse
No announcement yet.
Issue with <int-jdbc:outbound-gateway> Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with <int-jdbc:outbound-gateway>

    Hi
    I am trying use <int-jdbc:outbound-gateway> component to retrieve a "database view" (as shown in the below code snippet),

    My problem is it is not going in normal flow when ZERO rows (no rows) returned.
    It is only working when something returned (at least one row),

    As per the flow, I have to perform some other actions after completing this JDBC call, but I am unable to get the control if no rows returning.

    Could anyone help me how to handle this scenario when no rows returned, I googled but did not find anything relevant to my problem.
    I appreciate your time. Thanks much.
    Code:
    =========================
    <int:chain input-channel="XXXXXXChainInputChannel"
    		output-channel="XXXXXXnOutputChannel">
    		<int:transformer ref="XXXXXViewTransformer" method="transformXXXXXXXRequest"/>
    		<int-jdbc:outbound-gateway  data-source="db2DataSource" 
                query="${jdbc.query}"
                row-mapper="RowMapper"
                reply-sql-parameter-source-factory="replySource" 
                max-rows-per-poll="100"/>
       		<int:transformer ref="delegationViewTransformer" method="transformDelegationResponse"/>
    	</int:chain> 
    
    <bean id="replySource" class="org.springframework.integration.jdbc.ExpressionEvaluatingSqlParameterSourceFactory">
    		<property name="parameterExpressions">
    			<map>
    				<entry key="delegation" value="payload"/>				
    			</map>
    		</property>
    	</bean>	
    ===================
    Last edited by Gary Russell; Feb 11th, 2013, 12:55 PM.

  • #2
    Please use [ code ] .. [ /code ] tags (no spaces in brackets) around code/config (I edited your post).

    This is a known issue (null result in JDBC gateway). Gateways are always expected to return some kind of result.

    We are looking at a comprehensive fix for 3.0; in the meantime, with SI 2.2, you can add a custom advice to the gateway; something like...

    Code:
    public class NullReplyAdvice extends AbstractRequestHandlerAdvice {
    
    	@Override
    	protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
    		Object result = callback.execute();
    		if (result == null) {
    			result = new ErrorMessage(new MessageHandlingException(message, "No results returned from gateway"));
    		}
    		return result;
    	}
    
    }
    and add the advice to the gateway...

    Code:
    <int-jdbc:outbound-gateway  data-source="dataSource" request-channel="foo"
                query="select * from FOO">
    	<int-jdbc:request-handler-advice-chain>
    		<bean class="foo.NullReplyAdvice" />
    	</int-jdbc:request-handler-advice-chain>
    </int-jdbc:outbound-gateway>
    In this case, I returned an ErrorMessage, but you can return whatever you like (e.g. an empty list)...

    Code:
    public class NullReplyAdvice extends AbstractRequestHandlerAdvice {
    
    	@Override
    	protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
    		Object result = callback.execute();
    		if (result == null) {
    			result = new ArrayList<String>();
    		}
    		return result;
    	}
    
    }

    Comment


    • #3
      Hi Gary,

      It worked, Thanks allot for your help. You Guys are awesome
      I thought I would need to revert back to the old fashion code (using jdbc template) but I felt there must be some way to do this.
      Anyways thank you very much for your timely help, its really wonderful experience using spring integration (it helps to reduce lots of lots of code)

      Regards
      Ashok Gudise

      Comment

      Working...
      X