opt:sql添加数据库地址
This commit is contained in:
@@ -17,6 +17,8 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
@@ -25,6 +27,9 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class DruidFilter extends FilterEventAdapter {
|
||||
|
||||
private static final Pattern GENERIC_HOST_PTRN = Pattern.compile("(?<scheme>[\\w\\+:%]+)\\s*" // scheme: required; alphanumeric, plus, colon or percent
|
||||
+ "(?://(?<host>[^:/?#]*)).*");
|
||||
|
||||
@Override
|
||||
public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
|
||||
|
||||
@@ -39,6 +44,16 @@ public class DruidFilter extends FilterEventAdapter {
|
||||
|
||||
@Override
|
||||
protected void statementExecuteAfter(StatementProxy statement, String sql, boolean result) {
|
||||
String database="";
|
||||
try {
|
||||
ConnectionImpl connection = (ConnectionImpl)statement.getConnection();
|
||||
String url = connection.getURL();
|
||||
Matcher matcher = GENERIC_HOST_PTRN.matcher(url);
|
||||
if (matcher.matches()){
|
||||
database = matcher.group("host");
|
||||
}
|
||||
}catch (Exception ex){
|
||||
}
|
||||
int size = statement.getParametersSize();
|
||||
String executeSql = sql;
|
||||
int count = 0;
|
||||
@@ -55,7 +70,7 @@ public class DruidFilter extends FilterEventAdapter {
|
||||
}
|
||||
executeSql = SQLUtils.format(executeSql, JdbcUtils.MYSQL, params);
|
||||
}
|
||||
log.info("[----SQL----][update][ SQL: {} ]", executeSql);
|
||||
log.info("[----SQL----][update][数据库:{}][ SQL: {} ]",database, executeSql);
|
||||
}
|
||||
super.statementExecuteAfter(statement, sql, result);
|
||||
}
|
||||
@@ -64,6 +79,16 @@ public class DruidFilter extends FilterEventAdapter {
|
||||
public ResultSetProxy statement_getResultSet(FilterChain chain, StatementProxy statement) throws SQLException {
|
||||
ResultSetProxy rs = super.statement_getResultSet(chain, statement);
|
||||
String executeSql = statement.getLastExecuteSql();
|
||||
String database="";
|
||||
try {
|
||||
ConnectionImpl connection = (ConnectionImpl)statement.getConnection();
|
||||
String url = connection.getURL();
|
||||
Matcher matcher = GENERIC_HOST_PTRN.matcher(url);
|
||||
if (matcher.matches()){
|
||||
database = matcher.group("host");
|
||||
}
|
||||
}catch (Exception ex){
|
||||
}
|
||||
int result = 0;
|
||||
if (rs != null) {
|
||||
ResultSetImpl rss = rs.getResultSetRaw().unwrap(ResultSetImpl.class);
|
||||
@@ -82,7 +107,7 @@ public class DruidFilter extends FilterEventAdapter {
|
||||
} catch (Exception ex) {
|
||||
log.warn("[-SQL解析异常-][{}]", ex.getMessage());
|
||||
}
|
||||
log.info("[----SQL----][select][执行结果:{}][ SQL: {} ]", result, executeSql);
|
||||
log.info("[----SQL----][select][执行结果:{}][数据库:{}][ SQL: {} ]", result,database, executeSql);
|
||||
return rs;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user