1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.ibatis.common.jdbc.logging;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.HashSet;
21 import java.util.List;
22 import java.util.Map;
23 import java.util.Set;
24
25
26
27
28 public class BaseLogProxy {
29
30
31 private static int nextId = 100000;
32
33
34 protected static final Set SET_METHODS = new HashSet<>();
35
36
37 protected static final Set GET_METHODS = new HashSet<>();
38
39
40 protected static final Set EXECUTE_METHODS = new HashSet<>();
41
42
43 private Map columnMap = new HashMap<>();
44
45
46 private List columnNames = new ArrayList<>();
47
48
49 private List columnValues = new ArrayList<>();
50
51
52 protected int id;
53
54
55
56
57 public BaseLogProxy() {
58 id = getNextId();
59 }
60
61 static {
62 SET_METHODS.add("setString");
63 SET_METHODS.add("setInt");
64 SET_METHODS.add("setByte");
65 SET_METHODS.add("setShort");
66 SET_METHODS.add("setLong");
67 SET_METHODS.add("setDouble");
68 SET_METHODS.add("setFloat");
69 SET_METHODS.add("setTimestamp");
70 SET_METHODS.add("setDate");
71 SET_METHODS.add("setTime");
72 SET_METHODS.add("setArray");
73 SET_METHODS.add("setBigDecimal");
74 SET_METHODS.add("setAsciiStream");
75 SET_METHODS.add("setBinaryStream");
76 SET_METHODS.add("setBlob");
77 SET_METHODS.add("setBoolean");
78 SET_METHODS.add("setBytes");
79 SET_METHODS.add("setCharacterStream");
80 SET_METHODS.add("setClob");
81 SET_METHODS.add("setObject");
82 SET_METHODS.add("setNull");
83
84 GET_METHODS.add("getString");
85 GET_METHODS.add("getInt");
86 GET_METHODS.add("getByte");
87 GET_METHODS.add("getShort");
88 GET_METHODS.add("getLong");
89 GET_METHODS.add("getDouble");
90 GET_METHODS.add("getFloat");
91 GET_METHODS.add("getTimestamp");
92 GET_METHODS.add("getDate");
93 GET_METHODS.add("getTime");
94 GET_METHODS.add("getArray");
95 GET_METHODS.add("getBigDecimal");
96 GET_METHODS.add("getAsciiStream");
97 GET_METHODS.add("getBinaryStream");
98 GET_METHODS.add("getBlob");
99 GET_METHODS.add("getBoolean");
100 GET_METHODS.add("getBytes");
101 GET_METHODS.add("getCharacterStream");
102 GET_METHODS.add("getClob");
103 GET_METHODS.add("getObject");
104 GET_METHODS.add("getNull");
105
106 EXECUTE_METHODS.add("execute");
107 EXECUTE_METHODS.add("executeUpdate");
108 EXECUTE_METHODS.add("executeQuery");
109
110 }
111
112
113
114
115
116
117
118
119
120 protected void setColumn(Object key, Object value) {
121 columnMap.put(key, value);
122 columnNames.add(key);
123 columnValues.add(value);
124 }
125
126
127
128
129
130
131
132
133
134 protected Object getColumn(Object key) {
135 return columnMap.get(key);
136 }
137
138
139
140
141
142
143 protected String getValueString() {
144 return columnValues.toString();
145 }
146
147
148
149
150
151
152 protected String getTypeString() {
153 List typeList = new ArrayList<>(columnValues.size());
154 for (int i = 0; i < columnValues.size(); i++) {
155 Object value = columnValues.get(i);
156 if (value == null) {
157 typeList.add("null");
158 } else {
159 typeList.add(value.getClass().getName());
160 }
161 }
162 return typeList.toString();
163 }
164
165
166
167
168
169
170 protected String getColumnString() {
171 return columnNames.toString();
172 }
173
174
175
176
177 protected void clearColumnInfo() {
178 columnMap.clear();
179 columnNames.clear();
180 columnValues.clear();
181 }
182
183
184
185
186
187
188
189
190
191 protected String removeBreakingWhitespace(String original) {
192 return original.replace('\n', ' ').replace('\r', ' ').replace('\t', ' ');
193 }
194
195
196
197
198
199
200 protected synchronized static int getNextId() {
201 return nextId++;
202 }
203
204 }