Apache-Camel SQLEndpoint – 配置自定义的BeanPropertyRowMapper

huangapple go评论47阅读模式
英文:

Apache-Camel SQLEndpoint - configure a custom BeanPropertyRowMapper

问题

I'm using camel version 3.14.5 and I'm wondering if there's a way (I can't see one) where I can use a custom BeanPropertyRowMapper when using a SqlEndpoint.

I'm using the sql endpoint like this in a route:

.to("mySqlComponent:classpath:my_sql.sql?outputType=StreamList&outputClass=com.my.project.MyCustomMappedPojo")

Looking at the code it does look like a BeanPropertyRowMapper is hardcoded in the class

DefaultSqlEndpoint

@SuppressWarnings("unchecked")
public ResultSetIterator queryForStreamList(Connection connection, Statement statement, ResultSet rs) throws SQLException {
    if (outputClass == null) {
        RowMapper rowMapper = new ColumnMapRowMapper();
        return new ResultSetIterator(connection, statement, rs, rowMapper);
    } else {
        Class<?> outputClzz = getCamelContext().getClassResolver().resolveClass(outputClass);
        RowMapper rowMapper = new BeanPropertyRowMapper(outputClzz);
        return new ResultSetIterator(connection, statement, rs, rowMapper);
    }
}

So all I'm after is a way to make use of a Custom RowMapper.

The most obvious way would be to pass it to the SqlEndpoint directly, but there's no such property.

Alternatively I thought about using a custom SqlEndpoint whilst wiring a SqlComponent in Spring, but I see that the SqlComponent uses a SqlEndpoint hardcoded (i.e.: doesn't allow me to inject a custom Endpoint) which in turns uses the hardcoded BeanPropertyRowMapper as per the code sample above.

英文:

I'm using camel version 3.14.5 and I'm wondering if there's a way (I can't see one) where I can use a customBeanPropertyRowMapper when using a SqlEndpoint.

I'm using the sql endpoint like this in a route:

.to(&quot;mySqlComponent:classpath:my_sql.sql?outputType=StreamList&amp;outputClass=com.my.project.MyCustomMappedPojo&quot;)

Looking at the code it does look like a BeanPropertyRowMapper is hardcoded in the class

> DefaultSqlEndpoint

 @SuppressWarnings(&quot;unchecked&quot;)
    public ResultSetIterator queryForStreamList(Connection connection, Statement statement, ResultSet rs) throws SQLException {
        if (outputClass == null) {
            RowMapper rowMapper = new ColumnMapRowMapper();
            return new ResultSetIterator(connection, statement, rs, rowMapper);
        } else {
            Class&lt;?&gt; outputClzz = getCamelContext().getClassResolver().resolveClass(outputClass);
            RowMapper rowMapper = new BeanPropertyRowMapper(outputClzz);
            return new ResultSetIterator(connection, statement, rs, rowMapper);
        }
    }

So all I'm after is a way to make use of a Custom RowMapper.

The most obvious way would be to pass it to the SqlEndpoint directly, but there's no such property.

Alternatively I thought about using a custom SqlEndpoint whilst wiring a SqlComponent in Spring, but I see that the SqlComponent uses a SqlEndpoint hardcoded (i.e.: doesn't allow me to inject a custom Endpoint) which in turns uses the hardcoded BeanPropertyRowMapper as per the code sample above.

答案1

得分: 1

你真的有一个自定义的org.springframework.jdbc.core.BeanPropertyRowMapper吗?

目前在camel-sql中无法进行配置。
欢迎您创建一个JIRA并提交PR以添加对此的支持。

英文:

Do you really have a custom org.springframework.jdbc.core.BeanPropertyRowMapper ?

Its not possible to configure currently in camel-sql.
You are welcome to create a JIRA and work on a PR to add support for this.

huangapple
  • 本文由 发表于 2023年2月14日 19:06:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75446926.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定