Example usage for org.springframework.integration.jdbc JdbcPollingChannelAdapter setSelectSqlParameterSource

List of usage examples for org.springframework.integration.jdbc JdbcPollingChannelAdapter setSelectSqlParameterSource

Introduction

In this page you can find the example usage for org.springframework.integration.jdbc JdbcPollingChannelAdapter setSelectSqlParameterSource.

Prototype

public void setSelectSqlParameterSource(@Nullable SqlParameterSource sqlQueryParameterSource) 

Source Link

Document

A source of parameters for the select query used for polling.

Usage

From source file:org.springframework.integration.jdbc.JdbcPollingChannelAdapterIntegrationTests.java

@Test
public void testParameterizedPollForListOfMapsNoUpdate() {
    JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(this.embeddedDatabase,
            "select * from item where status=:status");
    adapter.setSelectSqlParameterSource(new SqlParameterSource() {

        public boolean hasValue(String name) {
            return "status".equals(name);
        }/*from   w w  w . j a v  a 2  s  .c o m*/

        public Object getValue(String name) throws IllegalArgumentException {
            return 2;
        }

        public String getTypeName(String name) {
            return null;
        }

        public int getSqlType(String name) {
            return Types.INTEGER;
        }
    });
    this.jdbcTemplate.update("insert into item values(1,2)");
    Message<Object> message = adapter.receive();
    Object payload = message.getPayload();
    assertTrue("Wrong payload type", payload instanceof List<?>);
    List<?> rows = (List<?>) payload;
    assertEquals("Wrong number of elements", 1, rows.size());
    assertTrue("Returned row not a map", rows.get(0) instanceof Map<?, ?>);
    Map<?, ?> row = (Map<?, ?>) rows.get(0);
    assertEquals("Wrong id", 1, row.get("id"));
    assertEquals("Wrong status", 2, row.get("status"));

}