Assert.notNull(this.rowMapper, "A rowmapper is required"); StoredProcedureItemReader<T> itemReader = new StoredProcedureItemReader<>(); itemReader.setName(this.name); itemReader.setProcedureName(this.procedureName); itemReader.setRowMapper(this.rowMapper); itemReader.setParameters(this.parameters); itemReader.setPreparedStatementSetter(this.preparedStatementSetter); itemReader.setFunction(this.function); itemReader.setRefCursorPosition(this.refCursorPosition); itemReader.setCurrentItemCount(this.currentItemCount); itemReader.setDataSource(this.dataSource); itemReader.setDriverSupportsAbsolute(this.driverSupportsAbsolute); itemReader.setFetchSize(this.fetchSize); itemReader.setIgnoreWarnings(this.ignoreWarnings); itemReader.setMaxItemCount(this.maxItemCount); itemReader.setMaxRows(this.maxRows); itemReader.setQueryTimeout(this.queryTimeout); itemReader.setSaveState(this.saveState); itemReader.setUseSharedExtendedConnection(this.useSharedExtendedConnection); itemReader.setVerifyCursorPosition(this.verifyCursorPosition);
@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 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()); }
PlatformTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate tt = new TransactionTemplate(tm); final StoredProcedureItemReader<String> reader = new StoredProcedureItemReader<>(); reader.setDataSource(ds); reader.setProcedureName("foo_bar"); reader.setParameters(new SqlParameter[] { new SqlParameter("foo", Types.VARCHAR), new SqlParameter("bar", Types.OTHER)}); reader.setPreparedStatementSetter( new PreparedStatementSetter() { @Override reader.setRefCursorPosition(3); final ExecutionContext ec = new ExecutionContext(); tt.execute(
callContext.setProcedureName(procedureName); callContext.setFunction(function); callContext.initializeMetaData(getDataSource()); callContext.processParameters(Arrays.asList(parameters)); SqlParameter cursorParameter = callContext.createReturnResultSetParameter("cursor", rowMapper); if (isUseSharedExtendedConnection()) { callableStatement = con.prepareCall(callString, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); callableStatement = con.prepareCall(callString, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); applyStatementSettings(callableStatement); if (this.preparedStatementSetter != null) { preparedStatementSetter.setValues(callableStatement); handleWarnings(callableStatement); close(); throw getExceptionTranslator().translate("Executing stored procedure", getSql(), se);
PlatformTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate tt = new TransactionTemplate(tm); final StoredProcedureItemReader<String> reader = new StoredProcedureItemReader<>(); reader.setDataSource(new ExtendedConnectionDataSourceProxy(ds)); reader.setUseSharedExtendedConnection(true); reader.setProcedureName("foo_bar"); final ExecutionContext ec = new ExecutionContext(); tt.execute(
PlatformTransactionManager tm = new DataSourceTransactionManager(ds); TransactionTemplate tt = new TransactionTemplate(tm); final StoredProcedureItemReader<String> reader = new StoredProcedureItemReader<>(); reader.setDataSource(ds); reader.setProcedureName("foo_bar"); final ExecutionContext ec = new ExecutionContext(); tt.execute(
@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(); }
@Test public void testRestartWithDriverSupportsAbsolute() throws Exception { testedAsStream().close(); tested = getItemReader(); ((StoredProcedureItemReader<Foo>) tested).setDriverSupportsAbsolute(true); testedAsStream().open(executionContext); testedAsStream().close(); testedAsStream().open(executionContext); testRestart(); }
@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; }
callContext.setProcedureName(procedureName); callContext.setFunction(function); callContext.initializeMetaData(getDataSource()); callContext.processParameters(Arrays.asList(parameters)); SqlParameter cursorParameter = callContext.createReturnResultSetParameter("cursor", rowMapper); if (isUseSharedExtendedConnection()) { callableStatement = con.prepareCall(callString, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); callableStatement = con.prepareCall(callString, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); applyStatementSettings(callableStatement); if (this.preparedStatementSetter != null) { preparedStatementSetter.setValues(callableStatement); handleWarnings(callableStatement); close(); throw getExceptionTranslator().translate("Executing stored procedure", getSql(), se);
Assert.notNull(this.rowMapper, "A rowmapper is required"); StoredProcedureItemReader<T> itemReader = new StoredProcedureItemReader<>(); itemReader.setName(this.name); itemReader.setProcedureName(this.procedureName); itemReader.setRowMapper(this.rowMapper); itemReader.setParameters(this.parameters); itemReader.setPreparedStatementSetter(this.preparedStatementSetter); itemReader.setFunction(this.function); itemReader.setRefCursorPosition(this.refCursorPosition); itemReader.setCurrentItemCount(this.currentItemCount); itemReader.setDataSource(this.dataSource); itemReader.setDriverSupportsAbsolute(this.driverSupportsAbsolute); itemReader.setFetchSize(this.fetchSize); itemReader.setIgnoreWarnings(this.ignoreWarnings); itemReader.setMaxItemCount(this.maxItemCount); itemReader.setMaxRows(this.maxRows); itemReader.setQueryTimeout(this.queryTimeout); itemReader.setSaveState(this.saveState); itemReader.setUseSharedExtendedConnection(this.useSharedExtendedConnection); itemReader.setVerifyCursorPosition(this.verifyCursorPosition);