View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.jdbc;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.endpoint.InboundEndpoint;
12  import org.mule.transport.AbstractMessageRequester;
13  import org.mule.transport.jdbc.sqlstrategy.SqlStatementStrategy;
14  
15  
16  public class JdbcMessageRequester extends AbstractMessageRequester
17  {
18  
19      private JdbcConnector connector;
20  
21      public JdbcMessageRequester(InboundEndpoint endpoint)
22      {
23          super(endpoint);
24          this.connector = (JdbcConnector) endpoint.getConnector();
25      }
26  
27      @Override
28      protected void doDispose()
29      {
30          // template method
31      }
32  
33      /**
34       * Make a specific request to the underlying transport
35       *
36       * @param timeout the maximum time the operation should block before returning.
37       *            The call should return immediately if there is data available. If
38       *            no data becomes available before the timeout elapses, null will be
39       *            returned
40       * @return the result of the request wrapped in a MuleMessage object. Null will be
41       *         returned if no data was available
42       * @throws Exception if the call to the underlying protocol causes an exception
43       */
44      protected MuleMessage doRequest(long timeout) throws Exception
45      {
46          return doRequest(timeout, null);
47      }
48  
49      /**
50       * Make a specific request to the underlying transport
51       * Special case: The event is need when doReceive was called from doSend
52       * @param timeout only for compatibility with doRequest(long timeout)
53       * @param event There is a need to get params from message
54       * @return the result of the request wrapped in a MuleMessage object. Null will be
55       *         returned if no data was available
56       * @throws Exception if the call to the underlying protocol causes an exception
57       */
58      protected MuleMessage doRequest(long timeout, MuleEvent event) throws Exception
59      {
60          String statement = connector.getStatement(endpoint);
61          SqlStatementStrategy strategy = connector.getSqlStatementStrategyFactory().create(statement, null);
62          return strategy.executeStatement(connector, endpoint, event, timeout);        
63      }
64  
65  
66      @Override
67      protected void doConnect() throws Exception
68      {
69          // template method
70      }
71  
72      @Override
73      protected void doDisconnect() throws Exception
74      {
75          // template method
76      }
77  
78  }