开发者

Testing inserts over Mule JDBC transport to embedded HSQLDB, subsequent query returns no results

开发者 https://www.devze.com 2023-03-27 02:43 出处:网络
My test attempts to show that a SQL statement sent over a Mule JDBC outbound endpoint executes successfully. The problem: after inserting over Mule, querying the same table returns no results.

My test attempts to show that a SQL statement sent over a Mule JDBC outbound endpoint executes successfully. The problem: after inserting over Mule, querying the same table returns no results.

I'm using Spring JDBC to test the results of that statement.

In my setup method I create the schema with a DDL statement sent over Spring JDBC:

final JdbcTemplate _jdbcTemplate = new JdbcTemplate(new
SimpleDriverDataSource(new JDBCDriver(), "jdbc:hsqldb:mem:mydb"));

Mule JDBC outbound connector is also configured to point to jdbc:hsqldb:mem:mydb

<spring:bean id="myDataSource" class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
    <spring:property name="driverName" value="org.hsq开发者_运维技巧ldb.jdbc.JDBCDriver"/>
    <spring:property name="url" value="jdbc:hsqldb:mem:mydb"/>
</spring:bean>

<jdbc:connector name="insertionConnector" dataSource-ref="myDataSource">
    <jdbc:query key="insertion"
                value="INSERT INTO mytable (TEST_KEY) VALUES (#[map-payload:_testkey])"/>
</jdbc:connector>

<custom-transformer name="objectFieldsToMap" class="com.mydomain.ObjectFieldsToMap"/>

<flow name="sendInsertion">
    <vm:inbound-endpoint address="vm://insert"/>
    <jdbc:outbound-endpoint queryKey="insertion" transformer-refs="objectFieldsToMap" connector-ref="insertionConnector"/>
</flow>

I verified that inserting a test row and querying for it using Spring JDBC both ways works.

I verified that sending the same insert statement over the outbound endpoint returns 1 row updated.

 final MuleClient muleClient = MyFactory.muleClient();
 final Date date = new Date();
 final MyObject myObject = new MyObject.Builder().setTestKey("test").build();

 muleClient.dispatch("vm://insert", myObject, null);

However, when I then query the same table using Spring JDBC I get an empty result set.

(String) _jdbcTemplate.queryForObject("SELECT TEST_KEY FROM MYDB.mytable", Class.forName("java.lang.String"));

Internally, Mule (using Apache DbUtils) commits after executing the statement so the insertion should be visible to subsequent queries. I am using the same JdbcTemplate object used to create the schema to then query for the results.

Help appreciated. Thank you.


Just to confirm, are you running Mule and your spring bean querying the table in the same JVM?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号