22
33import java .util .Map ;
44
5- import javax .sql .DataSource ;
6-
75import org .springframework .batch .core .Job ;
86import org .springframework .batch .item .database .JdbcCursorItemReader ;
9- import org .springframework .batch .item .database .builder .JdbcCursorItemReaderBuilder ;
10- import org .springframework .jdbc .core .ColumnMapRowMapper ;
11- import org .springframework .util .Assert ;
12-
13- import com .redis .riot .core .RiotException ;
147
158import picocli .CommandLine .ArgGroup ;
169import picocli .CommandLine .Command ;
@@ -34,30 +27,8 @@ protected Job job() {
3427 }
3528
3629 protected JdbcCursorItemReader <Map <String , Object >> reader () {
37- Assert .hasLength (sql , "No SQL statement specified" );
38- log .info ("Creating data source with {}" , dataSourceArgs );
39- DataSource dataSource ;
40- try {
41- dataSource = dataSourceArgs .dataSource ();
42- } catch (Exception e ) {
43- throw new RiotException (e );
44- }
45- log .info ("Creating JDBC reader with sql=\" {}\" {}" , sql , readerArgs );
46- JdbcCursorItemReaderBuilder <Map <String , Object >> reader = new JdbcCursorItemReaderBuilder <>();
47- reader .dataSource (dataSource );
48- reader .sql (sql );
49- reader .saveState (false );
50- reader .rowMapper (new ColumnMapRowMapper ());
51- reader .fetchSize (readerArgs .getFetchSize ());
52- reader .maxRows (readerArgs .getMaxRows ());
53- reader .queryTimeout (Math .toIntExact (readerArgs .getQueryTimeout ().getValue ().toMillis ()));
54- reader .useSharedExtendedConnection (readerArgs .isUseSharedExtendedConnection ());
55- reader .verifyCursorPosition (readerArgs .isVerifyCursorPosition ());
56- if (readerArgs .getMaxItemCount () > 0 ) {
57- reader .maxItemCount (readerArgs .getMaxItemCount ());
58- }
59- reader .name (sql );
60- return reader .build ();
30+ log .info ("Creating JDBC reader with sql=\" {}\" {} {}" , sql , dataSourceArgs , readerArgs );
31+ return JdbcCursorItemReaderFactory .create (sql , dataSourceArgs , readerArgs ).build ();
6132 }
6233
6334 public String getSql () {
0 commit comments