The Spring Batch StoredProcedureItemReader is similar to JdbcCursorItemReader where for common cases we replace the SQL property with procedure name. The JdbcCursorItemReader runs a query to obtain a cursor whereas Spring Batch StoredProcedureReader runs a stored procedure to get a cursor.
The stored procedure can return the cursor in three different ways:
- As a returned
ResultSet
– This is used by SQL Server, Sybase, DB2, Derby, and MySQL. - As a ref-cursor returned as an out parameter – This is used by Oracle and Postgresql
- As the return value of a stored function call.
Configuring spring batch StoredProcedureItemReader
Define RowMapper for StoredProcedureItemReader
public class StudentResultRowMapper implements RowMapper<Student> {
@Override
public Student mapRow(ResultSet rs, int i) throws SQLException {
Student student = new Student();
student.setId(rs.getLong("id"));
student.setRollNumber(rs.getString("roll_number"));
student.setName(rs.getString("name"));
return student;
}
}
Configure StoredProcedureItemReader
@Bean
public StoredProcedureItemReader reader() {
StoredProcedureItemReader reader = new StoredProcedureItemReader();
reader.setDataSource(dataSource);
reader.setProcedureName("student_procedure");
reader.setRowMapper(new StudentResultRowMapper());
reader.setRefCursorPosition(1);
return reader;
}
The StoredProcedureItemReader
class extends AbstractCursorItemReader
class.
That’s all about the Spring batch StoredProcedureItemReader example.
See docs for more details.
Spring Data JPA tutorials.
- Spring Data JPA Query Methods.
- Spring Data JPA StartingWith And EndingWith Example
- Spring Data JPA Is and Equals Example
- Spring Data JPA In and NotIn Example
- Spring Data JPA between Example
- Spring Data JPA And Or Example Using Spring Boot
- Spring Data JPA Not Example Using Spring Boot
- Spring Data JPA contains ignorecase Example
- Spring Data JPA Like and Containing Example
- Spring Data JPA greater than Example
- Spring Data JPA less than Example
- Spring Data JPA IsNull Example Using Spring Boot
Spring Data JPA and Hibernate tutorials using Spring Boot and Oracle.
- @Version Annotation Example In Hibernate.
- Hibernate Validator Constraints Example Using Spring Boot.
- @Temporal Annotation Example In Hibernate/Jpa Using Spring Boot.
- Hibernate Table Per Concrete Class Spring Boot.
- Hibernate Table Per Subclass Inheritance Spring Boot.
- Hibernate Single Table Inheritance using Spring Boot.
- One To One Mapping Annotation Example in Hibernate/JPA using Spring Boot and Oracle.
- One To One Bidirectional Mapping Example In Hibernate/JPA Using Spring Boot and Oracle.
- One To Many Mapping Annotation Example In Hibernate/JPA Using Spring Boot And Oracle.
- Many To One Unidirectional Mapping In Hibernate/JPA Annotation Example Using Spring Boot and Oracle.
- One To Many Bidirectional Mapping In Hibernate/JPA Annotation Example Using Spring Boot and Oracle.
- Many To Many Mapping Annotation Example In Hibernate/JPA Using Spring Boot And