Search code examples
javaapache-camel

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 customBeanPropertyRowMapper 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.


Solution

  • 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.