如何在 XML 输入的批量模式下在 mule 中插入数据库

How to do database insert in mule with bulk mode on for XML input

我输入了 XML 作为有效载荷,我想使用批量模式将 XML 值插入到数据库列中。 Mule 文档显示批量插入只能用集合完成。如果可以通过实现集合来完成,我们如何将 xml 转换为集合然后进行批量插入而不是耗时的 For-each 循环。

使用的 Mule 版本 - v3.8

让我们在下面举个例子,

样本 XML 作为负载输入,

<notes>
  <note number ="1">
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    <address>
        <mode = "Email">
        <fulladdress>abc@gmail.com</fulladdress>
    </address>
    <organisation>
        <designation type="contractor">Software engineer</designation>
    </organisation>
  </note>
  <note>
  <note number ="2">
    <to>Smith</to>
    <from>Gerri</from>
    <heading>Hello</heading>
    <body>Hi Smith, nice to meet you.</body>
    <address>
        <mode = "Email">
        <fulladdress>def@gmail.com</fulladdress>
    </address>
    <organisation>
        <designation type="permanent">Software engineer</designation>
    </organisation>
  </note>
</notes>

请回答以下两个问题, 1、如何将这个输入XML转化为集合? 2.问题1创建的集合如何实现批量插入?

假设您使用的是 Mule 3,并且您的有效负载如下所示:

<notes>
  <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
  </note>
  <note>
    <to>Smith</to>
    <from>Gerri</from>
    <heading>Hello</heading>
    <body>Hi Smith, nice to meet you.</body>
  </note>
</notes>

您可以使用 DataWeave 将其转换为代表 note 的 Java 对象的集合,如下所示:

%dw 1.0
%output application/java
---
payload.notes.*note

然后你可以在转换后插入你的铺位。