質問

I have a really strange bug in my application. I'm facing the problem that if I run my application in ServiceMix the resultset coming from SimpleJdbcCall contains always all the previous values from previous stored procedure calls.

However stores only the last value when running it locally.

My Camel route (with dummy names):

        <from ref="cronQuartzEndpoint"/>
        <to uri="bean:userDAO?method=listAll"/>

        <split>
            <simple>${body}</simple>
            <to uri="bean:myStoredProcCaller?method=requestAndStoreUserName" />
            <to uri="bean:userDAO?method=saveUser" />
        </split>

Let's see the stored procedure caller logic. Let's say the stored procedure returns with the name of the user, and waits for the id as parameter.

public User requestAndStoreUserName(User user) {
    LOG.info("userId: " + user.getId());

    //I know it's not necessary but I added it to ensure that new RowMapper is generated
    mySimpleJdbcCall.returningResultSet(USER_NAME_FIELD, new UserNameRowMapper());
    mySimpleJdbcCall.compile();

    Map<String, Object> results = mySimpleJdbcCall.execute(user.getId());

    List<String> userNames = (List<String>)results.get(USER_NAME_FIELD);
    LOG.info("userNames: " + userNames );
    if ( !userNames .isEmpty() ) {
        user.setName(userNames.get(0));
    }
    return user;
}

And my RowMapper is simple as this:

private static class UserNameRowMapper implements RowMapper<String> {
    @Override
    public String mapRow(ResultSet rs, int rowNum) throws SQLException {
        return rs.getString(USER_NAME_RESPONSE_FIELD_INDEX);
    }
};

The logs if I run my Camel route locally:

  • userId: 1
  • userNames: [Alice]
  • userId: 2
  • userNames: [Bob]

The logs if running it in ServiceMix:

  • userId: 1
  • userNames: [Alice]
  • userId: 2
  • userNames: [Alice, Bob]

The used versions of artifacts and all the configuration are the same on both side. Any ideas what is the logic behind this issue? Thanks, Gergely

役に立ちましたか?

解決

The problem layed behind the DataSource that I used: first I used commons.dbcp.BasicDataSource which uses pooling. When I changed it to spring.jdbc.SimpleDriverDataSource, then it started to work. This one always requests for a new connection to the DB, while the previous uses it's connection pool. However the BasicDataSource still worked with maven, but didn't in SMX --> I didn't checked the source of BasicDataSource yet, but the only difference between my local Maven dependencies and the dependencies found in SMX was: in my Maven I didn't imported commons-pool, while this package was installed in SMX. I assume there's an inner mechanism in case there's no commons-pool in the directory...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top