1

I'm trying to create an 'update-query' for my JdbcPollingChannelAdapter given following workflow :

  1. Select 500 records of type A from database
  2. Update 1 row in another table with the values of the last record read ( the one at position 500 )

But i'm unable to sort it out, as been trying to use spring-el to find the value.

By debugging, i reached JdbcPollingChannelAdapter executeUpdateQuery method,

void executeUpdateQuery(Object obj) {
        SqlParameterSource updateParameterSource = this.sqlParameterSourceFactory.createParameterSource(obj);
        this.jdbcOperations.update(this.updateSql, updateParameterSource);
    }

where Object obj is an ArrayList of 500 records of type A

This is my best match :

UPDATE LAST_EVENT_READ SET SEQUENCE=:#root[499].sequence, EVENT_DATE=:#[499].eventDate

Can anyone help me ?

P.S. Type A has sequence and eventDate attributes

1 Answer 1

1

I suggest you to use a custom SqlParameterSourceFactory and already don't rely on the SpEL:

public class CustomSqlParameterSourceFactory implements SqlParameterSourceFactory {

    @Override
    public SqlParameterSource createParameterSource(Object input) {
        List<?> objects = (List<?>) input;
        return new BeanPropertySqlParameterSource(objects.get(objects.size() - 1));
    }

}

Inject this into the JdbcPollingChannelAdapter.setUpdateSqlParameterSourceFactory() and already use simple properties in the UPDATE statement:

UPDATE LAST_EVENT_READ SET SEQUENCE=:sequence, EVENT_DATE=:eventDate
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.