11package com .codingapi .dbstream .interceptor ;
22
33import com .codingapi .dbstream .proxy .ConnectionProxy ;
4+ import com .codingapi .dbstream .query .JdbcQuery ;
45import com .codingapi .dbstream .scanner .DBMetaData ;
56import com .codingapi .dbstream .scanner .DBScanner ;
67import com .codingapi .dbstream .scanner .DbColumn ;
78import com .codingapi .dbstream .scanner .DbTable ;
89import lombok .Getter ;
910import lombok .Setter ;
1011
11- import java .sql .*;
12+ import java .sql .ResultSet ;
13+ import java .sql .ResultSetMetaData ;
14+ import java .sql .SQLException ;
15+ import java .sql .Statement ;
1216import java .util .*;
1317
1418/**
@@ -76,11 +80,18 @@ public class SQLExecuteState {
7680 @ Getter
7781 private long afterTimestamp ;
7882
83+ /**
84+ * JDBC数据查询
85+ */
86+ @ Getter
87+ private final JdbcQuery jdbcQuery ;
88+
7989
8090 public SQLExecuteState (String sql , ConnectionProxy connectionProxy , Statement statement , DBMetaData metaData ) {
8191 this .sql = sql ;
8292 this .connectionProxy = connectionProxy ;
8393 this .statement = statement ;
94+ this .jdbcQuery = new JdbcQuery (connectionProxy );
8495 this .metaData = metaData ;
8596 this .sqlExecuteParams = new ArrayList <>();
8697
@@ -255,7 +266,7 @@ public String getTransactionKey() {
255266 * @throws SQLException 查询异常
256267 */
257268 public List <Map <String , Object >> query (String sql ) throws SQLException {
258- return this .query (sql , new ArrayList <>() );
269+ return this .jdbcQuery . query (sql );
259270 }
260271
261272 /**
@@ -267,23 +278,7 @@ public List<Map<String, Object>> query(String sql) throws SQLException {
267278 * @throws SQLException 查询异常
268279 */
269280 public List <Map <String , Object >> query (String sql , List <Object > params ) throws SQLException {
270- PreparedStatement preparedStatement = connectionProxy .getConnection ().prepareStatement (sql );
271- for (int i = 0 ; i < params .size (); i ++) {
272- Object param = params .get (i );
273- preparedStatement .setObject (i + 1 , param );
274- }
275- ResultSet resultSet = preparedStatement .executeQuery ();
276- ResultSetMetaData resultSetMetaData = resultSet .getMetaData ();
277- List <Map <String , Object >> list = new ArrayList <>();
278- while (resultSet .next ()) {
279- Map <String , Object > map = new HashMap <>();
280- for (int i = 1 ; i <= resultSetMetaData .getColumnCount (); i ++) {
281- map .put (resultSetMetaData .getColumnName (i ), resultSet .getObject (i ));
282- }
283- list .add (map );
284- }
285- resultSet .close ();
286- return list ;
281+ return jdbcQuery .query (sql ,params );
287282 }
288283
289284 /**
@@ -316,6 +311,7 @@ public List<Map<String, Object>> getStatementGenerateKeys(DbTable dbTable) {
316311 }
317312
318313
314+
319315 /**
320316 * 获取驱动配置信息
321317 *
0 commit comments