15
15
*/
16
16
package org .apache .ibatis .logging .jdbc ;
17
17
18
+ import java .lang .reflect .Method ;
18
19
import java .sql .Array ;
20
+ import java .sql .PreparedStatement ;
19
21
import java .sql .SQLException ;
20
22
import java .util .ArrayList ;
21
23
import java .util .Arrays ;
25
27
import java .util .Map ;
26
28
import java .util .Set ;
27
29
import java .util .StringTokenizer ;
30
+ import java .util .stream .Collectors ;
28
31
29
32
import org .apache .ibatis .logging .Log ;
30
33
import org .apache .ibatis .reflection .ArrayUtil ;
37
40
*/
38
41
public abstract class BaseJdbcLogger {
39
42
40
- protected static final Set <String > SET_METHODS = new HashSet <>() ;
43
+ protected static final Set <String > SET_METHODS ;
41
44
protected static final Set <String > EXECUTE_METHODS = new HashSet <>();
42
45
43
46
private final Map <Object , Object > columnMap = new HashMap <>();
@@ -61,30 +64,11 @@ public BaseJdbcLogger(Log log, int queryStack) {
61
64
}
62
65
63
66
static {
64
- SET_METHODS .add ("setString" );
65
- SET_METHODS .add ("setNString" );
66
- SET_METHODS .add ("setInt" );
67
- SET_METHODS .add ("setByte" );
68
- SET_METHODS .add ("setShort" );
69
- SET_METHODS .add ("setLong" );
70
- SET_METHODS .add ("setDouble" );
71
- SET_METHODS .add ("setFloat" );
72
- SET_METHODS .add ("setTimestamp" );
73
- SET_METHODS .add ("setDate" );
74
- SET_METHODS .add ("setTime" );
75
- SET_METHODS .add ("setArray" );
76
- SET_METHODS .add ("setBigDecimal" );
77
- SET_METHODS .add ("setAsciiStream" );
78
- SET_METHODS .add ("setBinaryStream" );
79
- SET_METHODS .add ("setBlob" );
80
- SET_METHODS .add ("setBoolean" );
81
- SET_METHODS .add ("setBytes" );
82
- SET_METHODS .add ("setCharacterStream" );
83
- SET_METHODS .add ("setNCharacterStream" );
84
- SET_METHODS .add ("setClob" );
85
- SET_METHODS .add ("setNClob" );
86
- SET_METHODS .add ("setObject" );
87
- SET_METHODS .add ("setNull" );
67
+ SET_METHODS = Arrays .stream (PreparedStatement .class .getDeclaredMethods ())
68
+ .filter (method -> method .getName ().startsWith ("set" ))
69
+ .filter (method -> method .getParameterCount () > 1 )
70
+ .map (Method ::getName )
71
+ .collect (Collectors .toSet ());
88
72
89
73
EXECUTE_METHODS .add ("execute" );
90
74
EXECUTE_METHODS .add ("executeUpdate" );
0 commit comments