Skip to content

Commit 3385a4d

Browse files
committed
Change way that define a setter method to bind to PreparedStatement
* To use reflection In this changes, following methods are support. * setRef * setRowId * setSQLXML * setUnicodeStream * setURL
1 parent 5731bd6 commit 3385a4d

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
*/
1616
package org.apache.ibatis.logging.jdbc;
1717

18+
import java.lang.reflect.Method;
1819
import java.sql.Array;
20+
import java.sql.PreparedStatement;
1921
import java.sql.SQLException;
2022
import java.util.ArrayList;
2123
import java.util.Arrays;
@@ -25,6 +27,7 @@
2527
import java.util.Map;
2628
import java.util.Set;
2729
import java.util.StringTokenizer;
30+
import java.util.stream.Collectors;
2831

2932
import org.apache.ibatis.logging.Log;
3033
import org.apache.ibatis.reflection.ArrayUtil;
@@ -37,7 +40,7 @@
3740
*/
3841
public abstract class BaseJdbcLogger {
3942

40-
protected static final Set<String> SET_METHODS = new HashSet<>();
43+
protected static final Set<String> SET_METHODS;
4144
protected static final Set<String> EXECUTE_METHODS = new HashSet<>();
4245

4346
private final Map<Object, Object> columnMap = new HashMap<>();
@@ -61,30 +64,11 @@ public BaseJdbcLogger(Log log, int queryStack) {
6164
}
6265

6366
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());
8872

8973
EXECUTE_METHODS.add("execute");
9074
EXECUTE_METHODS.add("executeUpdate");

0 commit comments

Comments
 (0)