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

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

Introduction

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

Prototype

@Deprecated
public void setMaxRowsPerPoll(int maxRows) 

Source Link

Document

The maximum number of rows to pull out of the query results per poll (if greater than zero, otherwise all rows will be packed into the outgoing message).

Usage

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

@Test
public void testSimplePollForListWithRowMapperAndInsertPerRowAndMaxRows() {
    JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(this.embeddedDatabase,
            "select * from item where id not in (select id from copy)");
    adapter.setUpdateSql("insert into copy values(:id,10)");
    adapter.setUpdatePerRow(true);//from   w  w  w.j  a  v  a2 s  .c om
    adapter.setMaxRowsPerPoll(1);
    adapter.setRowMapper(new ItemRowMapper());
    adapter.setBeanFactory(mock(BeanFactory.class));
    adapter.afterPropertiesSet();

    this.jdbcTemplate.update("insert into item values(1,2)");
    this.jdbcTemplate.update("insert into item values(2,2)");

    logger.debug(adapter.receive());
    Message<Object> message = adapter.receive();
    Object payload = message.getPayload();
    List<?> rows = (List<?>) payload;
    assertEquals("Wrong number of elements", 1, rows.size());
    assertTrue("Wrong payload type", rows.get(0) instanceof Item);
    Item item = (Item) rows.get(0);
    logger.debug(item);
    assertEquals("Wrong id", 2, item.getId());
    assertEquals("Wrong status", 2, item.getStatus());

    int countOfStatusTwo = this.jdbcTemplate.queryForInt("select count(*) from item where status = 2");
    assertEquals("Status not updated incorect number of rows with status 2", 2, countOfStatusTwo);

    int countOfStatusTen = this.jdbcTemplate.queryForInt("select count(*) from copy where status = 10");
    assertEquals("Status not updated incorect number of rows with status 10", 2, countOfStatusTen);

}

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

@Test
public void testSimplePollForListWithRowMapperAndUpdatePerRowWithMaxRows() {
    JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(this.embeddedDatabase,
            "select * from item where status=2");
    adapter.setUpdateSql("update item set status = 10 where id = :id");
    adapter.setUpdatePerRow(true);/*from w w w .  java2s.c  om*/
    adapter.setMaxRowsPerPoll(1);
    adapter.setRowMapper(new ItemRowMapper());
    adapter.setBeanFactory(mock(BeanFactory.class));
    adapter.afterPropertiesSet();

    this.jdbcTemplate.update("insert into item values(1,2)");
    this.jdbcTemplate.update("insert into item values(2,2)");

    adapter.receive();
    Message<Object> message = adapter.receive();
    Object payload = message.getPayload();
    List<?> rows = (List<?>) payload;
    assertEquals("Wrong number of elements", 1, rows.size());
    assertTrue("Wrong payload type", rows.get(0) instanceof Item);
    Item item = (Item) rows.get(0);
    assertEquals("Wrong id", 2, item.getId());
    assertEquals("Wrong status", 2, item.getStatus());

    int countOfStatusTwo = this.jdbcTemplate.queryForInt("select count(*) from item where status = 2");
    assertEquals("Status not updated incorect number of rows with status 2", 0, countOfStatusTwo);

    int countOfStatusTen = this.jdbcTemplate.queryForInt("select count(*) from item where status = 10");
    assertEquals("Status not updated incorect number of rows with status 10", 2, countOfStatusTen);

}