muleステップjdbc transport:


muleのxml汪洋を泳ぎ続けた.単純な要件は、vm:queueにmapメッセージを送信し、muleはmap情報に基づいてsqlを動的に実行し、データを返す.
selectのクエリーmuleはデフォルトでmapデータを返します.プロファイル:my-mule-jdbc-config.xmlは次のとおりです.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jdbc="http://www.mulesource.com/schema/mule/jdbc/2.1"
    xmlns:spring="http://www.springframework.org/schema/beans"
    xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.1"
    xsi:schemaLocation="
          http://www.mulesource.com/schema/mule/jdbc/2.1 http://www.mulesource.com/schema/mule/jdbc/2.1/mule-jdbc-ee.xsd
          http://www.mulesource.org/schema/mule/core/2.1 http://www.mulesource.org/schema/mule/core/2.1/mule.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
             http://www.mulesource.org/schema/mule/vm/2.1 http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd">


    <spring:bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <spring:property name="driverClassName"
            value="com.mysql.jdbc.Driver" />
        <spring:property name="url"
            value="jdbc:mysql://192.168.10.120/sand_res" />
        <spring:property name="username" value="username" />
        <spring:property name="password" value="888" />
        <spring:property name="maxActive" value="30" />
        <spring:property name="maxIdle" value="10" />
        <spring:property name="maxWait" value="1000" />
        <spring:property name="defaultAutoCommit" value="true" />
    </spring:bean>
    <jdbc:connector name="jdbcConnector" dataSource-ref="dataSource">
        <jdbc:query key="selectUser"
            value="SELECT first_name,last_name FROM app_user where first_name=#[map-payload:firstName]" />

        <jdbc:query key="insertUser"
            value="insert into app_user
            (id,first_name,last_name ) values(#[map-payload:id], #[map-payload:firstName], #[map-payload:lastName])" />
    </jdbc:connector>
   

    <!--
        The Mule model initialises and manages your UMO components
    -->
    <model name="databaseModel">
        <service name="insertUMO">
            <!-- any number of endpoints can be added to an inbound router -->
            <inbound>
                <vm:inbound-endpoint path="query"/>
            </inbound>

            <!--
                An outbound router can have one or more router configurations that can be
                invoked depending on business rules, message contents, headers or any other
                criteria. The pass-through-router is a router that automatically passes
                on every message it receives
            -->
            <outbound>
                <pass-through-router>
                    <jdbc:outbound-endpoint queryKey="selectUser" synchronous="true"/>
                </pass-through-router>
            </outbound>
        </service>
    </model>
</mule>
 
注意:muleが2.1を採用した場合、jdbc transportのnamespase接尾辞はorgではなくcomで、書き間違えた場合、IDEはヒントを与えず、プログラム異常もおかしく、午後を振り回されました:(テストプログラム:
public class MyMuleClientTest
{
    public static void main(String[] args) throws MuleException
    {
        // create mule
        MuleContext muleContext;
        String config = "my-mule-jdbc-config.xml";
        muleContext = new DefaultMuleContextFactory().createMuleContext(config);
        muleContext.start();
        // creat mule client
        MuleClient client = new MuleClient();
        Map map = new HashMap();
        map.put("firstName", "feng");
        MuleMessage response = client.send("vm://query", map, null);       
        System.out.println("response = " + response.getPayload());
    }

}
 
実行するsqlは:SELECT first_name,last_name FROM app_user where first_name=「feng」insertの実行は類似しており、以下のように変更するだけです.
            <outbound>
                <pass-through-router>
                    <jdbc:outbound-endpoint queryKey="insertUser" synchronous="true"/>
                </pass-through-router>
            </outbound>
 
感じmuleのjdbc transtortは、微縮版のibatisです.ほほほ