@Override protected ItemReader<Foo> createItemReader() throws Exception { StoredProcedureItemReader<Foo> reader = new StoredProcedureItemReader<>(); reader.setDataSource(dataSource); reader.setProcedureName("read_foos"); reader.setRowMapper(new FooRowMapper()); reader.setVerifyCursorPosition(false); return reader; }
@Override protected ItemReader<Foo> getItemReader() throws Exception { StoredProcedureItemReader<Foo> result = new StoredProcedureItemReader<>(); result.setDataSource(getDataSource()); result.setProcedureName("read_foos"); result.setRowMapper(new FooRowMapper()); result.setVerifyCursorPosition(false); result.afterPropertiesSet(); return result; }
@Override protected ItemReader<Foo> createItemReader() throws Exception { JdbcCursorItemReader<Foo> result = new JdbcCursorItemReader<>(); result.setDataSource(dataSource); result.setSql("select ID, NAME, VALUE from T_FOOS"); result.setIgnoreWarnings(true); result.setVerifyCursorPosition(true); result.setRowMapper(new FooRowMapper()); result.setFetchSize(10); result.setMaxRows(100); result.setQueryTimeout(1000); result.setSaveState(true); return result; }
@Override protected ItemReader<Foo> getItemReader() throws Exception { JdbcCursorItemReader<Foo> result = new JdbcCursorItemReader<>(); result.setDataSource(getDataSource()); result.setSql("select ID, NAME, VALUE from T_FOOS"); result.setIgnoreWarnings(true); result.setVerifyCursorPosition(true); result.setRowMapper(new FooRowMapper()); result.setFetchSize(10); result.setMaxRows(100); result.setQueryTimeout(1000); result.setSaveState(true); result.setDriverSupportsAbsolute(false); return result; }
@Override protected void pointToEmptyInput(ItemReader<Foo> tested) throws Exception { StoredProcedureItemReader<Foo> reader = (StoredProcedureItemReader<Foo>) tested; reader.close(); reader.setDataSource(getDataSource()); reader.setProcedureName("read_some_foos"); reader.setParameters( new SqlParameter[] { new SqlParameter("from_id", Types.NUMERIC), new SqlParameter("to_id", Types.NUMERIC) }); reader.setPreparedStatementSetter( new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, 1000); ps.setInt(2, 1001); } }); reader.setRowMapper(new FooRowMapper()); reader.setVerifyCursorPosition(false); reader.afterPropertiesSet(); reader.open(new ExecutionContext()); }
@Test public void testNoSaveState() throws Exception { StoredProcedureItemReader<Foo> reader = new StoredProcedureItemReaderBuilder<Foo>() .dataSource(this.dataSource) .procedureName("read_foos") .rowMapper(new FooRowMapper()) .verifyCursorPosition(false) .saveState(false) .build(); ExecutionContext executionContext = new ExecutionContext(); reader.open(executionContext); reader.read(); reader.read(); reader.update(executionContext); assertEquals(0, executionContext.size()); reader.close(); }
@Test public void testSunnyScenario() throws Exception { StoredProcedureItemReader<Foo> reader = new StoredProcedureItemReaderBuilder<Foo>() .name("foo_reader") .dataSource(this.dataSource) .procedureName("read_foos") .rowMapper(new FooRowMapper()) .verifyCursorPosition(false) .build(); reader.open(new ExecutionContext()); Foo item1 = reader.read(); assertEquals(1, item1.getId()); assertEquals("bar1", item1.getName()); assertEquals(1, item1.getValue()); reader.close(); }
.dataSource(this.dataSource) .procedureName("read_foos") .rowMapper(new FooRowMapper()) .verifyCursorPosition(false) .refCursorPosition(3)