2
2
3
3
import java .util .Map ;
4
4
5
- import javax .sql .DataSource ;
6
-
7
5
import org .springframework .batch .core .Job ;
8
6
import 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 ;
14
7
15
8
import picocli .CommandLine .ArgGroup ;
16
9
import picocli .CommandLine .Command ;
@@ -34,30 +27,8 @@ protected Job job() {
34
27
}
35
28
36
29
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 ();
61
32
}
62
33
63
34
public String getSql () {
0 commit comments